Skip to content

[TNT-225] feat: 트레이너 - 회원 목록 조회 시 응답 데이터 추가 #55

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

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/main/java/com/tnt/application/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public GetMemberInfoResponse getMemberInfo(Long memberId) {

int totalTraineeCount = ptTrainerTrainees.size();

TrainerInfo trainerInfo = new TrainerInfo(activeTraineeCount,
totalTraineeCount, trainer.getInvitationCode());
TrainerInfo trainerInfo = new TrainerInfo(activeTraineeCount, totalTraineeCount);

memberInfo = new GetMemberInfoResponse(member.getName(), member.getEmail(), member.getProfileImageUrl(),
member.getMemberType(), member.getSocialType(), trainerInfo, null);
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/com/tnt/application/pt/PtService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.tnt.application.pt;

import static com.tnt.common.error.model.ErrorMessage.PT_LESSON_DUPLICATE_TIME;
import static com.tnt.common.error.model.ErrorMessage.PT_LESSON_NOT_FOUND;
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINEE_ALREADY_EXIST;
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINER_TRAINEE_ALREADY_EXIST;
import static com.tnt.common.error.model.ErrorMessage.PT_TRAINER_TRAINEE_NOT_FOUND;
import static com.tnt.common.error.model.ErrorMessage.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -33,7 +29,7 @@
import com.tnt.dto.trainer.response.ConnectWithTraineeResponse.ConnectTraineeInfo;
import com.tnt.dto.trainer.response.ConnectWithTraineeResponse.ConnectTrainerInfo;
import com.tnt.dto.trainer.response.GetActiveTraineesResponse;
import com.tnt.dto.trainer.response.GetActiveTraineesResponse.TraineeDto;
import com.tnt.dto.trainer.response.GetActiveTraineesResponse.TraineeInfo;
import com.tnt.dto.trainer.response.GetCalendarPtLessonCountResponse;
import com.tnt.dto.trainer.response.GetCalendarPtLessonCountResponse.CalendarPtLessonCount;
import com.tnt.dto.trainer.response.GetPtLessonsOnDateResponse;
Expand Down Expand Up @@ -145,11 +141,23 @@ public GetActiveTraineesResponse getActiveTrainees(Long memberId) {
Trainer trainer = trainerService.getTrainerWithMemberId(memberId);

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

return new GetActiveTraineesResponse(traineeDto);
List<TraineeInfo> traineeInfo = trainees.stream().map(trainee -> {
PtTrainerTrainee ptTrainerTrainee = ptTrainerTraineeRepository.findByTraineeIdAndDeletedAtIsNull(
trainee.getId())
.orElseThrow(() -> new NotFoundException(TRAINEE_NOT_FOUND));

List<String> ptGoals = ptGoalService.getAllPtGoalsWithTraineeId(trainee.getId())
.stream()
.map(PtGoal::getContent)
.toList();

return new TraineeInfo(trainee.getId(), trainee.getMember().getName(),
ptTrainerTrainee.getFinishedPtCount(), ptTrainerTrainee.getTotalPtCount(), trainee.getCautionNote(),
ptGoals);
}).toList();

return new GetActiveTraineesResponse(trainees.size(), traineeInfo);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public record TrainerInfo(
Integer activeTraineeCount,

@Schema(description = "함께했던 회원", example = "50", nullable = true)
Integer totalTraineeCount,

@Schema(description = "트레이너 초대 코드", example = "2H9DG4X3", nullable = true)
String invitationCode
Integer totalTraineeCount
) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@

@Schema(description = "관리중인 트레이니 목록 응답")
public record GetActiveTraineesResponse(
@Schema(description = "트레이니 회원 수", nullable = false)
Integer traineeCount,

@Schema(description = "트레이니 목록", nullable = false)
List<TraineeDto> trainees
List<TraineeInfo> trainees
) {

public record TraineeDto(
public record TraineeInfo(
@Schema(description = "트레이니 ID", example = "123523564", nullable = false)
Long id,

@Schema(description = "트레이니 이름", example = "김정호", nullable = false)
String name
String name,

@Schema(description = "진행한 PT 횟수", example = "10", nullable = false)
Integer finishedPtCount,

@Schema(description = "총 PT 횟수", example = "100", nullable = false)
Integer totalPtCount,

@Schema(description = "주의사항", example = "가냘퍼요", nullable = true)
String cautionNote,

@Schema(description = "PT 목적들", example = "[\"체중 감량\", \"근력 향상\"]", nullable = false)
List<String> goalContents
) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

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

private final MockMultipartFile profileImage = new MockMultipartFile("profileImage", "test.jpg",
IMAGE_JPEG_VALUE, "test image content" .getBytes());
IMAGE_JPEG_VALUE, "test image content".getBytes());

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -267,7 +268,7 @@ void get_member_info_trainer_success() throws Exception {
.andExpect(jsonPath("$.socialType").value(trainerMember.getSocialType().name()))
.andExpect(jsonPath("$.trainer.activeTraineeCount").value(2))
.andExpect(jsonPath("$.trainer.totalTraineeCount").value(3))
.andExpect(jsonPath("$.trainer.invitationCode").value(trainer.getInvitationCode()));
.andDo(print());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.tnt.domain.trainer.Trainer;
import com.tnt.dto.trainer.request.CreatePtLessonRequest;
import com.tnt.fixture.MemberFixture;
import com.tnt.fixture.PtGoalsFixture;
import com.tnt.fixture.PtTrainerTraineeFixture;
import com.tnt.fixture.TraineeFixture;
import com.tnt.fixture.TrainerFixture;
Expand Down Expand Up @@ -457,6 +458,12 @@ void get_active_trainees_success() throws Exception {
trainee1 = traineeRepository.save(trainee1);
trainee2 = traineeRepository.save(trainee2);

List<PtGoal> ptGoals1 = PtGoalsFixture.getPtGoals(trainee1.getId());
List<PtGoal> ptGoals2 = PtGoalsFixture.getPtGoals(trainee2.getId());

ptGoalRepository.saveAll(ptGoals1);
ptGoalRepository.saveAll(ptGoals2);

PtTrainerTrainee ptTrainerTrainee1 = PtTrainerTraineeFixture.getPtTrainerTrainee1(trainer, trainee1);
PtTrainerTrainee ptTrainerTrainee2 = PtTrainerTraineeFixture.getPtTrainerTrainee2(trainer, trainee2);

Expand All @@ -469,8 +476,14 @@ void get_active_trainees_success() throws Exception {
.andExpect(jsonPath("$.trainees").isArray())
.andExpect(jsonPath("$.trainees[0].id").value(trainee1.getId()))
.andExpect(jsonPath("$.trainees[0].name").value(traineeMember1.getName()))
.andExpect(jsonPath("$.trainees[0].finishedPtCount").value(ptTrainerTrainee1.getFinishedPtCount()))
.andExpect(jsonPath("$.trainees[0].totalPtCount").value(ptTrainerTrainee1.getTotalPtCount()))
.andExpect(jsonPath("$.trainees[0].cautionNote").value(trainee1.getCautionNote()))
.andExpect(jsonPath("$.trainees[1].id").value(trainee2.getId()))
.andExpect(jsonPath("$.trainees[1].name").value(traineeMember2.getName()))
.andExpect(jsonPath("$.trainees[1].finishedPtCount").value(ptTrainerTrainee2.getFinishedPtCount()))
.andExpect(jsonPath("$.trainees[1].totalPtCount").value(ptTrainerTrainee2.getTotalPtCount()))
.andExpect(jsonPath("$.trainees[1].cautionNote").value(trainee2.getCautionNote()))
.andDo(print());
}

Expand Down