Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [FEATURE] 상태별 공고 조회 기능 개발 #56

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading