Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public class TripService
@Override
public TripCreateResponse createTrip(UUID memberId, TripCreateRequest request) {
Trip trip = request.to(memberId);
assignPasswordIfNotOpen(trip, request.password());
Trip savedTrip = tripRepository.save(trip);
return TripCreateResponse.of(savedTrip);
}

@Override
public TripCreateResponse createTripWithItineraries(UUID memberId, TripCreateRequest request) {
Trip trip = request.toWithItineraries(memberId);
assignPasswordIfNotOpen(trip, request.password());
Trip savedTrip = tripRepository.save(trip);
return TripCreateResponse.of(savedTrip);
}
Expand Down Expand Up @@ -164,7 +162,7 @@ private void assignPasswordIfNotOpen(Trip trip, String password) {
if (trip.isOpen()) {
return;
}
String trimPassword = password.trim();
String trimPassword = (password != null) ? password.trim() : "";
if (!StringUtils.hasText(trimPassword)) {
throw new InvalidValueException(PRIVATE_TRIP_PASSWORD_REQUIRED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public record TripCreateRequest(
@FutureOrPresent
LocalDate end,

@Schema(description = "여행 공개 여부")
boolean open,

@Schema(description = "여행 참여 비밀번호")
String password,
// @Schema(description = "여행 공개 여부")
// boolean open,
//
// @Schema(description = "여행 참여 비밀번호")
// String password,

@Schema(description = "여행 최대 참가 인원")
int maxParticipants,
Expand All @@ -63,7 +63,7 @@ public Trip to(UUID memberId) {
imageUrl,
new TripDescription(description),
new TripPeriod(start, end),
open,
true,
maxParticipants,
hashTags,
category,
Expand All @@ -79,7 +79,7 @@ public Trip toWithItineraries(UUID memberId) {
imageUrl,
new TripDescription(description),
new TripPeriod(start, end),
open,
true,
Copy link
Contributor

Choose a reason for hiding this comment

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

해당 값 임시로 하드 코딩 한것일까요??
나중에는 아예 제거하는 것인지 문의 드려요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네, 맞습니다! 기획 사항이 변경되어 여행 생성 시에는 항상 공개 상태로 시작하고 이후에 비공개로 전환된다고 전달받았습니다. 그래서 Request DTO에서 open 필드를 제거했고 엔티티 생성 시에는 true(공개)를 고정값으로 넘겨주도록 수정했습니다! 비밀번호(password) 필드도 같은 이유로 제거했습니다!

maxParticipants,
hashTags,
category,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.retrip.trip.application.in.request.context;

import io.swagger.v3.oas.annotations.Parameter;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Parameter(hidden = true)
public @interface WithUserContext {
}
boolean required() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public record TripDetailResponse(
public static TripDetailResponse of(UUID memberId, Trip trip) {
return TripDetailResponse.builder()
.id(trip.getId())
.isLeader(trip.getTripParticipants().isLeader(memberId))
.isParticipant(trip.getTripParticipants().isParticipant(memberId))
.isLeader(memberId != null && trip.getTripParticipants().isLeader(memberId))
.isParticipant(memberId != null && trip.getTripParticipants().isParticipant(memberId))
.title(trip.getTitle().getValue())
.createdAt(trip.getCreatedAt())
.participantCount(trip.getTripParticipants().getCurrentCount())
Expand Down Expand Up @@ -158,14 +158,13 @@ public static List<TripParticipantResponse> toList(List<TripParticipant> tripPar
.toList();
}

//TODO: 해당 참가자 정보 auth API 에서 따로 가져오도록 수정해야함
private static TripParticipantResponse of(TripParticipant participant) {
return TripParticipantResponse.builder()
.participantId(participant.getId())
.memberId(participant.getMemberId())
.introduction("안녕하세여")
.nickName("박정수")
.imageUrl("http://~~~")
.introduction(null)
Copy link
Contributor

Choose a reason for hiding this comment

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

해당 값은 왜 Null로 세팅한 것일까요??
여행 참여 시 입력되는 값인거 같아서 문의드려요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

현재 Trip 서비스에서 참여자의 상세 프로필 정보(자기소개, 프로필 사진)를 조회하려면 Auth 서비스에서 member 정보와 연동이 필요한데 아직 해당 기능이 구현 전 단계입니다. 기존에는 하드코딩된 값이 내려가고 있어 모든 참가자가 똑같아 보이는 문제가 있었습니다. 우선 프론트엔드에서 null일 경우 기본 이미지,텍스트를 보여주는것으로 말씀드릴 예정이라 null로 변경했습니다. 추후 User 서비스 연동 시 실제 데이터로 교체될 예정입니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

@ekfrehd 님 넵! 이해했습니다.
추후 WebClient나 Feign Client 사용해서 연결하는 작업 필요할 거 같습니다.

.nickName("여행자-" + participant.getMemberId().toString().substring(0, 8))
.imageUrl(null)
.role(participant.getRole())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
Expand All @@ -30,6 +31,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {

String path = request.getRequestURI();
String pathLowercase = path.toLowerCase();

Expand All @@ -39,48 +41,43 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
pathLowercase.contains("actuator") ||
pathLowercase.contains("robots.txt") ||
pathLowercase.contains("status-check") ||
pathLowercase.contains("trips") ||
pathLowercase.contains("images") ||
pathLowercase.contains("/h2-console")) {
filterChain.doFilter(request, response);
return;
}

String token = resolveToken(request);
if (token == null || token.isEmpty()) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}

try {
Claims claims = getClaims(token);
if (StringUtils.hasText(token)) {
try {
Claims claims = getClaims(token);

String subject = claims.getSubject();
UUID memberId = UUID.fromString(subject);
String subject = claims.getSubject();
UUID memberId = UUID.fromString(subject);

UserContext userContext = new UserContext(
memberId,
claims.get("nickname", String.class),
claims.get("email", String.class),
claims.get("name", String.class),
null,
0
);
UserContext userContext = new UserContext(
memberId,
claims.get("nickname", String.class),
claims.get("email", String.class),
claims.get("name", String.class),
null,
0
);

request.setAttribute("userContext", userContext);

filterChain.doFilter(request, response);

} catch (Exception e) {
log.error("Token validation failed: {}", e.getMessage());
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
request.setAttribute("userContext", userContext);

} catch (Exception e) {
log.warn("Invalid Token: {}", e.getMessage());
}
}

filterChain.doFilter(request, response);
}

private String resolveToken(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ public class UserContextArgumentResolver implements HandlerMethodArgumentResolve

@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(WithUserContext.class);
return parameter.hasParameterAnnotation(WithUserContext.class)
&& parameter.getParameterType().equals(UserContext.class);
}

@Override
public UserContext resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
// UserContext userContext = (UserContext) webRequest.getAttribute(
// "userContext",
// RequestAttributes.SCOPE_REQUEST
// );
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

UserContext userContext = UserContext.mockOf();
UserContext userContext = (UserContext) webRequest.getAttribute(
"userContext",
RequestAttributes.SCOPE_REQUEST
);

if (userContext == null) {
throw new IllegalStateException("UserContext not found in request");
WithUserContext annotation = parameter.getParameterAnnotation(WithUserContext.class);
boolean required = (annotation != null) && annotation.required();

if (required && userContext == null) {
throw new IllegalStateException("Login required");
}

return userContext;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ public ApiResponse<Page<TripResponse>> getTrips(
return ApiResponse.ok(trips);
}


@Operation(
summary = "여행 상세 조회",
description = "tripId를 이용하여 여행 상세 정보를 조회하는 API"
description = "tripId를 이용하여 여행 상세 정보를 조회합니다. (비로그인 가능)"
)
@ApiErrorCodeExample(TRIP_NOT_FOUND)
@GetMapping("/{tripId}")
public ApiResponse<TripDetailResponse> getTripDetail(@WithUserContext UserContext userContext,
@PathVariable UUID tripId) {
TripDetailResponse tripDetail = getTripUseCase.getTripDetail(userContext.memberId(), tripId);
@Schema(description = "여행 상세 조회")
public ApiResponse<TripDetailResponse> getTripDetail(
@WithUserContext(required = false) UserContext userContext,
@PathVariable UUID tripId) {

UUID memberId = (userContext != null) ? userContext.memberId() : null;

TripDetailResponse tripDetail = getTripUseCase.getTripDetail(memberId, tripId);
return ApiResponse.ok(tripDetail);
}

Expand Down