Skip to content

Commit 7f1dd71

Browse files
authored
[TNT-225] feat: 트레이너 - 회원 목록 조회 시 응답 데이터 추가 (#55)
* [TNT-225] feat: 회원 목록 조회 시 응답 데이터 추가 * [TNT-225] feat: config 수정 * [TNT-225] feat: TRAINEE_NOT_FOUND 추가 * [TNT-225] feat: 트레이너 코드 제거
1 parent cdbfae6 commit 7f1dd71

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

Diff for: src/main/java/com/tnt/application/member/MemberService.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public GetMemberInfoResponse getMemberInfo(Long memberId) {
7171

7272
int totalTraineeCount = ptTrainerTrainees.size();
7373

74-
TrainerInfo trainerInfo = new TrainerInfo(activeTraineeCount,
75-
totalTraineeCount, trainer.getInvitationCode());
74+
TrainerInfo trainerInfo = new TrainerInfo(activeTraineeCount, totalTraineeCount);
7675

7776
memberInfo = new GetMemberInfoResponse(member.getName(), member.getEmail(), member.getProfileImageUrl(),
7877
member.getMemberType(), member.getSocialType(), trainerInfo, null);

Diff for: src/main/java/com/tnt/application/pt/PtService.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.tnt.application.pt;
22

3-
import static com.tnt.common.error.model.ErrorMessage.PT_LESSON_DUPLICATE_TIME;
4-
import static com.tnt.common.error.model.ErrorMessage.PT_LESSON_NOT_FOUND;
5-
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINEE_ALREADY_EXIST;
6-
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINER_TRAINEE_ALREADY_EXIST;
7-
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINER_TRAINEE_NOT_FOUND;
3+
import static com.tnt.common.error.model.ErrorMessage.*;
84

95
import java.time.LocalDate;
106
import java.time.LocalDateTime;
@@ -33,7 +29,7 @@
3329
import com.tnt.dto.trainer.response.ConnectWithTraineeResponse.ConnectTraineeInfo;
3430
import com.tnt.dto.trainer.response.ConnectWithTraineeResponse.ConnectTrainerInfo;
3531
import com.tnt.dto.trainer.response.GetActiveTraineesResponse;
36-
import com.tnt.dto.trainer.response.GetActiveTraineesResponse.TraineeDto;
32+
import com.tnt.dto.trainer.response.GetActiveTraineesResponse.TraineeInfo;
3733
import com.tnt.dto.trainer.response.GetCalendarPtLessonCountResponse;
3834
import com.tnt.dto.trainer.response.GetCalendarPtLessonCountResponse.CalendarPtLessonCount;
3935
import com.tnt.dto.trainer.response.GetPtLessonsOnDateResponse;
@@ -145,11 +141,23 @@ public GetActiveTraineesResponse getActiveTrainees(Long memberId) {
145141
Trainer trainer = trainerService.getTrainerWithMemberId(memberId);
146142

147143
List<Trainee> trainees = ptTrainerTraineeSearchRepository.findAllTrainees(trainer.getId());
148-
List<TraineeDto> traineeDto = trainees.stream()
149-
.map(trainee -> new TraineeDto(trainee.getId(), trainee.getMember().getName()))
150-
.toList();
151144

152-
return new GetActiveTraineesResponse(traineeDto);
145+
List<TraineeInfo> traineeInfo = trainees.stream().map(trainee -> {
146+
PtTrainerTrainee ptTrainerTrainee = ptTrainerTraineeRepository.findByTraineeIdAndDeletedAtIsNull(
147+
trainee.getId())
148+
.orElseThrow(() -> new NotFoundException(TRAINEE_NOT_FOUND));
149+
150+
List<String> ptGoals = ptGoalService.getAllPtGoalsWithTraineeId(trainee.getId())
151+
.stream()
152+
.map(PtGoal::getContent)
153+
.toList();
154+
155+
return new TraineeInfo(trainee.getId(), trainee.getMember().getName(),
156+
ptTrainerTrainee.getFinishedPtCount(), ptTrainerTrainee.getTotalPtCount(), trainee.getCautionNote(),
157+
ptGoals);
158+
}).toList();
159+
160+
return new GetActiveTraineesResponse(trainees.size(), traineeInfo);
153161
}
154162

155163
@Transactional

Diff for: src/main/java/com/tnt/dto/member/response/GetMemberInfoResponse.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public record TrainerInfo(
3737
Integer activeTraineeCount,
3838

3939
@Schema(description = "함께했던 회원", example = "50", nullable = true)
40-
Integer totalTraineeCount,
41-
42-
@Schema(description = "트레이너 초대 코드", example = "2H9DG4X3", nullable = true)
43-
String invitationCode
40+
Integer totalTraineeCount
4441
) {
4542

4643
}

Diff for: src/main/java/com/tnt/dto/trainer/response/GetActiveTraineesResponse.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66

77
@Schema(description = "관리중인 트레이니 목록 응답")
88
public record GetActiveTraineesResponse(
9+
@Schema(description = "트레이니 회원 수", nullable = false)
10+
Integer traineeCount,
11+
912
@Schema(description = "트레이니 목록", nullable = false)
10-
List<TraineeDto> trainees
13+
List<TraineeInfo> trainees
1114
) {
1215

13-
public record TraineeDto(
16+
public record TraineeInfo(
1417
@Schema(description = "트레이니 ID", example = "123523564", nullable = false)
1518
Long id,
1619

1720
@Schema(description = "트레이니 이름", example = "김정호", nullable = false)
18-
String name
21+
String name,
22+
23+
@Schema(description = "진행한 PT 횟수", example = "10", nullable = false)
24+
Integer finishedPtCount,
25+
26+
@Schema(description = "총 PT 횟수", example = "100", nullable = false)
27+
Integer totalPtCount,
28+
29+
@Schema(description = "주의사항", example = "가냘퍼요", nullable = true)
30+
String cautionNote,
31+
32+
@Schema(description = "PT 목적들", example = "[\"체중 감량\", \"근력 향상\"]", nullable = false)
33+
List<String> goalContents
1934
) {
2035

2136
}

Diff for: src/test/java/com/tnt/presentation/member/MemberControllerTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
1212
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
1313
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
1415
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
1516
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1617

@@ -70,7 +71,7 @@ class MemberControllerTest extends AbstractContainerBaseTest {
7071
private final GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
7172

7273
private final MockMultipartFile profileImage = new MockMultipartFile("profileImage", "test.jpg",
73-
IMAGE_JPEG_VALUE, "test image content" .getBytes());
74+
IMAGE_JPEG_VALUE, "test image content".getBytes());
7475

7576
@Autowired
7677
private MockMvc mockMvc;
@@ -267,7 +268,7 @@ void get_member_info_trainer_success() throws Exception {
267268
.andExpect(jsonPath("$.socialType").value(trainerMember.getSocialType().name()))
268269
.andExpect(jsonPath("$.trainer.activeTraineeCount").value(2))
269270
.andExpect(jsonPath("$.trainer.totalTraineeCount").value(3))
270-
.andExpect(jsonPath("$.trainer.invitationCode").value(trainer.getInvitationCode()));
271+
.andDo(print());
271272
}
272273

273274
@Test

Diff for: src/test/java/com/tnt/presentation/trainer/TrainerControllerTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.tnt.domain.trainer.Trainer;
3939
import com.tnt.dto.trainer.request.CreatePtLessonRequest;
4040
import com.tnt.fixture.MemberFixture;
41+
import com.tnt.fixture.PtGoalsFixture;
4142
import com.tnt.fixture.PtTrainerTraineeFixture;
4243
import com.tnt.fixture.TraineeFixture;
4344
import com.tnt.fixture.TrainerFixture;
@@ -457,6 +458,12 @@ void get_active_trainees_success() throws Exception {
457458
trainee1 = traineeRepository.save(trainee1);
458459
trainee2 = traineeRepository.save(trainee2);
459460

461+
List<PtGoal> ptGoals1 = PtGoalsFixture.getPtGoals(trainee1.getId());
462+
List<PtGoal> ptGoals2 = PtGoalsFixture.getPtGoals(trainee2.getId());
463+
464+
ptGoalRepository.saveAll(ptGoals1);
465+
ptGoalRepository.saveAll(ptGoals2);
466+
460467
PtTrainerTrainee ptTrainerTrainee1 = PtTrainerTraineeFixture.getPtTrainerTrainee1(trainer, trainee1);
461468
PtTrainerTrainee ptTrainerTrainee2 = PtTrainerTraineeFixture.getPtTrainerTrainee2(trainer, trainee2);
462469

@@ -469,8 +476,14 @@ void get_active_trainees_success() throws Exception {
469476
.andExpect(jsonPath("$.trainees").isArray())
470477
.andExpect(jsonPath("$.trainees[0].id").value(trainee1.getId()))
471478
.andExpect(jsonPath("$.trainees[0].name").value(traineeMember1.getName()))
479+
.andExpect(jsonPath("$.trainees[0].finishedPtCount").value(ptTrainerTrainee1.getFinishedPtCount()))
480+
.andExpect(jsonPath("$.trainees[0].totalPtCount").value(ptTrainerTrainee1.getTotalPtCount()))
481+
.andExpect(jsonPath("$.trainees[0].cautionNote").value(trainee1.getCautionNote()))
472482
.andExpect(jsonPath("$.trainees[1].id").value(trainee2.getId()))
473483
.andExpect(jsonPath("$.trainees[1].name").value(traineeMember2.getName()))
484+
.andExpect(jsonPath("$.trainees[1].finishedPtCount").value(ptTrainerTrainee2.getFinishedPtCount()))
485+
.andExpect(jsonPath("$.trainees[1].totalPtCount").value(ptTrainerTrainee2.getTotalPtCount()))
486+
.andExpect(jsonPath("$.trainees[1].cautionNote").value(trainee2.getCautionNote()))
474487
.andDo(print());
475488
}
476489

0 commit comments

Comments
 (0)