From 3b160c52d4d5df0e9a588cdf6d8dc1a5515d2eab Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Tue, 28 May 2024 21:59:33 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=A0=9C=EC=95=88=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EA=B8=B0=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 --- .../dto/request/BookmarkToggleRequest.java | 3 + .../bookmark/service/BookmarkService.java | 2 - .../propose/controller/ProposeController.java | 81 +------------ .../dto/request/ProposeCreateRequest.java | 24 +--- .../request/ProposeStatusUpdateRequest.java | 9 -- .../dto/request/ProposeUpdateRequest.java | 7 -- .../response/DateGroupedProposeResponse.java | 21 ---- .../response/ProposeAttachmentResponse.java | 20 ---- .../dto/response/ProposeCreateResponse.java | 17 ++- .../response/ProposeDetailGetResponse.java | 47 -------- .../response/ProposeSummaryGetResponse.java | 36 ------ .../propose/exception/ProposeErrorCode.java | 4 - .../propose/service/ProposeQueryService.java | 23 ---- .../propose/service/ProposeService.java | 111 ++++-------------- .../coredomain/domain/propose/Propose.java | 52 +------- .../domain/propose/ProposeAttachment.java | 50 -------- .../domain/propose/ProposeImage.java | 49 -------- .../ProposeAttachmentRepository.java | 9 -- .../repository/ProposeImageRepository.java | 9 -- .../propose/repository/ProposeRepository.java | 5 +- .../propose/ProposeCustomRepositoryImpl.java | 98 ++++++++-------- 21 files changed, 114 insertions(+), 563 deletions(-) delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeStatusUpdateRequest.java delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeUpdateRequest.java delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/DateGroupedProposeResponse.java delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeAttachmentResponse.java delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeDetailGetResponse.java delete mode 100644 api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeSummaryGetResponse.java delete mode 100644 core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeAttachment.java delete mode 100644 core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeImage.java delete mode 100644 core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeAttachmentRepository.java delete mode 100644 core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeImageRepository.java diff --git a/api/src/main/java/com/sponus/sponusbe/domain/bookmark/dto/request/BookmarkToggleRequest.java b/api/src/main/java/com/sponus/sponusbe/domain/bookmark/dto/request/BookmarkToggleRequest.java index aa9ed0c0..f12daee2 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/bookmark/dto/request/BookmarkToggleRequest.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/bookmark/dto/request/BookmarkToggleRequest.java @@ -3,7 +3,10 @@ import com.sponus.coredomain.domain.bookmark.Bookmark; import com.sponus.coredomain.domain.organization.Organization; +import jakarta.validation.constraints.NotNull; + public record BookmarkToggleRequest( + @NotNull Long target ) { diff --git a/api/src/main/java/com/sponus/sponusbe/domain/bookmark/service/BookmarkService.java b/api/src/main/java/com/sponus/sponusbe/domain/bookmark/service/BookmarkService.java index 6242cd76..a82fcc54 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/bookmark/service/BookmarkService.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/bookmark/service/BookmarkService.java @@ -44,6 +44,4 @@ public BookmarkToggleResponse bookmarkToggle(Organization organization, Bookmark return BookmarkToggleResponse.from(bookmark, true); }); } - - } 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 ea88ddb3..2dbc14ca 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 @@ -21,11 +21,7 @@ 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.request.ProposeStatusUpdateRequest; -import com.sponus.sponusbe.domain.propose.dto.request.ProposeUpdateRequest; -import com.sponus.sponusbe.domain.propose.dto.response.DateGroupedProposeResponse; import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse; -import com.sponus.sponusbe.domain.propose.dto.response.ProposeDetailGetResponse; import com.sponus.sponusbe.domain.propose.service.ProposeQueryService; import com.sponus.sponusbe.domain.propose.service.ProposeService; @@ -40,81 +36,12 @@ public class ProposeController { private final ProposeService proposeService; - private final ProposeQueryService proposeQueryService; - @PostMapping(consumes = "multipart/form-data") + @PostMapping() public ApiResponse createPropose( @AuthOrganization Organization authOrganization, - @RequestPart("request") @Valid ProposeCreateRequest request, - @RequestPart(value = "attachments", required = false) List attachments - ) throws IOException { - return ApiResponse.onSuccess( - proposeService.createPropose( - authOrganization, - request, - attachments == null ? List.of() : attachments - ) - ); + @RequestBody @Valid ProposeCreateRequest request + ){ + return ApiResponse.onSuccess(proposeService.createPropose(authOrganization, request)); } - - @GetMapping("/sent") - public ApiResponse> getSentProposes( - @AuthOrganization Organization authOrganization - ) { - return ApiResponse.onSuccess(proposeQueryService.getSentProposes(authOrganization)); - } - - @GetMapping("/received") - public ApiResponse> getReceivedProposes( - @AuthOrganization Organization authOrganization, - @RequestParam(required = false) Long announcementId - ) { - return ApiResponse.onSuccess(proposeQueryService.getReceivedProposes(authOrganization, announcementId)); - } - - @GetMapping("/{proposeId}") - public ApiResponse getProposeDetail( - @AuthOrganization Organization authOrganization, - @PathVariable Long proposeId - ) { - return ApiResponse.onSuccess(proposeService.getProposeDetail(authOrganization, proposeId)); - } - - @PatchMapping(value = "/{proposeId}", consumes = "multipart/form-data") - public ApiResponse updatePropose( - @AuthOrganization Organization authOrganization, - @PathVariable Long proposeId, - @RequestPart @Valid ProposeUpdateRequest request, - @RequestPart(value = "attachments", required = false) List attachments - ) { - proposeService.updatePropose( - authOrganization, - proposeId, - request, - attachments == null ? List.of() : attachments); - return ApiResponse.onSuccess(null); - } - - @PatchMapping(value = "/{proposeId}/status") - public ApiResponse acceptPropose( - @AuthOrganization Organization authOrganization, - @PathVariable Long proposeId, - @RequestBody @Valid ProposeStatusUpdateRequest request - ) { - proposeService.updateProposeStatus( - authOrganization, - proposeId, - request); - return ApiResponse.onSuccess(null); - } - - @DeleteMapping("/{proposeId}") - public ApiResponse deletePropose( - @AuthOrganization Organization authOrganization, - @PathVariable Long proposeId - ) { - proposeService.deletePropose(authOrganization, proposeId); - return ApiResponse.onSuccess(null); - } - } diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeCreateRequest.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeCreateRequest.java index 90a85c16..d3cb6ce0 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeCreateRequest.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeCreateRequest.java @@ -1,5 +1,6 @@ package com.sponus.sponusbe.domain.propose.dto.request; +import com.sponus.coredomain.domain.bookmark.Bookmark; import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coredomain.domain.propose.Propose; import com.sponus.coredomain.domain.propose.ProposeStatus; @@ -8,26 +9,13 @@ import jakarta.validation.constraints.NotNull; public record ProposeCreateRequest( - - @NotBlank(message = "[ERROR] 제안 제목 입력은 필수 입니다.") - String title, - - @NotBlank(message = "[ERROR] 제안 내용 입력은 필수 입니다.") - String content, - - @NotNull(message = "[ERROR] 제안 대상 공고 입력은 필수 입니다.") - Long announcementId + @NotNull + Long target ) { - public Propose toEntity( - Organization proposedOrganization, - Organization proposingOrganization - ) { + public Propose toEntity(Organization organization, Organization target) { return Propose.builder() - .title(title) - .content(content) - .status(ProposeStatus.PENDING) - .proposedOrganization(proposedOrganization) - .proposingOrganization(proposingOrganization) + .organization(organization) + .target(target) .build(); } } diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeStatusUpdateRequest.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeStatusUpdateRequest.java deleted file mode 100644 index 64b27075..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeStatusUpdateRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.request; - -import jakarta.validation.constraints.NotBlank; - -public record ProposeStatusUpdateRequest( - @NotBlank(message = "[ERROR] 제안 상태 입력은 필수 입니다.") - String status -) { -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeUpdateRequest.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeUpdateRequest.java deleted file mode 100644 index 0aaf37d3..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/request/ProposeUpdateRequest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.request; - -public record ProposeUpdateRequest( - String title, - String content -) { -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/DateGroupedProposeResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/DateGroupedProposeResponse.java deleted file mode 100644 index a26c63f4..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/DateGroupedProposeResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.response; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public record DateGroupedProposeResponse( - String createdDate, - List proposes -) { - public static List from(List proposes) { - final Map> groupedByDate = proposes.stream() - .collect(Collectors.groupingBy(ProposeSummaryGetResponse::createdDate)); - - // createdDate 내림차순으로 정렬된 결과를 List로 변환 - return groupedByDate.entrySet().stream() - .sorted(Map.Entry.>comparingByKey().reversed()) - .map(entry -> new DateGroupedProposeResponse(entry.getKey(), entry.getValue())) - .toList(); - } -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeAttachmentResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeAttachmentResponse.java deleted file mode 100644 index b5bd9d57..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeAttachmentResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.response; - -import com.sponus.coredomain.domain.propose.ProposeAttachment; - -import lombok.Builder; - -@Builder -public record ProposeAttachmentResponse( - Long id, - String name, - String url -) { - public static ProposeAttachmentResponse from(ProposeAttachment attachment) { - return ProposeAttachmentResponse.builder() - .id(attachment.getId()) - .name(attachment.getName()) - .url(attachment.getUrl()) - .build(); - } -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeCreateResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeCreateResponse.java index 88a17c14..e63a1322 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeCreateResponse.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeCreateResponse.java @@ -1,6 +1,21 @@ package com.sponus.sponusbe.domain.propose.dto.response; +import com.sponus.coredomain.domain.propose.Propose; + +import lombok.Builder; + +@Builder public record ProposeCreateResponse( - Long proposeId + Long id, + Long organizationId, + Long target ) { + + public static ProposeCreateResponse from(Propose propose) { + return ProposeCreateResponse.builder() + .id(propose.getId()) + .organizationId(propose.getOrganization().getId()) + .target(propose.getTarget().getId()) + .build(); + } } diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeDetailGetResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeDetailGetResponse.java deleted file mode 100644 index d4bea92b..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeDetailGetResponse.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.response; - -import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.Locale; - -import com.sponus.coredomain.domain.propose.Propose; - -public record ProposeDetailGetResponse( - Long proposeId, - String title, - String content, - String status, - Long proposedOrganizationId, - String proposedOrganizationName, - String proposedOrganizationImage, - Long proposingOrganizationId, - String proposingOrganizationName, - String proposingOrganizationImage, - List proposeAttachmentUrl, - String createdDate, - String createdDay -) { - public static ProposeDetailGetResponse from(Propose propose) { - DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MM.dd"); - DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("EEE", Locale.ENGLISH); - List attachmentUrls = propose.getProposeAttachments() - .stream() - .map(ProposeAttachmentResponse::from) - .toList(); - return new ProposeDetailGetResponse( - propose.getId(), - propose.getTitle(), - propose.getContent(), - propose.getStatus().name(), - propose.getProposedOrganization().getId(), - propose.getProposedOrganization().getName(), - propose.getProposedOrganization().getImageUrl(), - propose.getProposingOrganization().getId(), - propose.getProposingOrganization().getName(), - propose.getProposingOrganization().getImageUrl(), - attachmentUrls, - propose.getCreatedAt().format(dateFormatter), - propose.getUpdatedAt().format(dayFormatter) - ); - } -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeSummaryGetResponse.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeSummaryGetResponse.java deleted file mode 100644 index 65c533bd..00000000 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/dto/response/ProposeSummaryGetResponse.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.sponus.sponusbe.domain.propose.dto.response; - -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -import com.sponus.coredomain.domain.propose.Propose; - -public record ProposeSummaryGetResponse( - Long proposeId, - String title, - String status, - Long proposedOrganizationId, - String proposedOrganizationName, - Long proposingOrganizationId, - String proposingOrganizationName, - String proposingOrganizationImageUrl, - String createdDate, - String createdDay -) { - public static ProposeSummaryGetResponse from(Propose propose) { - DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MM.dd"); - DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("EEE", Locale.ENGLISH); - return new ProposeSummaryGetResponse( - propose.getId(), - propose.getTitle(), - propose.getStatus().name(), - propose.getProposedOrganization().getId(), - propose.getProposedOrganization().getName(), - propose.getProposingOrganization().getId(), - propose.getProposingOrganization().getName(), - propose.getProposingOrganization().getImageUrl(), - propose.getCreatedAt().format(dateFormatter), - propose.getUpdatedAt().format(dayFormatter) - ); - } -} diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java index 50aa9b25..82bfa209 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java @@ -12,10 +12,6 @@ @AllArgsConstructor public enum ProposeErrorCode implements BaseErrorCode { PROPOSE_ERROR(HttpStatus.BAD_REQUEST, "PROP4000", "제안 관련 에러"), - ANNOUNCEMENT_ID_IS_REQUIRED(HttpStatus.BAD_REQUEST, "PROP4001", "공고 ID가 필요합니다."), - INVALID_PROPOSING_ORGANIZATION(HttpStatus.BAD_REQUEST, "PROP4002", "해당 단체가 작성한 제안이 아닙니다."), - INVALID_PROPOSED_ORGANIZATION(HttpStatus.BAD_REQUEST, "PROP4003", "제안을 받은 단체만 접근이 가능합니다."), - PROPOSE_STATUS_NOT_PENDING(HttpStatus.BAD_REQUEST, "PROP4004", "수락 대기 중인 제안만 수정이 가능합니다."), INVALID_PROPOSE_STATUS(HttpStatus.BAD_REQUEST, "PROP4005", "유효하지 않은 제안 상태입니다."), PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다."); 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 fc7086c6..b2c378f4 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,35 +1,12 @@ 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.coreinfradb.propose.ProposeCustomRepository; -import com.sponus.sponusbe.domain.propose.dto.response.DateGroupedProposeResponse; -import com.sponus.sponusbe.domain.propose.dto.response.ProposeSummaryGetResponse; - import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class ProposeQueryService { - - private final ProposeCustomRepository proposeCustomRepository; - - public List getSentProposes(Organization organization) { - return DateGroupedProposeResponse.from( - proposeCustomRepository.findSentPropose(organization.getId()).stream() - .map(ProposeSummaryGetResponse::from) - .toList()); - } - - public List getReceivedProposes(Organization organization, Long announcementId) { - return DateGroupedProposeResponse.from( - proposeCustomRepository.findReceivedProposeWithAnnouncementId(organization.getId(), announcementId).stream() - .map(ProposeSummaryGetResponse::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 165edc0d..b8285387 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,23 +1,25 @@ package com.sponus.sponusbe.domain.propose.service; -import java.util.List; +import java.lang.annotation.Target; +import java.time.LocalDateTime; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; +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.ProposeAttachment; -import com.sponus.coredomain.domain.propose.ProposeStatus; 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; -import com.sponus.sponusbe.domain.propose.dto.request.ProposeStatusUpdateRequest; -import com.sponus.sponusbe.domain.propose.dto.request.ProposeUpdateRequest; import com.sponus.sponusbe.domain.propose.dto.response.ProposeCreateResponse; -import com.sponus.sponusbe.domain.propose.dto.response.ProposeDetailGetResponse; import com.sponus.sponusbe.domain.propose.exception.ProposeErrorCode; import com.sponus.sponusbe.domain.propose.exception.ProposeException; @@ -31,90 +33,29 @@ public class ProposeService { private final ProposeRepository proposeRepository; - private final S3Service s3Service; - private final FirebaseService firebaseService; + private final OrganizationRepository organizationRepository; - public ProposeCreateResponse createPropose( - Organization authOrganization, - ProposeCreateRequest request, - List attachments) { - return null; - } - - public ProposeDetailGetResponse getProposeDetail( - Organization authOrganization, - Long proposeId) { - final Propose propose = proposeRepository.findById(proposeId) - .orElseThrow(() -> new ProposeException(ProposeErrorCode.PROPOSE_NOT_FOUND)); - // 제안을 받은 단체가 조회할 경우 상태를 "VIEWED"으로 변경 - if (isProposedOrganization(authOrganization.getId(), propose)) - propose.updateToViewed(); - else if (!isProposingOrganization(authOrganization.getId(), propose)) - // 제안한 단체도 아닐 경우 조회 불가 - throw new ProposeException(ProposeErrorCode.INVALID_PROPOSING_ORGANIZATION); - - return ProposeDetailGetResponse.from(propose); - } + // TODO 예외처리 수정 + public ProposeCreateResponse createPropose(Organization organization, ProposeCreateRequest request) { - public void updatePropose( - Organization authOrganization, - Long proposeId, - ProposeUpdateRequest request, - List attachments) { - final Propose propose = getUpdatablePropose(authOrganization, proposeId); - propose.updateInfo(request.title(), request.content()); - updateProposeAttachments(propose, attachments); - } - - public void deletePropose(Organization authOrganization, Long proposeId) { - final Propose propose = getUpdatablePropose(authOrganization, proposeId); - proposeRepository.delete(propose); - } + if (organization.getId().equals(request.target())) + throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - public void updateProposeStatus(Organization authOrganization, Long proposeId, ProposeStatusUpdateRequest status) { - final Propose propose = proposeRepository.findById(proposeId) - .orElseThrow(() -> new ProposeException(ProposeErrorCode.PROPOSE_NOT_FOUND)); - // 제안을 "받은" 단체만 가능 - if (!isProposedOrganization(authOrganization.getId(), propose)) - throw new ProposeException(ProposeErrorCode.INVALID_PROPOSED_ORGANIZATION); + final Organization target = organizationRepository.findById(request.target()) + .orElseThrow(() -> new OrganizationException(OrganizationErrorCode.ORGANIZATION_NOT_FOUND)); - try { - propose.updateStatus(ProposeStatus.of(status.status())); - } catch (Exception e) { - throw new ProposeException(ProposeErrorCode.INVALID_PROPOSE_STATUS); - } - } + if (proposeRepository.existsByOrganization(target)) + throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - private Propose getUpdatablePropose(Organization organization, Long proposeId) { - final Propose propose = proposeRepository.findById(proposeId) - .orElseThrow(() -> new ProposeException(ProposeErrorCode.PROPOSE_NOT_FOUND)); + long count = proposeRepository.findByOrganization(organization) + .stream() + .filter(propose -> propose.getCreatedAt().isAfter(LocalDateTime.now().toLocalDate().atStartOfDay())) + .count(); - if (!isProposingOrganization(organization.getId(), propose)) - throw new ProposeException(ProposeErrorCode.INVALID_PROPOSING_ORGANIZATION); - - if (propose.getStatus() != ProposeStatus.PENDING) - throw new ProposeException(ProposeErrorCode.PROPOSE_STATUS_NOT_PENDING); - - return propose; - } - - private boolean isProposingOrganization(Long organizationId, Propose propose) { - return propose.getProposingOrganization().getId().equals(organizationId); - } - - private boolean isProposedOrganization(Long organizationId, Propose propose) { - return propose.getProposedOrganization().getId().equals(organizationId); - } + if (count > 5) + throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - private void updateProposeAttachments(Propose propose, List attachments) { - propose.getProposeAttachments().clear(); - attachments.forEach(attachment -> { - final String url = s3Service.uploadFile(attachment); - ProposeAttachment proposeAttachment = ProposeAttachment.builder() - .name(attachment.getOriginalFilename()) - .url(url) - .build(); - proposeAttachment.setPropose(propose); - }); + final Propose propose = proposeRepository.save(request.toEntity(organization, target)); + return ProposeCreateResponse.from(propose); } } 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 3ca5b282..2bb4a25d 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 @@ -40,51 +40,11 @@ public class Propose extends BaseEntity { @Column(name = "propose_id") private Long id; - @Column(name = "propose_title", nullable = false) - private String title; + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + @JoinColumn(name = "organization_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Organization organization; - @Column(name = "propose_content", nullable = false) - private String content; - - @Enumerated(EnumType.STRING) - @Column(name = "propose_status", nullable = false) - private ProposeStatus status; - - @Column(name = "imp_uid") - private String impUid; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "proposed_organization_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Organization proposedOrganization; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "proposing_organization_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Organization proposingOrganization; - - @Builder.Default - @OneToMany(mappedBy = "propose", cascade = CascadeType.ALL, orphanRemoval = true) - private List proposeAttachments = new ArrayList<>(); - - public void updateToViewed() { - if (this.status == ProposeStatus.PENDING) - this.status = ProposeStatus.VIEWED; - } - - public void updateInfo(String title, String content) { - this.title = title == null ? this.title : title; - this.content = content == null ? this.content : content; - } - - public void updateStatus(ProposeStatus status) { - this.status = status == null ? this.status : status; - } - - public void updateToPaid(String impUid) { - this.status = ProposeStatus.PAID; - this.impUid = impUid; - } - - public boolean isPaid() { - return this.status == ProposeStatus.PAID; - } + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + @JoinColumn(name = "target_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Organization target; } diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeAttachment.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeAttachment.java deleted file mode 100644 index db8216a2..00000000 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeAttachment.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.sponus.coredomain.domain.propose; - -import jakarta.persistence.Column; -import jakarta.persistence.ConstraintMode; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Getter -@Entity -@Table(name = "propose_attachment") -public class ProposeAttachment { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "attachment_id") - private Long id; - - @Column(name = "file_name", nullable = false) - private String name; - - @Column(name = "file_url", nullable = false) - private String url; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "propose_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Propose propose; - - public void setPropose(Propose propose) { - if (this.propose != null) { - this.propose.getProposeAttachments().remove(this); - } - this.propose = propose; - propose.getProposeAttachments().add(this); - } -} diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeImage.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeImage.java deleted file mode 100644 index e14f1902..00000000 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/ProposeImage.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.sponus.coredomain.domain.propose; - -import jakarta.persistence.Column; -import jakarta.persistence.ConstraintMode; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Getter -@Entity -@Table(name = "propose_image") -public class ProposeImage { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "image_id") - private Long id; - - @Column(name = "image_name", nullable = false) - private String name; - - @Column(name = "image_url", nullable = false) - private String url; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "propose_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Propose propose; - - // public void setPropose(Propose propose) { - // if (this.propose != null) { - // this.propose.getProposeImages().remove(this); - // } - // this.propose = propose; - // propose.getProposeImages().add(this); - // } -} diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeAttachmentRepository.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeAttachmentRepository.java deleted file mode 100644 index 3b4c65ff..00000000 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeAttachmentRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sponus.coredomain.domain.propose.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.sponus.coredomain.domain.propose.ProposeAttachment; - -public interface ProposeAttachmentRepository extends JpaRepository { - -} diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeImageRepository.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeImageRepository.java deleted file mode 100644 index 81e09a64..00000000 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/propose/repository/ProposeImageRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sponus.coredomain.domain.propose.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.sponus.coredomain.domain.propose.ProposeImage; - -public interface ProposeImageRepository extends JpaRepository { - -} 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 1add350a..d20abaeb 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 @@ -4,8 +4,11 @@ import org.springframework.data.jpa.repository.JpaRepository; +import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coredomain.domain.propose.Propose; public interface ProposeRepository extends JpaRepository { - Optional findByImpUid(String impUid); + + Boolean existsByOrganization(Organization organization); + Optional findByOrganization(Organization organization); } diff --git a/core/core-infra-db/src/main/java/com/sponus/coreinfradb/propose/ProposeCustomRepositoryImpl.java b/core/core-infra-db/src/main/java/com/sponus/coreinfradb/propose/ProposeCustomRepositoryImpl.java index 656de0aa..30510511 100644 --- a/core/core-infra-db/src/main/java/com/sponus/coreinfradb/propose/ProposeCustomRepositoryImpl.java +++ b/core/core-infra-db/src/main/java/com/sponus/coreinfradb/propose/ProposeCustomRepositoryImpl.java @@ -1,49 +1,49 @@ -package com.sponus.coreinfradb.propose; - -import java.util.List; - -import org.springframework.stereotype.Repository; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.sponus.coredomain.domain.propose.Propose; -import com.sponus.coredomain.domain.propose.QPropose; - -import jakarta.persistence.EntityManager; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Repository -public class ProposeCustomRepositoryImpl implements ProposeCustomRepository { - - private final EntityManager entityManager; - - @Override - - public List findSentPropose(Long id) { - QPropose p = QPropose.propose; - - JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager); - - return queryFactory.selectFrom(p) - .where(p.proposingOrganization.id.eq(id)) - .leftJoin(p.proposingOrganization).fetchJoin() - .fetch(); - } - - @Override - public List findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId) { - QPropose p = QPropose.propose; - - JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager); - - BooleanBuilder whereClause = new BooleanBuilder(); - whereClause.and(p.proposedOrganization.id.eq(organizationId)); - - return queryFactory.selectFrom(p) - .where(whereClause) - .orderBy(p.createdAt.desc()) - .leftJoin(p.proposedOrganization).fetchJoin() - .fetch(); - } -} +// package com.sponus.coreinfradb.propose; +// +// import java.util.List; +// +// import org.springframework.stereotype.Repository; +// +// import com.querydsl.core.BooleanBuilder; +// import com.querydsl.jpa.impl.JPAQueryFactory; +// import com.sponus.coredomain.domain.propose.Propose; +// import com.sponus.coredomain.domain.propose.QPropose; +// +// import jakarta.persistence.EntityManager; +// import lombok.RequiredArgsConstructor; +// +// @RequiredArgsConstructor +// @Repository +// public class ProposeCustomRepositoryImpl implements ProposeCustomRepository { +// +// private final EntityManager entityManager; +// +// @Override +// +// public List findSentPropose(Long id) { +// QPropose p = QPropose.propose; +// +// JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager); +// +// return queryFactory.selectFrom(p) +// .where(p.proposingOrganization.id.eq(id)) +// .leftJoin(p.proposingOrganization).fetchJoin() +// .fetch(); +// } +// +// @Override +// public List findReceivedProposeWithAnnouncementId(Long organizationId, Long announcementId) { +// QPropose p = QPropose.propose; +// +// JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager); +// +// BooleanBuilder whereClause = new BooleanBuilder(); +// whereClause.and(p.proposedOrganization.id.eq(organizationId)); +// +// return queryFactory.selectFrom(p) +// .where(whereClause) +// .orderBy(p.createdAt.desc()) +// .leftJoin(p.proposedOrganization).fetchJoin() +// .fetch(); +// } +// } From 4d30ee49b91b58f2e2e7a06cd14b580f69855626 Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Tue, 25 Jun 2024 18:26:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EC=A0=9C=EC=95=88=20=ED=95=98?= =?UTF-8?q?=EB=A3=A8=205=ED=9A=8C=20=EC=A0=9C=ED=95=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/propose/service/ProposeService.java | 13 ++++++++----- .../propose/repository/ProposeRepository.java | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) 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 b8285387..a43a4216 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 @@ -47,12 +47,15 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre if (proposeRepository.existsByOrganization(target)) throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - long count = proposeRepository.findByOrganization(organization) - .stream() - .filter(propose -> propose.getCreatedAt().isAfter(LocalDateTime.now().toLocalDate().atStartOfDay())) - .count(); + // long count = proposeRepository.findByOrganization(organization) + // .stream() + // .filter(propose -> propose.getCreatedAt().isAfter(LocalDateTime.now().toLocalDate().atStartOfDay())) + // .count(); - if (count > 5) + Long count = proposeRepository.countProposesByOrganizationToday(organization, + LocalDateTime.now().toLocalDate().atStartOfDay()); + + if (count >= 5) throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); final Propose propose = proposeRepository.save(request.toEntity(organization, target)); 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 d20abaeb..5ea80827 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,11 @@ package com.sponus.coredomain.domain.propose.repository; +import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.sponus.coredomain.domain.organization.Organization; import com.sponus.coredomain.domain.propose.Propose; @@ -10,5 +13,9 @@ public interface ProposeRepository extends JpaRepository { Boolean existsByOrganization(Organization organization); - Optional findByOrganization(Organization organization); + + // 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); } From 33c10935e48499b22415a108f0546e0fe644cddb Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Tue, 25 Jun 2024 18:51:51 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sponusbe/domain/propose/exception/ProposeErrorCode.java | 1 + .../sponus/sponusbe/domain/propose/service/ProposeService.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java index 82bfa209..62c0982b 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java @@ -13,6 +13,7 @@ public enum ProposeErrorCode implements BaseErrorCode { PROPOSE_ERROR(HttpStatus.BAD_REQUEST, "PROP4000", "제안 관련 에러"), INVALID_PROPOSE_STATUS(HttpStatus.BAD_REQUEST, "PROP4005", "유효하지 않은 제안 상태입니다."), + PROPOSE_LIMIT_ERROR(HttpStatus.CONFLICT, "PROP4009", "하루 제안 5회 초과하였습니다."), PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다."); private final HttpStatus httpStatus; 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 a43a4216..d8e09369 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 @@ -56,7 +56,7 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre LocalDateTime.now().toLocalDate().atStartOfDay()); if (count >= 5) - throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); + throw new ProposeException(ProposeErrorCode.PROPOSE_LIMIT_ERROR); final Propose propose = proposeRepository.save(request.toEntity(organization, target)); return ProposeCreateResponse.from(propose); From ee3f77fd40a40eeae8bad85980cc3f83fb8d6821 Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Sun, 30 Jun 2024 17:29:04 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EC=8B=9C=20=EC=A0=9C=EC=95=88=20=EB=B6=88?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../propose/exception/ProposeErrorCode.java | 1 + .../domain/propose/service/ProposeService.java | 17 ++++++++++------- .../domain/organization/Organization.java | 1 - .../coredomain/domain/propose/Propose.java | 6 ------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java index 62c0982b..46f38ab0 100644 --- a/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java +++ b/api/src/main/java/com/sponus/sponusbe/domain/propose/exception/ProposeErrorCode.java @@ -14,6 +14,7 @@ public enum ProposeErrorCode implements BaseErrorCode { PROPOSE_ERROR(HttpStatus.BAD_REQUEST, "PROP4000", "제안 관련 에러"), INVALID_PROPOSE_STATUS(HttpStatus.BAD_REQUEST, "PROP4005", "유효하지 않은 제안 상태입니다."), PROPOSE_LIMIT_ERROR(HttpStatus.CONFLICT, "PROP4009", "하루 제안 5회 초과하였습니다."), + PROFILE_NOT_COMPLETED(HttpStatus.BAD_REQUEST, "PROP4010", "프로필이 작성되지 않았습니다."), PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다."); private final HttpStatus httpStatus; 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 d8e09369..ede2952a 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 @@ -35,7 +35,6 @@ public class ProposeService { private final ProposeRepository proposeRepository; private final OrganizationRepository organizationRepository; - // TODO 예외처리 수정 public ProposeCreateResponse createPropose(Organization organization, ProposeCreateRequest request) { if (organization.getId().equals(request.target())) @@ -44,20 +43,24 @@ public ProposeCreateResponse createPropose(Organization organization, ProposeCre final Organization target = organizationRepository.findById(request.target()) .orElseThrow(() -> new OrganizationException(OrganizationErrorCode.ORGANIZATION_NOT_FOUND)); + if (organization.getImageUrl() == null || organization.getImageUrl().isEmpty()) + throw new ProposeException(ProposeErrorCode.PROFILE_NOT_COMPLETED); + if (proposeRepository.existsByOrganization(target)) throw new ProposeException(ProposeErrorCode.PROPOSE_ERROR); - // long count = proposeRepository.findByOrganization(organization) - // .stream() - // .filter(propose -> propose.getCreatedAt().isAfter(LocalDateTime.now().toLocalDate().atStartOfDay())) - // .count(); - - Long count = proposeRepository.countProposesByOrganizationToday(organization, + final Long count = proposeRepository.countProposesByOrganizationToday(organization, LocalDateTime.now().toLocalDate().atStartOfDay()); if (count >= 5) throw new ProposeException(ProposeErrorCode.PROPOSE_LIMIT_ERROR); + // TODO 쿼리와 비교 + // long count = proposeRepository.findByOrganization(organization) + // .stream() + // .filter(propose -> propose.getCreatedAt().isAfter(LocalDateTime.now().toLocalDate().atStartOfDay())) + // .count(); + final Propose propose = proposeRepository.save(request.toEntity(organization, target)); return ProposeCreateResponse.from(propose); } diff --git a/core/core-domain/src/main/java/com/sponus/coredomain/domain/organization/Organization.java b/core/core-domain/src/main/java/com/sponus/coredomain/domain/organization/Organization.java index 1de6284d..a79e6585 100644 --- a/core/core-domain/src/main/java/com/sponus/coredomain/domain/organization/Organization.java +++ b/core/core-domain/src/main/java/com/sponus/coredomain/domain/organization/Organization.java @@ -8,7 +8,6 @@ import com.sponus.coredomain.domain.organization.enums.OrganizationType; import com.sponus.coredomain.domain.organization.enums.ProfileStatus; import com.sponus.coredomain.domain.organization.enums.Role; -import com.sponus.coredomain.domain.portfolio.PortfolioImage; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; 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 2bb4a25d..e35f0abf 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,8 +1,5 @@ package com.sponus.coredomain.domain.propose; -import java.util.ArrayList; -import java.util.List; - import com.sponus.coredomain.domain.common.BaseEntity; import com.sponus.coredomain.domain.organization.Organization; @@ -10,8 +7,6 @@ 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; @@ -19,7 +14,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor;