Skip to content

Commit 3f63313

Browse files
committed
feat: PagedResponse 구현 및 레슨 수강 도메인에 적용
1 parent 58517e3 commit 3f63313

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/main/java/com/threestar/trainus/domain/lesson/student/controller/StudentLessonController.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.threestar.trainus.domain.lesson.student.controller;
22

3+
import java.util.List;
4+
35
import org.springframework.http.HttpStatus;
46
import org.springframework.http.ResponseEntity;
57
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -13,12 +15,15 @@
1315
import com.threestar.trainus.domain.lesson.student.dto.LessonApplicationResponseDto;
1416
import com.threestar.trainus.domain.lesson.student.dto.LessonDetailResponseDto;
1517
import com.threestar.trainus.domain.lesson.student.dto.LessonSearchListResponseDto;
18+
import com.threestar.trainus.domain.lesson.student.dto.LessonSearchResponseDto;
1619
import com.threestar.trainus.domain.lesson.student.dto.LessonSimpleResponseDto;
1720
import com.threestar.trainus.domain.lesson.student.dto.MyLessonApplicationListResponseDto;
21+
import com.threestar.trainus.domain.lesson.student.dto.MyLessonApplicationResponseDto;
1822
import com.threestar.trainus.domain.lesson.student.service.StudentLessonService;
1923
import com.threestar.trainus.global.exception.domain.ErrorCode;
2024
import com.threestar.trainus.global.exception.handler.BusinessException;
2125
import com.threestar.trainus.global.unit.BaseResponse;
26+
import com.threestar.trainus.global.unit.PagedResponse;
2227

2328
import io.swagger.v3.oas.annotations.Operation;
2429
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -36,7 +41,7 @@ public class StudentLessonController {
3641

3742
@GetMapping
3843
@Operation(summary = "레슨 검색 api", description = "category(필수, Default: \"ALL\") / search(선택) / 그외 법정동 선택 필수")
39-
public ResponseEntity<BaseResponse<LessonSearchListResponseDto>> searchLessons(
44+
public ResponseEntity<PagedResponse<List<LessonSearchResponseDto>>> searchLessons(
4045
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
4146
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
4247
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@@ -49,7 +54,7 @@ public ResponseEntity<BaseResponse<LessonSearchListResponseDto>> searchLessons(
4954
) {
5055
LessonSearchListResponseDto lessonList = studentLessonService.searchLessons(page, limit, category, search, city,
5156
district, dong);
52-
return BaseResponse.ok("레슨 검색 조회 완료.", lessonList, HttpStatus.OK);
57+
return PagedResponse.ok("레슨 검색 조회 완료.", lessonList.data(), lessonList.count(), HttpStatus.OK);
5358
}
5459

5560
@GetMapping("/{lessonId}")
@@ -91,7 +96,7 @@ public ResponseEntity<BaseResponse<Void>> deleteLessonApplication(
9196

9297
@GetMapping("/my-applications")
9398
@Operation(summary = "나의 레슨 신청 목록 조회", description = "현재 로그인한 사용자의 레슨 신청 목록을 조회합니다.")
94-
public ResponseEntity<BaseResponse<MyLessonApplicationListResponseDto>> getMyLessonApplications(
99+
public ResponseEntity<PagedResponse<List<MyLessonApplicationResponseDto>>> getMyLessonApplications(
95100
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
96101
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
97102
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@@ -104,9 +109,10 @@ public ResponseEntity<BaseResponse<MyLessonApplicationListResponseDto>> getMyLes
104109
throw new BusinessException(ErrorCode.AUTHENTICATION_REQUIRED);
105110
}
106111

107-
MyLessonApplicationListResponseDto response = studentLessonService.getMyLessonApplications(userId, page, limit,
112+
MyLessonApplicationListResponseDto result = studentLessonService.getMyLessonApplications(userId, page, limit,
108113
status);
109-
return BaseResponse.ok("나의 레슨 신청 목록 조회 완료.", response, HttpStatus.OK);
114+
115+
return PagedResponse.ok("나의 레슨 신청 목록 조회 완료.", result.data(), result.count(), HttpStatus.OK);
110116
}
111117

112118
@GetMapping("/summary/{lessonId}")

src/main/java/com/threestar/trainus/domain/lesson/student/dto/LessonSearchListResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.List;
44

55
public record LessonSearchListResponseDto(
6-
List<LessonSearchResponseDto> lessons,
6+
List<LessonSearchResponseDto> data,
77
int count
88
) {
99
}

src/main/java/com/threestar/trainus/domain/lesson/student/dto/MyLessonApplicationListResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@Builder
88
// 내 신청 현황 List 전체 응답
99
public record MyLessonApplicationListResponseDto(
10-
List<MyLessonApplicationResponseDto> lessonApplications,
10+
List<MyLessonApplicationResponseDto> data,
1111
int count
1212
) {
1313
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.threestar.trainus.global.unit;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
6+
import com.fasterxml.jackson.annotation.JsonInclude;
7+
8+
import lombok.AllArgsConstructor;
9+
import lombok.Builder;
10+
import lombok.Getter;
11+
12+
@Getter
13+
@Builder
14+
@AllArgsConstructor
15+
@JsonInclude(JsonInclude.Include.NON_NULL)
16+
public class PagedResponse<T> {
17+
private final int status;
18+
private final String message;
19+
private final T data;
20+
private final int count;
21+
22+
public static <T> ResponseEntity<PagedResponse<T>> ok(String message, T data, int count, HttpStatus status) {
23+
return ResponseEntity.status(status)
24+
.body(PagedResponse.<T>builder()
25+
.status(status.value())
26+
.message(message)
27+
.data(data)
28+
.count(count)
29+
.build());
30+
}
31+
}

0 commit comments

Comments
 (0)