Skip to content

Commit

Permalink
✨ [FEATURE] 상태별 공고 조회 기능 개발 (#51)
Browse files Browse the repository at this point in the history
* 🙈chore: dto 폴더 정리

* ✨ feat: 상태별 공고 목록 조회 기능 개발
  • Loading branch information
xxoznge authored Jan 28, 2024
1 parent 9319a60 commit 14e32a3
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 24 deletions.
7 changes: 5 additions & 2 deletions http/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +52,12 @@ public ApiResponse<AnnouncementResponse> getAnnouncement(@PathVariable Long anno
return ApiResponse.onSuccess(announcementService.getAnnouncement(announcementId));
}

@GetMapping("/status")
public ApiResponse<List<AnnouncementResponse>> getListAnnouncement(
@RequestParam("status") AnnouncementStatus status) {
return ApiResponse.onSuccess(announcementService.getListAnnouncement(status));
}

@GetMapping
public ApiResponse<List<AnnouncementResponse>> searchAnnouncement(@RequestParam("search") String keyword) {
return ApiResponse.onSuccess(announcementQueryService.searchAnnouncement(keyword));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.sponus.sponusbe.domain.announcement.dto.response;

public record AnnouncementBriefResponse() {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Announcement, Long> {

List<Announcement> findByTitleContains(String title);

List<Announcement> findByStatus(AnnouncementStatus status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,6 +43,13 @@ public AnnouncementResponse getAnnouncement(Long announcementId) {
return AnnouncementResponse.from(announcement);
}

public List<AnnouncementResponse> getListAnnouncement(AnnouncementStatus status) {
List<Announcement> 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));
Expand Down

0 comments on commit 14e32a3

Please sign in to comment.