-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-46] 공지사항 전체 조회 API offset 기반 페이지네이션 적용 (#89)
- Loading branch information
Showing
8 changed files
with
145 additions
and
70 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/ddingdong/ddingdongBE/domain/notice/api/NoticeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ddingdong.ddingdongBE.domain.notice.api; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
import ddingdong.ddingdongBE.domain.notice.controller.dto.request.GetAllNoticeByPageRequest; | ||
import ddingdong.ddingdongBE.domain.notice.controller.dto.response.GetAllNoticeByPageResponse; | ||
import ddingdong.ddingdongBE.domain.notice.controller.dto.response.NoticeResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Tag(name = "Notice", description = "Notice API") | ||
@RequestMapping(value = "/server/notices", produces = APPLICATION_JSON_VALUE) | ||
public interface NoticeApi { | ||
|
||
@Operation(summary = "공지사항 전체 조회 API") | ||
@GetMapping | ||
GetAllNoticeByPageResponse getAllNotices( | ||
GetAllNoticeByPageRequest request | ||
); | ||
|
||
@Operation(summary = "공지사항 상세 조회 API") | ||
@GetMapping("/{noticeId}") | ||
NoticeResponse getNoticeDetail(@PathVariable Long noticeId); | ||
} |
26 changes: 13 additions & 13 deletions
26
src/main/java/ddingdong/ddingdongBE/domain/notice/controller/NoticeApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ddingdong/ddingdongBE/domain/notice/controller/dto/request/GetAllNoticeByPageRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ddingdong.ddingdongBE.domain.notice.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
import lombok.Getter; | ||
import org.springdoc.api.annotations.ParameterObject; | ||
|
||
@Getter | ||
@ParameterObject | ||
public class GetAllNoticeByPageRequest { | ||
|
||
@Parameter(description = "현재 페이지 수") | ||
private int page; | ||
|
||
@Parameter(description = "조회할 페이지 크기", example = "10") | ||
private Integer limit; | ||
|
||
public GetAllNoticeByPageRequest(int page, Integer limit) { | ||
this.page = page; | ||
this.limit = (limit == null) ? 10 : limit; | ||
} | ||
} | ||
|
38 changes: 0 additions & 38 deletions
38
...ava/ddingdong/ddingdongBE/domain/notice/controller/dto/response/DetailNoticeResponse.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...ingdong/ddingdongBE/domain/notice/controller/dto/response/GetAllNoticeByPageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ddingdong.ddingdongBE.domain.notice.controller.dto.response; | ||
|
||
import ddingdong.ddingdongBE.domain.notice.entity.Notice; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record GetAllNoticeByPageResponse( | ||
List<NoticeResponseDto> notices | ||
) { | ||
|
||
public static GetAllNoticeByPageResponse from(List<Notice> notices) { | ||
List<NoticeResponseDto> noticeResponses = notices.stream() | ||
.map(NoticeResponseDto::from) | ||
.toList(); | ||
|
||
return GetAllNoticeByPageResponse | ||
.builder() | ||
.notices(noticeResponses) | ||
.build(); | ||
} | ||
|
||
@Builder | ||
public record NoticeResponseDto( | ||
Long id, | ||
String title, | ||
LocalDateTime createdAt | ||
) { | ||
|
||
public static NoticeResponseDto from(Notice notice) { | ||
return NoticeResponseDto | ||
.builder() | ||
.id(notice.getId()) | ||
.title(notice.getTitle()) | ||
.createdAt(notice.getCreatedAt()) | ||
.build(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/ddingdong/ddingdongBE/domain/notice/repository/NoticeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
package ddingdong.ddingdongBE.domain.notice.repository; | ||
|
||
import ddingdong.ddingdongBE.domain.notice.entity.Notice; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface NoticeRepository extends JpaRepository<Notice, Long> { | ||
|
||
@Query( | ||
value = """ | ||
SELECT * | ||
FROM notice AS n | ||
ORDER BY n.id DESC | ||
LIMIT :limit | ||
OFFSET :offsetValue | ||
""", | ||
nativeQuery = true | ||
) | ||
List<Notice> findAllByPage(int limit, int offsetValue); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters