Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ dependencies {
// OpenCSV
implementation 'com.opencsv:opencsv:5.7.1'

// Cache
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'com.github.ben-manes.caffeine:caffeine'

// Servlet API
//compileOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
"/",
"/find-route",
"/index.html",
//"/assets/**",
"/assets/**",
"/login",
"/error",
"/oauth2/authorization/**",
"/login/oauth2/code/**",
"/api/auth/**",
"/swagger-ui/**",
"/v3/api-docs/**",
"/places/**"
//"/route/**"
"/places/**",
"/route/**",
"/api/place/**"
).permitAll() // 요청을 보낸 이가 누구이든 상관없이 통과되는 URL.
.requestMatchers( "/css/**", "/js/**", "/images/**").permitAll()
.anyRequest().authenticated()
Expand Down Expand Up @@ -92,7 +93,7 @@ public CorsConfigurationSource corsConfigurationSource() {
public WebSecurityCustomizer webSecurityCustomizer() {
return webSecurity -> {
webSecurity.ignoring()
.requestMatchers("/assets/**", "/route/**");
.requestMatchers("/assets/**");
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package _team.onmyway.controller;

import _team.onmyway.dto.PlaceDetailDTO;
import _team.onmyway.dto.UpdatePlaceDetailDTO;
import _team.onmyway.service.PlaceService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/place")
@RequiredArgsConstructor
public class PlaceController {

private final PlaceService placeService;

@GetMapping("/{id}")
public ResponseEntity<PlaceDetailDTO> getPlaceDetail(@PathVariable long id) {
PlaceDetailDTO placeDetailDTO = placeService.getHashtags(id);
return new ResponseEntity<>(placeDetailDTO, HttpStatus.OK);
}
}
8 changes: 8 additions & 0 deletions backend/src/main/java/_team/onmyway/dto/PlaceDetailDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package _team.onmyway.dto;

import java.util.List;

public record PlaceDetailDTO(
Long placeId,
List<String> hashtags
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Getter
@AllArgsConstructor
public class PlaceRecommendationDTO {
private Long id;
private String name;
private double lat;
private double lng;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static RecommendationResponseDTO from(List<PlaceRecommendationDTO> recomm
@Getter
@AllArgsConstructor
static class PlaceInfo {
private Long placeId;
private String name;
private double lat;
private double lng;
Expand All @@ -45,6 +46,7 @@ public static PlaceInfo from(PlaceRecommendationDTO p, double userLat, double us
int minutes = (int) (distance / 80); // 80m = 1분

return new PlaceInfo(
p.getId(),
p.getName(),
p.getLat(),
p.getLng(),
Expand Down
16 changes: 0 additions & 16 deletions backend/src/main/java/_team/onmyway/entity/Descriptions.java

This file was deleted.

2 changes: 2 additions & 0 deletions backend/src/main/java/_team/onmyway/entity/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Place {
@OneToMany(mappedBy = "place") // 양방향 연결
private List<WorkingTime> workingTimes = new ArrayList<>();

private String catchPhrase;

@BatchSize(size = 100)
@OneToMany(mappedBy = "place")
private List<Photos> photos = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package _team.onmyway.repository;

import _team.onmyway.entity.HashtagMapping;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface HashtagMappingRepository extends JpaRepository<HashtagMapping, Integer> {
@Query("select h.hashTag.tag from HashtagMapping h join h.hashTag where h.place.id =:placeId")
public List<String> findHashtagByPlaceId(Long placeId);
}
14 changes: 12 additions & 2 deletions backend/src/main/java/_team/onmyway/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import _team.onmyway.entity.Photos;
import _team.onmyway.entity.Place;
import _team.onmyway.repository.PhotosRepository;
import com.github.benmanes.caffeine.cache.Cache;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -18,15 +20,17 @@ public class ImageService {

private final WebClient webClient;
private final PhotosRepository photosRepository;
private final Cache<Long, String> placePhotoCache;

@Value("${naver.api.clientId}")
private String naverClientId;

@Value("${naver.api.clientSecret}")
private String naverClientSecret;

public ImageService(PhotosRepository photosRepository) {
public ImageService(PhotosRepository photosRepository, Cache<Long, String> placePhotoCache) {
this.photosRepository = photosRepository;
this.placePhotoCache = placePhotoCache;
this.webClient = WebClient.builder()
.baseUrl("https://openapi.naver.com")
.build();
Expand All @@ -37,8 +41,14 @@ public Mono<String> getImageURL(Place p) {
if (hasPhoto) {
return Mono.just(photosRepository.findFirstByPlaceId(p.getId()).get().getPhotoURL());
} else {
String distinct = p.getAddress().split(" ")[2];
String cacheURL = placePhotoCache.getIfPresent(p.getId());
if (cacheURL != null) {
return Mono.just(cacheURL);
}

String distinct = p.getAddress();
String name = p.getName();

return webClient.get()
.uri(uri -> uri
.path("/v1/search/image")
Expand Down
25 changes: 25 additions & 0 deletions backend/src/main/java/_team/onmyway/service/PlaceService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package _team.onmyway.service;

import _team.onmyway.dto.PlaceDetailDTO;
import _team.onmyway.dto.UpdatePlaceDetailDTO;
import _team.onmyway.entity.HashtagMapping;
import _team.onmyway.repository.HashtagMappingRepository;
import _team.onmyway.repository.PlaceRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PlaceService {

private final HashtagMappingRepository hashtagMappingRepository;

public PlaceDetailDTO getHashtags(Long placeId) {
List<String> hashtagMappings = hashtagMappingRepository.findHashtagByPlaceId(placeId);

PlaceDetailDTO placeDetail = new PlaceDetailDTO(placeId, hashtagMappings);
return placeDetail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ private PlaceRecommendationDTO toPlaceRecommendationDTO(Place place, double user
double distance = geoDistanceService.distanceMeters(userLat, userLng, place.getLat(), place.getLng());
int walkingMinutes = geoDistanceService.estimateWalkingMinutes(distance);
return new PlaceRecommendationDTO(
place.getId(),
place.getName(),
place.getLat(),
place.getLng(),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ jwt.refresh-expiration=${REFRESH_TOKEN_EXPIRATION}
#Tmap api
tmap.api.key=${TMAP_API_KEY}

#Naver api
# Naver api
naver.api.clientId=${NAVER_CLIENT_ID}
naver.api.clientSecret=${NAVER_CLIENT_SECRET}