From 24d5b654436cbef02bd1b887549cf32651a01d15 Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Sun, 30 Jun 2024 18:32:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=B3=B4=EB=82=B8=20=EC=A0=9C?= =?UTF-8?q?=EC=95=88=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../propose/controller/ProposeController.java | 18 ++++++----- .../dto/response/ProposeGetResponse.java | 32 +++++++++++++++++++ .../propose/service/ProposeQueryService.java | 15 +++++++++ .../propose/service/ProposeService.java | 7 ---- .../coredomain/domain/propose/Propose.java | 13 ++++++++ .../domain/propose/ProposeStatus.java | 4 +-- .../propose/repository/ProposeRepository.java | 3 ++ 7 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.java 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 2dbc14ca..8b82c26d 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 @@ -2,26 +2,20 @@ import static com.sponus.sponusbe.global.enums.ApiPath.*; -import java.io.IOException; import java.util.List; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import com.sponus.coredomain.domain.common.ApiResponse; import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coreinfrasecurity.annotation.AuthOrganization; 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.service.ProposeQueryService; import com.sponus.sponusbe.domain.propose.service.ProposeService; @@ -36,12 +30,20 @@ public class ProposeController { private final ProposeService proposeService; + private final ProposeQueryService proposequeryService; @PostMapping() public ApiResponse createPropose( @AuthOrganization Organization authOrganization, @RequestBody @Valid ProposeCreateRequest request - ){ + ) { return ApiResponse.onSuccess(proposeService.createPropose(authOrganization, request)); } + + @GetMapping("/send") + public ApiResponse> getSendPropose( + @AuthOrganization Organization authOrganization + ) { + return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization)); + } } 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/ProposeGetResponse.java new file mode 100644 index 00000000..b9a92b0f --- /dev/null +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeGetResponse.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 ProposeGetResponse( + Long id, + Long organizationId, + Long target, + String targetName, + String targetImageUrl, + ProposeStatus status, + LocalDate createdAt +) { + + public static ProposeGetResponse from(Propose propose) { + return ProposeGetResponse.builder() + .id(propose.getId()) + .organizationId(propose.getOrganization().getId()) + .target(propose.getTarget().getId()) + .targetName(propose.getTarget().getName()) + .targetImageUrl(propose.getTarget().getImageUrl()) + .status(propose.getStatus()) + .createdAt(propose.getCreatedAt().toLocalDate()) + .build(); + } +} 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 b2c378f4..65a288d6 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 @@ -1,12 +1,27 @@ package com.sponus.sponusbe.domain.propose.service; +import java.util.List; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.sponus.coredomain.domain.organization.Organization; +import com.sponus.coredomain.domain.propose.repository.ProposeRepository; +import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse; + import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class ProposeQueryService { + + private final ProposeRepository proposeRepository; + + public List getSendPropose(Organization organization) { + return proposeRepository.findByOrganizationOrderByCreatedAtDesc(organization) + .stream() + .map(ProposeGetResponse::from) + .toList(); + } } 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 ede2952a..8b06cba6 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 @@ -1,21 +1,14 @@ package com.sponus.sponusbe.domain.propose.service; -import java.lang.annotation.Target; import java.time.LocalDateTime; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.sponus.coredomain.domain.bookmark.Bookmark; import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coredomain.domain.organization.repository.OrganizationRepository; import com.sponus.coredomain.domain.propose.Propose; import com.sponus.coredomain.domain.propose.repository.ProposeRepository; -import com.sponus.coreinfrafirebase.FirebaseService; -import com.sponus.coreinfras3.S3Service; -import com.sponus.sponusbe.domain.bookmark.dto.response.BookmarkToggleResponse; -import com.sponus.sponusbe.domain.bookmark.exception.BookmarkErrorCode; -import com.sponus.sponusbe.domain.bookmark.exception.BookmarkException; import com.sponus.sponusbe.domain.organization.exception.OrganizationErrorCode; import com.sponus.sponusbe.domain.organization.exception.OrganizationException; import com.sponus.sponusbe.domain.propose.dto.request.ProposeCreateRequest; diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/Propose.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/Propose.java index e35f0abf..bbda198d 100644 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/Propose.java +++ b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/Propose.java @@ -1,5 +1,9 @@ package com.sponus.coredomain.domain.propose; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + import com.sponus.coredomain.domain.common.BaseEntity; import com.sponus.coredomain.domain.organization.Organization; @@ -7,6 +11,8 @@ import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; @@ -26,6 +32,8 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter @Entity +@DynamicUpdate +@DynamicInsert @Table(name = "propose") public class Propose extends BaseEntity { @@ -41,4 +49,9 @@ public class Propose extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinColumn(name = "target_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Organization target; + + @Enumerated(EnumType.STRING) + @ColumnDefault("'WAITING'") + @Column(name = "propose_status") + private ProposeStatus status; } diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeStatus.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeStatus.java index 35670bad..b8d779be 100644 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeStatus.java +++ b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeStatus.java @@ -1,9 +1,7 @@ package com.sponus.coredomain.domain.propose; public enum ProposeStatus { - // 제안을 보낸 측: PENDING - // 제안을 받은 측: VIEWED, ACCEPTED, REJECTED, SUSPENDED, PAID - PENDING, VIEWED, ACCEPTED, REJECTED, SUSPENDED, PAID, COMPLETED; + ACCEPTED, REJECTED, WAITING; public static ProposeStatus of(String input) { return ProposeStatus.valueOf(input.toUpperCase()); 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 5ea80827..bccc772f 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 @@ -1,6 +1,7 @@ package com.sponus.coredomain.domain.propose.repository; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -18,4 +19,6 @@ public interface ProposeRepository extends JpaRepository { @Query("SELECT COUNT(p) FROM Propose p WHERE p.organization = :organization AND p.createdAt >= :startOfDay") Long countProposesByOrganizationToday(@Param("organization") Organization organization, @Param("startOfDay") LocalDateTime startOfDay); + + List findByOrganizationOrderByCreatedAtDesc(Organization organization); } From e66229bd2030d199b82e0be830daf529ddd50db0 Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Sun, 30 Jun 2024 18:57:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EB=B3=B4=EB=82=B8=20=EC=A0=9C?= =?UTF-8?q?=EC=95=88=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../propose/controller/ProposeController.java | 12 +++++++----- .../propose/service/ProposeQueryService.java | 15 +++++++++++++-- .../propose/repository/ProposeRepository.java | 11 +++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) 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 8b82c26d..cab6b55a 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 @@ -2,9 +2,8 @@ import static com.sponus.sponusbe.global.enums.ApiPath.*; -import java.util.List; - import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -13,6 +12,8 @@ import com.sponus.coredomain.domain.common.ApiResponse; import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coreinfrasecurity.annotation.AuthOrganization; +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.request.ProposeCreateRequest; import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse; import com.sponus.sponusbe.domain.propose.dto.response.ProposeGetResponse; @@ -41,9 +42,10 @@ public ApiResponse createPropose( } @GetMapping("/send") - public ApiResponse> getSendPropose( - @AuthOrganization Organization authOrganization + public ApiResponse> getSendPropose( + @AuthOrganization Organization authOrganization, + @ModelAttribute @Valid PageCondition pageCondition ) { - return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization)); + return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization, pageCondition)); } } 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 65a288d6..bccdc392 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 @@ -2,11 +2,16 @@ import java.util.List; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.sponus.coredomain.domain.organization.Organization; 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 lombok.RequiredArgsConstructor; @@ -18,10 +23,16 @@ public class ProposeQueryService { private final ProposeRepository proposeRepository; - public List getSendPropose(Organization organization) { - return proposeRepository.findByOrganizationOrderByCreatedAtDesc(organization) + public PageResponse getSendPropose(Organization organization, PageCondition pageCondition) { + Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize()); + List organizations = proposeRepository.findByOrganizationOrderByCreatedAtDesc( + organization, pageable) .stream() .map(ProposeGetResponse::from) .toList(); + + return PageResponse.of( + PageableExecutionUtils.getPage(organizations, pageable, + () -> proposeRepository.countByOrganization(organization))); } } 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 bccc772f..0e5398f5 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 @@ -1,9 +1,9 @@ package com.sponus.coredomain.domain.propose.repository; import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -18,7 +18,10 @@ public interface ProposeRepository extends JpaRepository { // Optional findByOrganization(Organization organization); @Query("SELECT COUNT(p) FROM Propose p WHERE p.organization = :organization AND p.createdAt >= :startOfDay") - Long countProposesByOrganizationToday(@Param("organization") Organization organization, @Param("startOfDay") LocalDateTime startOfDay); + Long countProposesByOrganizationToday(@Param("organization") Organization organization, + @Param("startOfDay") LocalDateTime startOfDay); - List findByOrganizationOrderByCreatedAtDesc(Organization organization); + Page findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable); + + Long countByOrganization(Organization organization); }