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..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,26 +2,21 @@ 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.ModelAttribute; 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.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; import com.sponus.sponusbe.domain.propose.service.ProposeQueryService; import com.sponus.sponusbe.domain.propose.service.ProposeService; @@ -36,12 +31,21 @@ 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, + @ModelAttribute @Valid PageCondition pageCondition + ) { + return ApiResponse.onSuccess(proposequeryService.getSendPropose(authOrganization, pageCondition)); + } } 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..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 @@ -1,12 +1,38 @@ package com.sponus.sponusbe.domain.propose.service; +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; @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class ProposeQueryService { + + private final ProposeRepository proposeRepository; + + 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/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..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,8 +1,9 @@ package com.sponus.coredomain.domain.propose.repository; import java.time.LocalDateTime; -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; @@ -17,5 +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); + + Page findByOrganizationOrderByCreatedAtDesc(Organization organization, Pageable pageable); + + Long countByOrganization(Organization organization); }