Skip to content

Commit

Permalink
Merge pull request #139 from Team-Going/feature/134
Browse files Browse the repository at this point in the history
[feat] 개별 프로필 조회 API 구현
  • Loading branch information
gardening-y authored Mar 4, 2024
2 parents a440c2f + 260c343 commit 597ea79
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ public ResponseEntity<BaseResponse<?>> updateParticipant(@PathVariable final Lon
tripDetailService.updateParticipant(userId, tripId, request);
return ApiResponseUtil.success(SuccessMessage.OK);
}

@GetMapping("/participants/{participantId}")
public ResponseEntity<BaseResponse<?>> getParticipantProfile(@PathVariable final Long participantId,
@UserId final Long userId) {
final TripParticipantProfileResponse response = tripDetailService.getParticipantProfile(userId, participantId);
return ApiResponseUtil.success(SuccessMessage.OK, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.doorip.trip.dto.response;

import lombok.AccessLevel;
import lombok.Builder;
import org.doorip.trip.domain.Participant;
import org.doorip.user.domain.User;

@Builder(access = AccessLevel.PRIVATE)
public record TripParticipantProfileResponse(
String name,
String intro,
int result,
int styleA,
int styleB,
int styleC,
int styleD,
int styleE,
boolean isOwner

) {

public static TripParticipantProfileResponse of(User user, int validatedResult, Participant participant, boolean isOwner) {
return TripParticipantProfileResponse.builder()
.name(user.getName())
.intro(user.getIntro())
.result(validatedResult)
.styleA(participant.getStyleA())
.styleB(participant.getStyleB())
.styleC(participant.getStyleC())
.styleD(participant.getStyleD())
.styleE(participant.getStyleE())
.isOwner(isOwner)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.doorip.message.ErrorMessage;
import org.doorip.trip.domain.*;
import org.doorip.trip.dto.request.ParticipantUpdateRequest;
import org.doorip.trip.dto.response.MyTodoResponse;
import org.doorip.trip.dto.response.OurTodoResponse;
import org.doorip.trip.dto.response.TripParticipantGetResponse;
import org.doorip.trip.dto.response.TripStyleResponse;
import org.doorip.trip.dto.response.*;
import org.doorip.trip.repository.ParticipantRepository;
import org.doorip.trip.repository.TodoRepository;
import org.doorip.trip.repository.TripRepository;
Expand Down Expand Up @@ -81,6 +78,15 @@ public void updateParticipant(Long userId, Long tripId, ParticipantUpdateRequest
findParticipant.updateStyles(request.styleA(), request.styleB(), request.styleC(), request.styleD(), request.styleE());
}

public TripParticipantProfileResponse getParticipantProfile(Long userId, Long participantId) {
User findUser = getUser(userId);
Participant findParticipant = getParticipantById(participantId);
User participantUser = findParticipant.getUser();
boolean isOwner = isEqualUserAndParticipantUser(findUser, participantUser);
int validatedResult = getValidatedResult(participantUser);
return TripParticipantProfileResponse.of(participantUser, validatedResult, findParticipant, isOwner);
}

private Map<String, Integer> createDefaultPropensity() {
return new HashMap<>(Map.of(STYLE_A, MIN_STYLE_RATE, STYLE_B, MIN_STYLE_RATE,
STYLE_C, MIN_STYLE_RATE, STYLE_D, MIN_STYLE_RATE, STYLE_E, MIN_STYLE_RATE)) {
Expand Down Expand Up @@ -192,4 +198,21 @@ private int calculatePropensityWeight(boolean isLeft, int rate) {
}
return rate;
}

private Participant getParticipantById(Long id) {
return participantRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(ErrorMessage.PARTICIPANT_NOT_FOUND));
}

private boolean isEqualUserAndParticipantUser(User user, User participantUser) {
return user.equals(participantUser);
}

private int getValidatedResult(User user) {
try {
return user.getResult().getNumResult();
} catch (NullPointerException e) {
return -1;
}
}
}

0 comments on commit 597ea79

Please sign in to comment.