diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index 36500a8b..96f7e436 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -1,83 +1,101 @@ package com.bbteam.budgetbuddies.domain.comment.controller; - import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.responses.ApiResponses; +import com.bbteam.budgetbuddies.domain.comment.service.CommentService; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -public interface CommentController { - @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveDiscountInfoComment( - Long userId, - CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); - - - @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") - }) - ResponseEntity> findAllByDiscountInfo( - Long discountInfoId, - Pageable pageable); - - @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveSupportInfoComment( - Long userId, - CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); - - @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") - - - }) - ResponseEntity> findAllBySupportInfo( - Long supportInfoId, - Pageable pageable); - - @Operation(summary = "[User] 특정 댓글 삭제하기", description = "특정 댓글을 삭제하는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") - }) - @GetMapping("/comments/delete") - ResponseEntity deleteComment(Long commentId); +import org.springframework.web.bind.annotation.*; + +@RestController +public class CommentController implements CommentControllerApi { + + @Qualifier("discountCommentService") + private final CommentService discountCommentService; + + @Qualifier("supportCommentService") + private final CommentService supportCommentService; + + public CommentController(CommentService discountCommentService, + CommentService supportCommentService) { + this.discountCommentService = discountCommentService; + this.supportCommentService = supportCommentService; + } + + @PostMapping("/discounts/comments") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoCommentDto dto = discountCommentService.saveComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/discounts/comments") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = discountCommentService.findByInfoWithPaging(discountInfoId, pageable); + return ResponseEntity.ok(result); + } + + + @PostMapping("/supports/comments") + public ResponseEntity saveSupportInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ + CommentResponseDto.SupportInfoCommentDto dto = supportCommentService.saveComment(userId, supportInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/supports/comments") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId, + @PageableDefault(size = 20, page = 0)Pageable pageable){ + Page result = supportCommentService.findByInfoWithPaging(supportInfoId, pageable); + return ResponseEntity.ok(result); + } + + @PostMapping("/comments/delete") + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + discountCommentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } + + @GetMapping("/supports/comments/modify") + public ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/supports/comments/modify") + public ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + @GetMapping("/discounts/comments/modify") + public ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/discounts/comments/modify") + public ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java new file mode 100644 index 00000000..ecaa37a4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -0,0 +1,126 @@ +package com.bbteam.budgetbuddies.domain.comment.controller; + + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +public interface CommentControllerApi { + @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveDiscountInfoComment( + Long userId, + CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); + + + @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + }) + ResponseEntity> findAllByDiscountInfo( + Long discountInfoId, + Pageable pageable); + + @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveSupportInfoComment( + Long userId, + CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); + + @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + + + }) + ResponseEntity> findAllBySupportInfo( + Long supportInfoId, + Pageable pageable); + + @Operation(summary = "[User] 특정 댓글 삭제하기", description = "특정 댓글을 삭제하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") + }) + ResponseEntity deleteComment(Long commentId); + + @Operation(summary = "[User] SupportInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] SupprotInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + + + @Operation(summary = "[User] DiscountInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] DiscountInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java deleted file mode 100644 index 8f9691d7..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.controller; - -import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; -import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -import com.bbteam.budgetbuddies.domain.comment.service.CommentService; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequiredArgsConstructor -public class CommentControllerImpl implements CommentController{ - - private final CommentService commentService; - - @PostMapping("/discounts/comments") - public ResponseEntity saveDiscountInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ - CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); - return ResponseEntity.ok(dto); - } - - - @GetMapping("/discounts/comments") - public ResponseEntity> findAllByDiscountInfo( - @RequestParam("discountInfoId") Long discountInfoId, - @PageableDefault(size = 20, page = 0) Pageable pageable){ - Page result = commentService.findByDiscountInfoWithPaging(discountInfoId, pageable); - return ResponseEntity.ok(result); - } - - - @PostMapping("/supports/comments") - public ResponseEntity saveSupportInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ - CommentResponseDto.SupportInfoSuccessDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); - return ResponseEntity.ok(dto); - } - - - @GetMapping("/supports/comments") - public ResponseEntity> findAllBySupportInfo( - @RequestParam("supportInfoId") Long supportInfoId, - @PageableDefault(size = 20, page = 0)Pageable pageable){ - Page result = commentService.findBySupportInfoWithPaging(supportInfoId, pageable); - return ResponseEntity.ok(result); - } - - - public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { - commentService.deleteComment(commentId); - return ResponseEntity.ok("ok"); - } - -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java index 626a1e6f..8e424e50 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java @@ -36,6 +36,7 @@ public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } @@ -47,26 +48,10 @@ public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(C .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } - public static CommentResponseDto.DiscountInfoSuccessDto toDiscountInfoSuccessDto(Comment comment){ - return CommentResponseDto.DiscountInfoSuccessDto.builder() - .commentId(comment.getId()) - .discountInfoId(comment.getDiscountInfo().getId()) - .userId(comment.getUser().getId()) - .content(comment.getContent()) - .build(); - } - - public static CommentResponseDto.SupportInfoSuccessDto toSupportInfoSuccessDto(Comment comment){ - return CommentResponseDto.SupportInfoSuccessDto.builder() - .commentId(comment.getId()) - .supportInfoId(comment.getSupportInfo().getId()) - .userId(comment.getUser().getId()) - .content(comment.getContent()) - .build(); - } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java index 45b91e8e..9b516614 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Getter; -import lombok.Setter; public class CommentRequestDto { @@ -19,4 +18,11 @@ public static class SupportInfoCommentDto { private String content; private Long supportInfoId; } + + @Getter + @Builder + public static class CommentModifyDto { + private String content; + private Long commentId; + } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java index bfc27405..932cad45 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java @@ -4,6 +4,9 @@ import lombok.Builder; import lombok.Getter; +import java.time.LocalDate; +import java.time.LocalDateTime; + public class CommentResponseDto { @Getter @@ -14,6 +17,7 @@ public static class DiscountInfoCommentDto{ private Long discountInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } @Getter @@ -24,24 +28,9 @@ public static class SupportInfoCommentDto{ private Long supportInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } - @Getter - @Builder - public static class DiscountInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long discountInfoId; - private String content; - } - @Getter - @Builder - public static class SupportInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long supportInfoId; - private String content; - } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java index ce3ecccc..81827240 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java @@ -41,4 +41,9 @@ public class Comment extends BaseEntity { @Column(nullable = false) private Integer anonymousNumber; + public void modifyComment(String newComment) { + this.content = newComment; + return; + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java new file mode 100644 index 00000000..9bf31236 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java @@ -0,0 +1,27 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; + +import java.util.NoSuchElementException; +import java.util.Optional; + +public abstract class AbstractCommentService implements CommentService { + + protected final CommentRepository commentRepository; + + public AbstractCommentService(CommentRepository commentRepository) { + this.commentRepository = commentRepository; + } + + @Override + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public Optional findById(Long commentId) { + return commentRepository.findById(commentId); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java index ac49bc5a..29661e29 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java @@ -1,40 +1,39 @@ package com.bbteam.budgetbuddies.domain.comment.service; +import com.bbteam.budgetbuddies.domain.comment.converter.CommentConverter; import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; -public interface CommentService { - CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto); - CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto); +public interface CommentService { - /** - * - * @param discountInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findByDiscountInfo(Long discountInfoId); + T saveComment(Long userId, R dto); - /** - * - * @param supportInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findBySupportInfo(Long supportInfoId); - Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable); - Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable); + List findByInfo(Long infoId); + + + Page findByInfoWithPaging(Long infoId, Pageable pageable); + void deleteComment(Long commentId); + T findCommentOne(Long commentId); + T modifyComment(CommentRequestDto.CommentModifyDto dto); + Optional findById(Long commentId); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java deleted file mode 100644 index df8063fa..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.service; - - -import com.bbteam.budgetbuddies.domain.comment.converter.CommentConverter; -import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; -import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -import com.bbteam.budgetbuddies.domain.comment.entity.Comment; -import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; -import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; -import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; -import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; -import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; -import com.bbteam.budgetbuddies.domain.user.entity.User; -import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.HashMap; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.stream.Collectors; - -// 임시로 유저는 service에서 찾아서 처리하는 로직으로 작성함 -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CommentServiceImpl implements CommentService{ - - private final CommentRepository commentRepository; - private final UserRepository userRepository; - private final DiscountInfoRepository discountInfoRepository; - private final SupportInfoRepository supportInfoRepository; - - @Override - @Transactional - public CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { - User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); - SupportInfo supportInfo = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException()); - int anonymousNumber = getSupportAnonymousNumber(user, supportInfo); - Comment comment = CommentConverter.toSupportComment(dto, user, supportInfo, anonymousNumber); - Comment savedComment = commentRepository.save(comment); - - return CommentConverter.toSupportInfoSuccessDto(savedComment); - } - - private int getSupportAnonymousNumber(User user, SupportInfo supportInfo) { - int anonymousNumber; - Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, supportInfo); - if(foundComment.isEmpty()){ - anonymousNumber = supportInfo.addAndGetAnonymousNumber(); - } else { - anonymousNumber = foundComment.get().getAnonymousNumber(); - } - return anonymousNumber; - } - - - @Override - @Transactional - public CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { - User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); - DiscountInfo discountInfo = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException()); - int anonymousNumber = getDiscountAnonymousNumber(user, discountInfo); - Comment comment = CommentConverter.toDiscountComment(dto, user, discountInfo, anonymousNumber); - Comment savedComment = commentRepository.save(comment); - - return CommentConverter.toDiscountInfoSuccessDto(savedComment); - } - - private int getDiscountAnonymousNumber(User user, DiscountInfo discountInfo) { - int anonymousNumber; - Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, discountInfo); - if(foundComment.isEmpty()){ - anonymousNumber = discountInfo.addAndGetAnonymousNumber(); - } else { - anonymousNumber = foundComment.get().getAnonymousNumber(); - } - return anonymousNumber; - } - - @Override - public List findByDiscountInfo(Long discountInfoId) { - List commentList = commentRepository.findByDiscountInfo(discountInfoId); - - HashMap anonymousMapping = countAnonymousNumber(commentList); - List collect = commentList.stream() - .map(CommentConverter::toDiscountInfoCommentDto) - .collect(Collectors.toList()); - return collect; - - } - - @Override - public List findBySupportInfo(Long supportInfoId) { - List commentList = commentRepository.findBySupportInfo(supportInfoId); - HashMap anonymousMapping = countAnonymousNumber(commentList); - List collect = commentList.stream() - .map(CommentConverter::toSupportInfoCommentDto) - .collect(Collectors.toList()); - return collect; - } - - private static HashMap countAnonymousNumber(List commentList) { - HashMap anonymousMapping = new HashMap<>(); - Long count = 1L; - for (Comment comment : commentList) { - Long id = comment.getUser().getId(); - if(!anonymousMapping.containsKey(id)){ - anonymousMapping.put(id, count); - count++; - } - } - return anonymousMapping; - } - - @Override - public Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable) { - Page commentPage = commentRepository.findByDiscountInfoWithPaging(discountInfoId, pageable); - Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); - return result; - } - - @Override - public Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable) { - Page commentPage = commentRepository.findBySupportInfoWithPaging(supportInfoId, pageable); - Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); - return result; - } - - @Override - @Transactional - public void deleteComment(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); - commentRepository.delete(comment); - } -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java new file mode 100644 index 00000000..b5a146a4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java @@ -0,0 +1,103 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.converter.CommentConverter; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("discountCommentService") +@Transactional(readOnly = true) +public class DiscountCommentService extends AbstractCommentService { + private final UserRepository userRepository; + private final DiscountInfoRepository discountInfoRepository; + + public DiscountCommentService(CommentRepository commentRepository, UserRepository userRepository, DiscountInfoRepository discountInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.discountInfoRepository = discountInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto saveComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + DiscountInfo info = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toDiscountComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toDiscountInfoCommentDto(savedComment); + } + + + + private int getAnonymousNumber(User user, DiscountInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findByDiscountInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toDiscountInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findByDiscountInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.DiscountInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getDiscountInfo() == null){ + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toDiscountInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getDiscountInfo() == null) { + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toDiscountInfoCommentDto(comment); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java new file mode 100644 index 00000000..9e46d66b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java @@ -0,0 +1,102 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.converter.CommentConverter; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("supportCommentService") +@Transactional(readOnly = true) +public class SupportCommentService extends AbstractCommentService { + + private final UserRepository userRepository; + private final SupportInfoRepository supportInfoRepository; + + public SupportCommentService(CommentRepository commentRepository, UserRepository userRepository, SupportInfoRepository supportInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.supportInfoRepository = supportInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto saveComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + SupportInfo info = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toSupportComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toSupportInfoCommentDto(savedComment); + } + + private int getAnonymousNumber(User user, SupportInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findBySupportInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toSupportInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findBySupportInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.SupportInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getSupportInfo() == null){ + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toSupportInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getSupportInfo() == null) { + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toSupportInfoCommentDto(comment); + } +} diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java similarity index 87% rename from src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java rename to src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java index 47636c82..ff919466 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java @@ -12,10 +12,10 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -39,9 +39,15 @@ */ @SpringBootTest @Transactional -class CommentServiceTest { +class CommentServiceTestV2 { + + @Qualifier("discountCommentService") + @Autowired + CommentService discountCommentService; + + @Qualifier("supportCommentService") @Autowired - CommentService commentService; + com.bbteam.budgetbuddies.domain.comment.service.CommentService supportCommentService; @Autowired UserRepository userRepository; @@ -72,10 +78,10 @@ public void saveDiscountInfoCommentTest(){ .content("굿") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); + discountCommentService.saveComment(user1.getId(), dto1); em.flush(); - List returnDto = commentService.findByDiscountInfo(sale1.getId()); + List returnDto = discountCommentService.findByInfo(sale1.getId()); Assertions.assertThat(returnDto.size()).isEqualTo(1); Assertions.assertThat(returnDto.get(0).getDiscountInfoId()).isEqualTo(sale1.getId()); @@ -126,14 +132,14 @@ public void saveDiscountInfoCommentTest2(){ .content("유용해요!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); em.flush(); - List returnDto = commentService.findByDiscountInfo(sale1.getId()); - List returnDto2 = commentService.findByDiscountInfo(sale2.getId()); + List returnDto = discountCommentService.findByInfo(sale1.getId()); + List returnDto2 = discountCommentService.findByInfo(sale2.getId()); Assertions.assertThat(returnDto.size()).isEqualTo(2); Assertions.assertThat(returnDto.get(0).getDiscountInfoId()).isEqualTo(sale1.getId()); Assertions.assertThat(returnDto.get(0).getUserId()).isEqualTo(user1.getId()); @@ -199,16 +205,16 @@ void DiscountAnonymousCommentTest(){ .content("구웃!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); - commentService.saveDiscountComment(user1.getId(), dto4); - commentService.saveDiscountComment(user3.getId(), dto4); + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); em.flush(); - List result = commentService.findByDiscountInfo(sale1.getId()); + List result = discountCommentService.findByInfo(sale1.getId()); Integer test1 = result.get(0).getAnonymousNumber(); Integer test2 = result.get(1).getAnonymousNumber(); Integer test3 = result.get(2).getAnonymousNumber(); @@ -260,14 +266,14 @@ public void saveSupportInfoCommentTest2(){ .content("유용해요!") .build(); - commentService.saveSupportComment(user1.getId(), dto1); - commentService.saveSupportComment(user2.getId(), dto2); - commentService.saveSupportComment(user1.getId(), dto3); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); em.flush(); - List returnDto = commentService.findBySupportInfo(info1.getId()); - List returnDto2 = commentService.findBySupportInfo(info2.getId()); + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(info2.getId()); Assertions.assertThat(returnDto.size()).isEqualTo(2); Assertions.assertThat(returnDto.get(0).getSupportInfoId()).isEqualTo(info1.getId()); Assertions.assertThat(returnDto.get(0).getUserId()).isEqualTo(user1.getId()); @@ -347,17 +353,17 @@ void supportAnonymousCommentTest(){ .content("굿") .build(); - commentService.saveSupportComment(user1.getId(), dto1); - commentService.saveSupportComment(user2.getId(), dto2); - commentService.saveSupportComment(user1.getId(), dto3); - commentService.saveSupportComment(user3.getId(), dto4); - commentService.saveSupportComment(user4.getId(), dto5); - commentService.saveSupportComment(user1.getId(), dto6); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); em.flush(); - List returnDto = commentService.findBySupportInfo(info1.getId()); - List returnDto2 = commentService.findBySupportInfo(info2.getId()); + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(info2.getId()); Integer test1 = returnDto.get(0).getAnonymousNumber(); Integer test2 = returnDto.get(1).getAnonymousNumber(); @@ -422,19 +428,19 @@ void DiscountInfoCommentPagingTest() { .content("구웃!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); - commentService.saveDiscountComment(user1.getId(), dto4); - commentService.saveDiscountComment(user3.getId(), dto4); - commentService.saveDiscountComment(user2.getId(), dto4); + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + discountCommentService.saveComment(user2.getId(), dto4); //sale1 = 5 em.flush(); PageRequest pageRequest1 = PageRequest.of(0, 2); - Page result1 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest1); + Page result1 = discountCommentService.findByInfoWithPaging(sale1.getId(), pageRequest1); Assertions.assertThat(result1.getTotalElements()).isEqualTo(5); Assertions.assertThat(result1.getTotalPages()).isEqualTo(3); Assertions.assertThat(result1.hasNext()).isTrue(); @@ -446,7 +452,7 @@ void DiscountInfoCommentPagingTest() { PageRequest pageRequest2 = PageRequest.of(1, 3); - Page result2 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest2); + Page result2 = discountCommentService.findByInfoWithPaging(sale1.getId(), pageRequest2); Assertions.assertThat(result2.getTotalElements()).isEqualTo(5); Assertions.assertThat(result2.getTotalPages()).isEqualTo(2); Assertions.assertThat(result2.hasNext()).isFalse(); @@ -523,18 +529,18 @@ void SupportInfoPagingTest() { .content("굿") .build(); - commentService.saveSupportComment(user1.getId(), dto1); - commentService.saveSupportComment(user2.getId(), dto2); - commentService.saveSupportComment(user1.getId(), dto3); // 얘만 info2 - commentService.saveSupportComment(user3.getId(), dto4); - commentService.saveSupportComment(user4.getId(), dto5); - commentService.saveSupportComment(user1.getId(), dto6); - commentService.saveSupportComment(user2.getId(), dto5); - commentService.saveSupportComment(user3.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); // 얘만 info2 + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + supportCommentService.saveComment(user2.getId(), dto5); + supportCommentService.saveComment(user3.getId(), dto5); em.flush(); PageRequest pageRequest1 = PageRequest.of(0, 2); - Page result1 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest1); + Page result1 = supportCommentService.findByInfoWithPaging(info1.getId(), pageRequest1); Assertions.assertThat(result1.getTotalElements()).isEqualTo(7); Assertions.assertThat(result1.getTotalPages()).isEqualTo(4); @@ -546,7 +552,7 @@ void SupportInfoPagingTest() { Assertions.assertThat(list1.get(0).getAnonymousNumber()).isEqualTo(1); PageRequest pageRequest2 = PageRequest.of(1, 5); - Page result2 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest2); + Page result2 = supportCommentService.findByInfoWithPaging(info1.getId(), pageRequest2); Assertions.assertThat(result2.getTotalElements()).isEqualTo(7); Assertions.assertThat(result2.getTotalPages()).isEqualTo(2);