-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from TogetherWithOcean-TWO/SCRUM-122-recommend
일주일마다 장소 추천 로직 및 추천 장소 조회
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
TWO/src/main/java/com/togetherwithocean/TWO/Recommend/Controller/RecommendController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.togetherwithocean.TWO.Recommend.Controller; | ||
|
||
import com.togetherwithocean.TWO.Recommend.DTO.RecommendPlaceDTO; | ||
import com.togetherwithocean.TWO.Recommend.Service.RecommendService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@RequestMapping("/recommend") | ||
public class RecommendController { | ||
private final RecommendService recommendService; | ||
@GetMapping("") | ||
public ResponseEntity<RecommendPlaceDTO> getRecommendPlace(Authentication principal) { | ||
if (principal == null) | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); | ||
RecommendPlaceDTO recommendPlace = recommendService.getRecommendPlace(); | ||
return ResponseEntity.status(HttpStatus.OK).body(recommendPlace); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
TWO/src/main/java/com/togetherwithocean/TWO/Recommend/DTO/RecommendPlaceDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.togetherwithocean.TWO.Recommend.DTO; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class RecommendPlaceDTO { | ||
String name; | ||
Double latitude; | ||
Double longtitude; | ||
String direction; | ||
|
||
@Builder | ||
public RecommendPlaceDTO(String name, Double latitude, Double longtitude, String direction) { | ||
this.name = name; | ||
this.latitude = latitude; | ||
this.longtitude = longtitude; | ||
this.direction = direction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
TWO/src/main/java/com/togetherwithocean/TWO/Recommend/Service/RecommendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.togetherwithocean.TWO.Recommend.Service; | ||
|
||
import com.togetherwithocean.TWO.Member.Domain.Member; | ||
import com.togetherwithocean.TWO.Recommend.DTO.RecommendPlaceDTO; | ||
import com.togetherwithocean.TWO.Recommend.Domain.Recommend; | ||
import com.togetherwithocean.TWO.Recommend.Repository.RecommendRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecommendService { | ||
private final RecommendRepository recommendRepository; | ||
|
||
String findNowDirection() { | ||
Long recCount = recommendRepository.getRecommendedCount(); // 지금까지 추천한 장소의 개수 | ||
|
||
// 추천한 장소 개수를 기반으로 이번에 추천할 장소의 위치 결정 | ||
String direction = ""; | ||
if (recCount % 4 == 0) | ||
direction = "동해"; | ||
else if (recCount % 4 == 1) | ||
direction = "서해"; | ||
else if (recCount % 4 == 2) | ||
direction = "남해"; | ||
else if (recCount % 4 == 3) | ||
direction = "제주도"; | ||
|
||
return direction; | ||
} | ||
|
||
public RecommendPlaceDTO getRecommendPlace() { | ||
Recommend recommendLoc = recommendRepository.getRecommendByDir(findNowDirection()); | ||
|
||
return RecommendPlaceDTO.builder() | ||
.longtitude(recommendLoc.getLongitude()) | ||
.latitude(recommendLoc.getLatitude()) | ||
.direction(recommendLoc.getDirection()) | ||
.name(recommendLoc.getName()) | ||
.build(); | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 * * SUN") | ||
public void initDailyAchieve() { | ||
// 한 주간 추천한 장소 플래그 true로 변경 | ||
String nowDirection = findNowDirection(); | ||
Recommend nowRecommend = recommendRepository.getRecommendByDir(nowDirection); | ||
nowRecommend.setRecs(true); | ||
recommendRepository.save(nowRecommend); | ||
|
||
// 해당 direction의 장소들이 이미 모두 추천된 경우 (새로 추천할 장소가 없는 경우) | ||
// -> 해당 direction 장소들의 추천 여부를 다시 전부 false로 변경 | ||
if (recommendRepository.getRecommendByDir(findNowDirection()) == null) { | ||
recommendRepository.updateRecsFalseByDirection(nowDirection); | ||
} | ||
} | ||
} |