Skip to content

Commit b8b3ef7

Browse files
authored
feat: PagedResponse 구현 및 레슨 수강 도메인에 적용 (#85)
* feat: PagedResponse 구현 및 레슨 수강 도메인에 적용 * feat: PageResponse 응답 Wrapper 적용
1 parent d39376b commit b8b3ef7

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
import com.threestar.trainus.domain.lesson.student.dto.LessonApplicationResponseDto;
1414
import com.threestar.trainus.domain.lesson.student.dto.LessonDetailResponseDto;
1515
import com.threestar.trainus.domain.lesson.student.dto.LessonSearchListResponseDto;
16+
import com.threestar.trainus.domain.lesson.student.dto.LessonSearchListWrapperDto;
1617
import com.threestar.trainus.domain.lesson.student.dto.LessonSimpleResponseDto;
1718
import com.threestar.trainus.domain.lesson.student.dto.MyLessonApplicationListResponseDto;
19+
import com.threestar.trainus.domain.lesson.student.dto.MyLessonApplicationListWrapperDto;
1820
import com.threestar.trainus.domain.lesson.student.service.StudentLessonService;
1921
import com.threestar.trainus.global.exception.domain.ErrorCode;
2022
import com.threestar.trainus.global.exception.handler.BusinessException;
2123
import com.threestar.trainus.global.unit.BaseResponse;
24+
import com.threestar.trainus.global.unit.PagedResponse;
2225

2326
import io.swagger.v3.oas.annotations.Operation;
2427
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -36,7 +39,7 @@ public class StudentLessonController {
3639

3740
@GetMapping
3841
@Operation(summary = "레슨 검색 api", description = "category(필수, Default: \"ALL\") / search(선택) / 그외 법정동 선택 필수")
39-
public ResponseEntity<BaseResponse<LessonSearchListResponseDto>> searchLessons(
42+
public ResponseEntity<PagedResponse<LessonSearchListWrapperDto>> searchLessons(
4043
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
4144
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
4245
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@@ -47,9 +50,13 @@ public ResponseEntity<BaseResponse<LessonSearchListResponseDto>> searchLessons(
4750
@RequestParam String district,
4851
@RequestParam String dong
4952
) {
50-
LessonSearchListResponseDto lessonList = studentLessonService.searchLessons(page, limit, category, search, city,
51-
district, dong);
52-
return BaseResponse.ok("레슨 검색 조회 완료.", lessonList, HttpStatus.OK);
53+
54+
LessonSearchListResponseDto serviceResponse = studentLessonService.searchLessons(
55+
page, limit, category, search, city, district, dong
56+
);
57+
LessonSearchListWrapperDto response = new LessonSearchListWrapperDto(serviceResponse.lessons());
58+
59+
return PagedResponse.ok("레슨 검색 조회 완료.", response, serviceResponse.count(), HttpStatus.OK);
5360
}
5461

5562
@GetMapping("/{lessonId}")
@@ -91,7 +98,7 @@ public ResponseEntity<BaseResponse<Void>> deleteLessonApplication(
9198

9299
@GetMapping("/my-applications")
93100
@Operation(summary = "나의 레슨 신청 목록 조회", description = "현재 로그인한 사용자의 레슨 신청 목록을 조회합니다.")
94-
public ResponseEntity<BaseResponse<MyLessonApplicationListResponseDto>> getMyLessonApplications(
101+
public ResponseEntity<PagedResponse<MyLessonApplicationListWrapperDto>> getMyLessonApplications(
95102
@RequestParam(defaultValue = "1") @Min(value = 1, message = "페이지는 1 이상이어야 합니다.")
96103
@Max(value = 1000, message = "페이지는 1000 이하여야 합니다.") int page,
97104
@RequestParam(defaultValue = "5") @Min(value = 1, message = "limit는 1 이상이어야 합니다.")
@@ -104,9 +111,12 @@ public ResponseEntity<BaseResponse<MyLessonApplicationListResponseDto>> getMyLes
104111
throw new BusinessException(ErrorCode.AUTHENTICATION_REQUIRED);
105112
}
106113

107-
MyLessonApplicationListResponseDto response = studentLessonService.getMyLessonApplications(userId, page, limit,
108-
status);
109-
return BaseResponse.ok("나의 레슨 신청 목록 조회 완료.", response, HttpStatus.OK);
114+
MyLessonApplicationListResponseDto serviceResponse = studentLessonService.getMyLessonApplications(userId, page,
115+
limit, status);
116+
MyLessonApplicationListWrapperDto response = new MyLessonApplicationListWrapperDto(
117+
serviceResponse.lessonApplications());
118+
119+
return PagedResponse.ok("나의 레슨 신청 목록 조회 완료.", response, serviceResponse.count(), HttpStatus.OK);
110120
}
111121

112122
@GetMapping("/summary/{lessonId}")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.threestar.trainus.domain.lesson.student.dto;
2+
3+
import java.util.List;
4+
5+
public record LessonSearchListWrapperDto(
6+
List<LessonSearchResponseDto> lessons
7+
) {
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.threestar.trainus.domain.lesson.student.dto;
2+
3+
import java.util.List;
4+
5+
public record MyLessonApplicationListWrapperDto(
6+
List<MyLessonApplicationResponseDto> lessonApplications
7+
){
8+
}
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)