From fcbcd8ced12f945981cd61f3d8deb5836990b23a Mon Sep 17 00:00:00 2001 From: LEE SO JUNG <90453158+xxoznge@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:16:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B0=9B=EC=9D=80=20=EC=A0=9C=EC=95=88?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B0=9C=EB=B0=9C=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../propose/controller/ProposeController.java | 13 ++++++-- .../response/ReceiveProposeGetResponse.java | 32 +++++++++++++++++++ ...ponse.java => SendProposeGetResponse.java} | 6 ++-- .../propose/service/ProposeQueryService.java | 23 ++++++++++--- .../propose/service/ProposeService.java | 5 +-- .../propose/repository/ProposeRepository.java | 4 +++ 6 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ReceiveProposeGetResponse.java rename api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/{ProposeGetResponse.java => SendProposeGetResponse.java} (82%) diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java index cab6b55..cfa1743 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/controller/ProposeController.java @@ -16,7 +16,8 @@ import com.sponus.sponusbe.domain.organization.dto.response.PageResponse; import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest; import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse; -import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse; +import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse; +import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse; import com.sponus.sponusbe.domain.propose.service.ProposeQueryService; import com.sponus.sponusbe.domain.propose.service.ProposeService; @@ -42,10 +43,18 @@ public ApiResponse createPropose( } @GetMapping("/send") - public ApiResponse> getSendPropose( + public ApiResponse> getSendPropose( @AuthOrganization Organization authOrganization, @ModelAttribute @Valid PageCondition pageCondition ) { return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization, pageCondition)); } + + @GetMapping("/receive") + public ApiResponse> getReceivedPropose( + @AuthOrganization Organization authOrganization, + @ModelAttribute @Valid PageCondition pageCondition + ) { + return ApiResponse.onSuccess(proposequeryService.getReceivedPropose(authOrganization, pageCondition)); + } } diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ReceiveProposeGetResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ReceiveProposeGetResponse.java new file mode 100644 index 0000000..9f1d097 --- /dev/null +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ReceiveProposeGetResponse.java @@ -0,0 +1,32 @@ +package com.sponus.sponusbe.domain.propose.dto.response; + +import java.time.LocalDate; + +import com.sponus.coredomain.domain.propose.Propose; +import com.sponus.coredomain.domain.propose.ProposeStatus; + +import lombok.Builder; + +@Builder +public record ReceiveProposeGetResponse( + Long id, + Long organizationId, + Long target, + String organizationName, + String organizationImageUrl, + ProposeStatus status, + LocalDate createdAt +) { + + public static ReceiveProposeGetResponse from(Propose propose) { + return ReceiveProposeGetResponse.builder() + .id(propose.getId()) + .organizationId(propose.getOrganization().getId()) + .target(propose.getTarget().getId()) + .organizationName(propose.getOrganization().getName()) + .organizationImageUrl(propose.getOrganization().getImageUrl()) + .status(propose.getStatus()) + .createdAt(propose.getCreatedAt().toLocalDate()) + .build(); + } +} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/SendProposeGetResponse.java similarity index 82% rename from api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.java rename to api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/SendProposeGetResponse.java index b9a92b0..7d489c8 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/SendProposeGetResponse.java @@ -8,7 +8,7 @@ import lombok.Builder; @Builder -public record ProposeGetResponse( +public record SendProposeGetResponse( Long id, Long organizationId, Long target, @@ -18,8 +18,8 @@ public record ProposeGetResponse( LocalDate createdAt ) { - public static ProposeGetResponse from(Propose propose) { - return ProposeGetResponse.builder() + public static SendProposeGetResponse from(Propose propose) { + return SendProposeGetResponse.builder() .id(propose.getId()) .organizationId(propose.getOrganization().getId()) .target(propose.getTarget().getId()) diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java index bccdc39..7f46772 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeQueryService.java @@ -12,7 +12,8 @@ import com.sponus.coredomain.domain.propose.repository.ProposeRepository; import com.sponus.sponusbe.domain.organization.dto.request.PageCondition; import com.sponus.sponusbe.domain.organization.dto.response.PageResponse; -import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse; +import com.sponus.sponusbe.domain.propose.dto.response.ReceiveProposeGetResponse; +import com.sponus.sponusbe.domain.propose.dto.response.SendProposeGetResponse; import lombok.RequiredArgsConstructor; @@ -23,16 +24,30 @@ public class ProposeQueryService { private final ProposeRepository proposeRepository; - public PageResponse getSendPropose(Organization organization, PageCondition pageCondition) { + public PageResponse getSendPropose(Organization organization, PageCondition pageCondition) { Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize()); - List organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc( + List organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc( organization, pageable) .stream() - .map(ProposeGetResponse::from) + .map(SendProposeGetResponse::from) .toList(); return PageResponse.of( PageableExecutionUtils.getPage(organizations, pageable, () -> proposeRepository.countByOrganization(organization))); } + + public PageResponse getReceivedPropose(Organization organization, + PageCondition pageCondition) { + Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize()); + List receivedProposes = proposeRepository.findByTargetOrderByCreatedAtDesc( + organization, pageable) + .stream() + .map(ReceiveProposeGetResponse::from) + .toList(); + + return PageResponse.of( + PageableExecutionUtils.getPage(receivedProposes, pageable, + () -> proposeRepository.countByTarget(organization))); + } } diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java index 8b06cba..7dc7819 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/service/ProposeService.java @@ -38,10 +38,7 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre if (organization.getImageUrl() == null || organization.getImageUrl().isEmpty()) throw new ProposeException(ProposeErrorCode.PROFILE_NOT_COMPLETED); - - if (proposeRepository.existsByOrganization(target)) - throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - + final Long count = proposeRepository.countProposesByOrganizationToday(organization, LocalDateTime.now().toLocalDate().atStartOfDay()); diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeRepository.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeRepository.java index 0e5398f..913418f 100644 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeRepository.java +++ b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeRepository.java @@ -24,4 +24,8 @@ Long countProposesByOrganizationToday(@Param("organization") Organization organi Page findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable); Long countByOrganization(Organization organization); + + Page findByTargetOrderByCreatedAtDesc(Organization target, Pageable pageable); + + Long countByTarget(Organization target); }