diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java index dd81fe41..feef70c9 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java @@ -27,11 +27,11 @@ public class TacticController { @Operation(summary = "전술 목록 조회", description = "전체 전술 목록을 조회합니다. 단, 공개(anonymous가 false) 인 전술만 조회. 페이징 적용, 생성 날짜 기준 내림차순 정렬.") @GetMapping - public ApiResponse> getTacticList( + public ApiResponse> getTacticList( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) { Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); - Page tacticLists = tacticQueryService.getTactics(pageable); + Page tacticLists = tacticQueryService.getTactics(pageable); return ApiResponse.onSuccess(tacticLists); } @@ -56,7 +56,7 @@ public ApiResponse> getUserTactic( @Operation(summary = "제목으로 전술 검색", description = "제목으로 전술을 검색합니다. 단, 공개(anonymous가 false) 인 전술만 검색가능. 페이징 적용, 생성 날짜 기준 내림차순 정렬.") @GetMapping("/search") public ApiResponse> searchTitle( - @RequestParam(value ="title",required = false) String title, + @RequestParam(value = "title", required = false) String title, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) { Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); @@ -66,7 +66,7 @@ public ApiResponse> searchTitle( @Operation(summary = "전술 생성", description = "전술을 생성합니다. 프로필이 생성이 된 후에 작성 가능.") @PostMapping - public ApiResponse createTactic(@Valid @RequestBody TacticCreateRequest request, @LoginUser User user){ + public ApiResponse createTactic(@Valid @RequestBody TacticCreateRequest request, @LoginUser User user) { TacticResponse tacticDetail = tacticService.createTactic(request, user); return ApiResponse.onSuccess(tacticDetail); } @@ -82,14 +82,14 @@ public ApiResponse updateTactic(@PathVariable(name = "tacticId") @Operation(summary = "전술 복사후 가져오기", description = "다른 사람의 전술을 복사해서 작성자를 자신으로 하여 저장.") @PostMapping("/{tacticId}") - public ApiResponse copyTactic(@PathVariable(name = "tacticId") Long tacticId, @LoginUser User user){ + public ApiResponse copyTactic(@PathVariable(name = "tacticId") Long tacticId, @LoginUser User user) { TacticResponse tacticDetail = tacticService.copyTactic(tacticId, user); return ApiResponse.onSuccess(tacticDetail); } @Operation(summary = "전술 삭제", description = "자신의 전술 삭제. 전술 작성자 만이 삭제 가능.") @DeleteMapping("/{tacticId}") - public ApiResponse deleteTactic(@PathVariable(name = "tacticId") Long tacticId, @LoginUser User user){ + public ApiResponse deleteTactic(@PathVariable(name = "tacticId") Long tacticId, @LoginUser User user) { tacticService.deleteTactic(tacticId, user); return ApiResponse.noContent(); } @@ -123,7 +123,7 @@ public ApiResponse updateComment(@PathVariable(name = "commentI @Operation(summary = "전술 댓글 삭제", description = "자신의 댓글을 삭제하는 기능. 댓글 작성자 만이 삭제 가능.") @DeleteMapping("/comment/{commentId}") - public ApiResponse deleteComment(@PathVariable(name = "commentId") Long commentId, @LoginUser User user){ + public ApiResponse deleteComment(@PathVariable(name = "commentId") Long commentId, @LoginUser User user) { tacticService.deleteComment(commentId, user); return ApiResponse.onSuccess("댓글이 삭제 되었습니다."); } diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java b/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java index 21a85cf8..a6c2a13c 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; @Builder public record TacticDetailResponse( @@ -45,6 +46,33 @@ public static TacticDetailResponse from(Tactic tactic, Long likeCnt, Long commen .build(); } + @Builder + public record AllTacticList(Long tacticId, + Long userId, + String nickname, + String tacticName, + Boolean anonymous, + String mainFormation, + Long likeCnt, + Long commentCnt){ + public static AllTacticList from(Tactic tactic){ + return TacticDetailResponse.AllTacticList.builder() + .tacticId(tactic.getTacticId()) + .userId(tactic.getUser().getId()) + .nickname(tactic.getUser().getProfile().getNickname()) + .tacticName(tactic.getTacticName()) + .anonymous(tactic.isAnonymous()) + .mainFormation(tactic.getMainFormation()) + .likeCnt((long) tactic.getLikes().size()) + .commentCnt((long) tactic.getComments().size()) + .build(); + } + + public static List from(List tactics){ + return tactics.stream().map(TacticDetailResponse.AllTacticList::from).collect(Collectors.toList()); + } + } + @Builder public record DetailList( Long detailId, diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java index b3027e9b..15287983 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java @@ -22,9 +22,9 @@ public class TacticQueryService { private final TacticRepository tacticRepository; private final RedisUtil redisUtil; - public Page getTactics(Pageable pageable) { + public Page getTactics(Pageable pageable) { Page tactics = tacticRepository.findAllByAnonymousFalse(pageable); - return tactics.map(TacticResponse.TacticList::from); + return tactics.map(TacticDetailResponse.AllTacticList::from); } public Page getUserTactics(User user, Pageable pageable) {