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

feat: 시간표 프레임 한번에 조회 구현 #1108

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ResponseEntity<TimetableFrameUpdateResponse> updateTimetableFrame(
@Operation(summary = "시간표 프레임 조회")
@SecurityRequirement(name = "Jwt Authentication")
@GetMapping("/v2/timetables/frame")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R

이거 왜 인지 모르겠는데, 컨트롤러랑 API Path가 다르네요..? 뭐지뭐지

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미 클라에서 적용이 됐을 것 같은데 /v2/timetables/frame은 기존 방식, /v2/timetables/frames는 새로운 방식으로 나눠도 좋을 것 같아요. 대응이 필요한,,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스웨거에는 기존꺼도 /v2/timetables/frames로 올라가있네요!
저는 그래서 그냥 지금처럼 해도 되지 않을까 하는데 어떻게 생각하시나요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니당

ResponseEntity<List<TimetableFrameResponse>> getTimetablesFrame(
ResponseEntity<Object> getTimetablesFrame(
@RequestParam(name = "semester") String semester,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

여기에도 required 옵션 줘야 하나용 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 꼼꼼하시네요bb

@Auth(permit = {STUDENT}) Integer userId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public ResponseEntity<TimetableFrameUpdateResponse> updateTimetableFrame(
}

@GetMapping("/v2/timetables/frames")
public ResponseEntity<List<TimetableFrameResponse>> getTimetablesFrame(
@RequestParam(name = "semester") String semester,
public ResponseEntity<Object> getTimetablesFrame(
@RequestParam(name = "semester", required = false) String semester,
@Auth(permit = {STUDENT}) Integer userId
) {
List<TimetableFrameResponse> response = frameServiceV2.getTimetablesFrame(userId, semester);
Object response = frameServiceV2.getTimetablesFrame(userId, semester);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ SELECT COUNT(t) FROM TimetableFrame t
void deleteAllByUser(User user);

void deleteAllByUserAndSemester(User user, Semester semester);

List<TimetableFrame> findAllByUserId(Integer userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static in.koreatech.koin.domain.timetableV2.validation.TimetableFrameValidate.validateUserAuthorization;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -57,13 +59,30 @@ public TimetableFrameUpdateResponse updateTimetableFrame(
return timetableFrameUpdater.updateTimetableFrame(frame, userId, request.timetableName(), request.isMain());
}

public List<TimetableFrameResponse> getTimetablesFrame(Integer userId, String semesterRequest) {
public Object getTimetablesFrame(Integer userId, String semesterRequest) {
if (semesterRequest == null) {
return getAllTimetablesFrame(userId);
}

Semester semester = semesterRepositoryV2.getBySemester(semesterRequest);
return timetableFrameRepositoryV2.findAllByUserIdAndSemesterId(userId, semester.getId()).stream()
.map(TimetableFrameResponse::from)
.toList();
}

@Transactional(readOnly = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

클래스에 readOnly 트랜잭션이 걸려있는데, 여기에 추가하신 이유가 궁금합니다 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지우겠습니다!

public Map<String, Map<String, List<TimetableFrameResponse>>> getAllTimetablesFrame(Integer userId) {
List<TimetableFrame> timetableFrames = timetableFrameRepositoryV2.findAllByUserId(userId);

Map<String, List<TimetableFrameResponse>> groupedBySemester = timetableFrames.stream()
.collect(Collectors.groupingBy(
frame -> frame.getSemester().getSemester(),
Collectors.mapping(TimetableFrameResponse::from, Collectors.toList())
));

return Map.of("semesters", groupedBySemester);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

dto 클래스로 반환할 수 있을 것 같아요.
리펙토링 할 때 반영하면 좋을 것 같아요 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 생각없이 만들어서 바로 올리고 씻으면서 dto로 변환해야겠다 바로 생각이 들었었습니다..ㅎㅎ
짚어주셔서 감사합니당 수정하겠습니다!

}

@Transactional
public void deleteAllTimetablesFrame(Integer userId, String semester) {
User user = userRepository.getById(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,59 @@ void setup() {
assertThat(timetableFrameRepositoryV2.findById(frame2.getId())).isNotPresent();
assertThat(timetableFrameRepositoryV2.findById(frame3.getId())).isNotPresent();
}

@Test
void 모든_학기의_시간표_프레임을_조회한다() throws Exception {
Semester semester1 = semesterFixture.semester("20241");
Semester semester2 = semesterFixture.semester("20242");

timetableV2Fixture.시간표1(user, semester1);
timetableV2Fixture.시간표2(user, semester1);

timetableV2Fixture.시간표1(user, semester2);
timetableV2Fixture.시간표2(user, semester2);
timetableV2Fixture.시간표3(user, semester2);

mockMvc.perform(
get("/v2/timetables/frames")
.header("Authorization", "Bearer " + token)
.contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(content().json("""
{
"semesters": {
"20241": [
{
"id": 1,
"timetable_name": "시간표1",
"is_main": true
},
{
"id": 2,
"timetable_name": "시간표2",
"is_main": false
}
],
"20242": [
{
"id": 3,
"timetable_name": "시간표1",
"is_main": true
},
{
"id": 4,
"timetable_name": "시간표2",
"is_main": false
},
{
"id": 5,
"timetable_name": "시간표3",
"is_main": false
}
]
}
}
"""));
}
}
Loading