Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
Minor update.
Browse files Browse the repository at this point in the history
* Added the google maps api key. #49
* Added timestamp to post response. #48
  • Loading branch information
Leo-Lem committed May 26, 2023
1 parent 0664ff5 commit 1288940
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ spring:
springdoc:
api-docs.path: /docs
swagger-ui.path: /docs/swagger

googlemaps.apikey: <google-maps-api-key>
30 changes: 30 additions & 0 deletions src/main/java/studentscroll/api/maps/MapsRestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package studentscroll.api.maps;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import studentscroll.api.maps.dto.APIKeyResponse;

@Tag(name = "Maps")
@SecurityRequirement(name = "token")
@RestController
@RequestMapping("/maps")
public class MapsRestController {

@Value("${googlemaps.apikey}")
private String apiKey;

@Operation(summary = "Retrieve the Google Maps API key.")
@ApiResponse(responseCode = "200", description = "Returning the API key.")
@GetMapping
public APIKeyResponse read() {
return new APIKeyResponse(apiKey);
}

}
10 changes: 10 additions & 0 deletions src/main/java/studentscroll/api/maps/dto/APIKeyResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package studentscroll.api.maps.dto;

import lombok.Data;

@Data
public class APIKeyResponse {

private final String apiKey;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class PostResponse {
@NonNull
private final String[] tags;

@NonNull
private final LocalDateTime timestamp;

// event posts

private final String description;
Expand All @@ -42,6 +45,7 @@ public PostResponse(Post post) {
this.posterId = post.getPoster().getId();
this.title = post.getTitle();
this.tags = post.getTags().toArray(new String[] {});
this.timestamp = post.getTimestamp();

if (post instanceof EventPost) {
EventPost eventPost = (EventPost) post;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public SecurityFilterChain filterChain(HttpSecurity security) throws Exception {
.requestMatchers("/chats/{chatId}", "/chats/{chatId}/messages").access(isParticipantAuthz)
.requestMatchers(HttpMethod.GET, "/chats/{chatId}/messages/{messageId}").access(isParticipantAuthz)
.requestMatchers("/chats/{chatId}/messages/{messageId}").access(isSenderAuthz))
.authorizeHttpRequests(authz -> authz.requestMatchers(HttpMethod.GET, "/maps").authenticated())
.authorizeHttpRequests(authz -> authz.anyRequest().denyAll())
.authenticationProvider(authenticationProvider())
.addFilterBefore(jwtFilter(), UsernamePasswordAuthenticationFilter.class)
Expand Down

0 comments on commit 1288940

Please sign in to comment.