From 14e32a3ec4ee14999d886f281f85e044a6356f76 Mon Sep 17 00:00:00 2001 From: Sojung Lee <90453158+xxoznge@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:55:15 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[FEATURE]=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EB=B3=84=20=EA=B3=B5=EA=B3=A0=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🙈chore: dto 폴더 정리 * ✨ feat: 상태별 공고 목록 조회 기능 개발 --- http/test.http | 7 +++++-- .../controller/AnnouncementController.java | 17 ++++++++++----- .../dto/AnnouncementBriefResponse.java | 4 ---- .../AnnouncementCreateRequest.java | 2 +- .../AnnouncementUpdateRequest.java | 2 +- .../response/AnnouncementBriefResponse.java | 4 ++++ .../AnnouncementCreateResponse.java | 2 +- .../{ => response}/AnnouncementResponse.java | 2 +- .../AnnouncementUpdateResponse.java | 2 +- .../repository/AnnouncementRepository.java | 4 ++++ .../service/AnnouncementQueryService.java | 6 +++--- .../service/AnnouncementService.java | 21 ++++++++++++++----- 12 files changed, 49 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementBriefResponse.java rename src/main/java/com/sponus/sponusbe/domain/announcement/dto/{ => request}/AnnouncementCreateRequest.java (94%) rename src/main/java/com/sponus/sponusbe/domain/announcement/dto/{ => request}/AnnouncementUpdateRequest.java (95%) create mode 100644 src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementBriefResponse.java rename src/main/java/com/sponus/sponusbe/domain/announcement/dto/{ => response}/AnnouncementCreateResponse.java (94%) rename src/main/java/com/sponus/sponusbe/domain/announcement/dto/{ => response}/AnnouncementResponse.java (94%) rename src/main/java/com/sponus/sponusbe/domain/announcement/dto/{ => response}/AnnouncementUpdateResponse.java (94%) diff --git a/http/test.http b/http/test.http index aec25ee7..218bb7dd 100644 --- a/http/test.http +++ b/http/test.http @@ -43,14 +43,17 @@ Content-Type: application/json } ### 상세 조회 -GET http://localhost:8080/api/v1/announcements/2 +GET http://localhost:8080/api/v1/announcements/1 + +### 공고 상태별 목록 조회 +GET http://localhost:8080/api/v1/announcements/status?status=POSTED ### 삭제 (생성한 단체만 삭제 가능) DELETE http://localhost:8080/api/v1/announcements/1 Authorization: Bearer {{matsterToken}} ### 공고 수정 -PATCH http://localhost:8080/api/v1/announcements/1 +PATCH http://localhost:8080/api/v1/announcements/2 Authorization: Bearer {{matsterToken}} Content-Type: application/json diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/controller/AnnouncementController.java b/src/main/java/com/sponus/sponusbe/domain/announcement/controller/AnnouncementController.java index 2d0ba502..53825bcc 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/controller/AnnouncementController.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/controller/AnnouncementController.java @@ -13,11 +13,12 @@ import org.springframework.web.bind.annotation.RestController; import com.sponus.sponusbe.auth.annotation.AuthOrganization; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateRequest; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateResponse; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementResponse; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementUpdateRequest; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementUpdateResponse; +import com.sponus.sponusbe.domain.announcement.dto.request.AnnouncementCreateRequest; +import com.sponus.sponusbe.domain.announcement.dto.request.AnnouncementUpdateRequest; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementCreateResponse; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementResponse; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementUpdateResponse; +import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus; import com.sponus.sponusbe.domain.announcement.service.AnnouncementQueryService; import com.sponus.sponusbe.domain.announcement.service.AnnouncementService; import com.sponus.sponusbe.domain.organization.entity.Organization; @@ -51,6 +52,12 @@ public ApiResponse getAnnouncement(@PathVariable Long anno return ApiResponse.onSuccess(announcementService.getAnnouncement(announcementId)); } + @GetMapping("/status") + public ApiResponse> getListAnnouncement( + @RequestParam("status") AnnouncementStatus status) { + return ApiResponse.onSuccess(announcementService.getListAnnouncement(status)); + } + @GetMapping public ApiResponse> searchAnnouncement(@RequestParam("search") String keyword) { return ApiResponse.onSuccess(announcementQueryService.searchAnnouncement(keyword)); diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementBriefResponse.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementBriefResponse.java deleted file mode 100644 index ef88b96a..00000000 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementBriefResponse.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.sponus.sponusbe.domain.announcement.dto; - -public record AnnouncementBriefResponse() { -} diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateRequest.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementCreateRequest.java similarity index 94% rename from src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateRequest.java rename to src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementCreateRequest.java index 53d8168c..a0455fc5 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateRequest.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementCreateRequest.java @@ -1,4 +1,4 @@ -package com.sponus.sponusbe.domain.announcement.dto; +package com.sponus.sponusbe.domain.announcement.dto.request; import com.sponus.sponusbe.domain.announcement.entity.Announcement; import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateRequest.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementUpdateRequest.java similarity index 95% rename from src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateRequest.java rename to src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementUpdateRequest.java index d2ee5f08..8a66656c 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateRequest.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/request/AnnouncementUpdateRequest.java @@ -1,4 +1,4 @@ -package com.sponus.sponusbe.domain.announcement.dto; +package com.sponus.sponusbe.domain.announcement.dto.request; import com.sponus.sponusbe.domain.announcement.entity.Announcement; import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementBriefResponse.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementBriefResponse.java new file mode 100644 index 00000000..11c10770 --- /dev/null +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementBriefResponse.java @@ -0,0 +1,4 @@ +package com.sponus.sponusbe.domain.announcement.dto.response; + +public record AnnouncementBriefResponse() { +} diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateResponse.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementCreateResponse.java similarity index 94% rename from src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateResponse.java rename to src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementCreateResponse.java index 469fc6c7..563dc658 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementCreateResponse.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementCreateResponse.java @@ -1,4 +1,4 @@ -package com.sponus.sponusbe.domain.announcement.dto; +package com.sponus.sponusbe.domain.announcement.dto.response; import com.sponus.sponusbe.domain.announcement.entity.Announcement; import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementResponse.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementResponse.java similarity index 94% rename from src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementResponse.java rename to src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementResponse.java index 748e9862..abe7f38e 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementResponse.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementResponse.java @@ -1,4 +1,4 @@ -package com.sponus.sponusbe.domain.announcement.dto; +package com.sponus.sponusbe.domain.announcement.dto.response; import com.sponus.sponusbe.domain.announcement.entity.Announcement; import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateResponse.java b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementUpdateResponse.java similarity index 94% rename from src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateResponse.java rename to src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementUpdateResponse.java index f1877a56..16b3a96a 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/dto/AnnouncementUpdateResponse.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/dto/response/AnnouncementUpdateResponse.java @@ -1,4 +1,4 @@ -package com.sponus.sponusbe.domain.announcement.dto; +package com.sponus.sponusbe.domain.announcement.dto.response; import com.sponus.sponusbe.domain.announcement.entity.Announcement; import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/repository/AnnouncementRepository.java b/src/main/java/com/sponus/sponusbe/domain/announcement/repository/AnnouncementRepository.java index 52c9674b..2f09c001 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/repository/AnnouncementRepository.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/repository/AnnouncementRepository.java @@ -5,8 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import com.sponus.sponusbe.domain.announcement.entity.Announcement; +import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus; public interface AnnouncementRepository extends JpaRepository { List findByTitleContains(String title); + + List findByStatus(AnnouncementStatus status); + } diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementQueryService.java b/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementQueryService.java index d69864db..a6502437 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementQueryService.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementQueryService.java @@ -5,9 +5,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementBriefResponse; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateRequest; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementResponse; +import com.sponus.sponusbe.domain.announcement.dto.request.AnnouncementCreateRequest; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementBriefResponse; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementResponse; import com.sponus.sponusbe.domain.announcement.repository.AnnouncementRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementService.java b/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementService.java index d7fa4e9b..3d06c167 100644 --- a/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementService.java +++ b/src/main/java/com/sponus/sponusbe/domain/announcement/service/AnnouncementService.java @@ -1,14 +1,18 @@ package com.sponus.sponusbe.domain.announcement.service; +import java.util.List; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateRequest; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementCreateResponse; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementResponse; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementUpdateRequest; -import com.sponus.sponusbe.domain.announcement.dto.AnnouncementUpdateResponse; +import com.sponus.sponusbe.domain.announcement.dto.request.AnnouncementCreateRequest; +import com.sponus.sponusbe.domain.announcement.dto.request.AnnouncementUpdateRequest; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementCreateResponse; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementResponse; +import com.sponus.sponusbe.domain.announcement.dto.response.AnnouncementUpdateResponse; import com.sponus.sponusbe.domain.announcement.entity.Announcement; +import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus; import com.sponus.sponusbe.domain.announcement.exception.AnnouncementErrorCode; import com.sponus.sponusbe.domain.announcement.exception.AnnouncementException; import com.sponus.sponusbe.domain.announcement.repository.AnnouncementRepository; @@ -39,6 +43,13 @@ public AnnouncementResponse getAnnouncement(Long announcementId) { return AnnouncementResponse.from(announcement); } + public List getListAnnouncement(AnnouncementStatus status) { + List announcements = announcementRepository.findByStatus(status); + return announcements.stream() + .map(AnnouncementResponse::from) + .collect(Collectors.toList()); + } + public void deleteAnnouncement(Organization organization, Long announcementId) { final Announcement announcement = announcementRepository.findById(announcementId) .orElseThrow(() -> new AnnouncementException(AnnouncementErrorCode.ANNOUNCEMENT_NOT_FOUND));