Skip to content

Commit

Permalink
Merge pull request #220 from prgrms-web-devcourse-final-project/fix/#219
Browse files Browse the repository at this point in the history
-for-test

feat: ํ‚ค์›Œ๋“œ ํŽธ์ง€ ํ…Œ์ŠคํŠธ api ๊ตฌํ˜„
  • Loading branch information
l2yujw authored Dec 10, 2024
2 parents 93bdbde + 0921545 commit 7a1167f
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
package postman.bottler.keyword.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import postman.bottler.keyword.service.AsyncRecommendationService;
import postman.bottler.keyword.service.RedisLetterService;
import postman.bottler.user.auth.CustomUserDetails;
import postman.bottler.user.service.UserService;

@RestController
@RequiredArgsConstructor
@RequestMapping("/test/recommendations")
@Tag(name = "ํ…Œ์ŠคํŠธ์šฉ")
public class RecommendationController {

private final AsyncRecommendationService asyncRecommendationService;
private final RedisLetterService redisLetterService;
private final UserService userService;

@Operation(
summary = "ํ‚ค์›Œ๋“œ ํŽธ์ง€ ์ถ”์ฒœ ์š”์ฒญ",
description = "ํ˜„์žฌ 3๊ฐœ๊ฐ€ ์ถ”์ฒœ๋ฉ๋‹ˆ๋‹ค"
)
@PostMapping("/process")
public ResponseEntity<String> processRecommendation(@AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<String> processRecommendation() {
// ๋น„๋™๊ธฐ ์ถ”์ฒœ ์ž‘์—… ์‹œ์ž‘
asyncRecommendationService.processRecommendationForUser(userDetails.getUserId());
List<Long> userIds = userService.getAllUserIds();
userIds.forEach(asyncRecommendationService::processRecommendationForUser);

return ResponseEntity.ok("Recommendation process started for user " + userDetails.getUserId());
return ResponseEntity.ok("Recommendation process started for user " + userIds);
}

@Operation(
summary = "์ถ”์ฒœ ๋œ ํŽธ์ง€ ์กฐํšŒ ์š”์ฒญ",
description = "ํ˜„์žฌ ์ถ”์ฒœ๋œ ํŽธ์ง€์˜ id ๋“ค์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค"
)
@GetMapping("/result")
public ResponseEntity<List<Long>> getRecommendationResult(@AuthenticationPrincipal CustomUserDetails userDetails) {
List<Long> result = redisLetterService.getRecommendations(userDetails.getUserId());
public ResponseEntity<Map<Long, List<Long>>> getRecommendationResult() {
List<Long> userIds = userService.getAllUserIds();
Map<Long, List<Long>> result = new HashMap<>();
userIds.forEach(userId ->
result.put(userId, redisLetterService.getRecommendations(userId))
);

return ResponseEntity.ok(result);
}
Expand All @@ -49,10 +58,10 @@ public ResponseEntity<List<Long>> getRecommendationResult(@AuthenticationPrincip
description = "๊ธฐ์กด ์ถ”์ฒœ๋œ ํŽธ์ง€ ์ค‘ ๊ฐ€์žฅ ์˜ค๋ž˜๋œ ํŽธ์ง€๋ฅผ ๋ฐ€์–ด๋‚ด๊ณ  ์ถ”์ฒœ ํ›„๋ณด ์ค‘ ์กฐ๊ฑด์— ๋งž๋Š” ํŽธ์ง€ id๋ฅผ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค."
)
@PostMapping("/update")
public ResponseEntity<String> updateRecommendationsFromTemp(
@AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<String> updateRecommendationsFromTemp() {
List<Long> userIds = userService.getAllUserIds();
try {
redisLetterService.updateRecommendationsFromTemp(userDetails.getUserId());
userIds.forEach(redisLetterService::updateRecommendationsFromTemp);
return ResponseEntity.ok("์ถ”์ฒœ ํ‚ค์›Œ๋“œ ํŽธ์ง€ ๋ณ€๊ฒฝ ์™„๋ฃŒ");
} catch (Exception e) {
return ResponseEntity.status(500).body("Failed to update recommendations: " + e.getMessage());
Expand All @@ -65,8 +74,11 @@ public ResponseEntity<String> updateRecommendationsFromTemp(
+ "\n ์ถ”์ฒœํ•  ๋•Œ ํŽธ์ง€๊ฐ€ ์‚ญ์ œ๋˜์–ด ์žˆ์„ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ธฐ ๋–„๋ฌธ์— ๊ฒ€์ฆ ํ›„ ์ˆœ์ฐจ์ ์œผ๋กœ ์ด์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค."
)
@GetMapping("/temp")
public ResponseEntity<List<Long>> getRecommendTemp(@AuthenticationPrincipal CustomUserDetails userDetails) {
List<Long> result = redisLetterService.getRecommendedTemp(userDetails.getUserId());
public ResponseEntity<Map<Long, List<Long>>> getRecommendTemp() {
List<Long> userIds = userService.getAllUserIds();
Map<Long, List<Long>> result = new HashMap<>();
userIds.forEach(userId -> result.put(userId, redisLetterService.getRecommendations(userId))
);
return ResponseEntity.ok(result);
}
}

0 comments on commit 7a1167f

Please sign in to comment.