-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#10] 나의 여행 등록 설정 #12
Merged
Merged
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8e5d8fd
feat: 토큰 검증 argument resolver 추가
hynxp 5e9d7fc
feat: 사용자 여행 일정 관련 도메인 추가
hynxp 6a910f6
chore: starter-validation 의존성 추가
hynxp 844bbb0
style: travel->travelschedule 패키지명 변경
hynxp 4cfa1d9
test: city, country 기본 데이터 추가 세팅 및 테스트 db 변경
hynxp 753f179
feat: 나의 여행 일정 추가 구현
hynxp f1a551a
test: 나의 여행 일정 서비스 테스트 추가
hynxp 8891965
refactor: 미사용 repository 제거
hynxp d35d3ee
feat: 여행 일정 조회 구현
hynxp ee4048e
test: 여행 일정 조회 테스트 추가 및 기존 테스트 수정
hynxp 1706182
test: 미사용 필드 제거
hynxp cc689d6
test: 여행 일정 컨트롤러 테스트 추가
hynxp e92d5a5
refactor: request, responsea 직렬화/역직렬화 어노테이션 설정
hynxp 6d6449e
refactor: 여행 일정 설정 메서드 네이밍 변경
hynxp 2f86ff1
refactor: 여행 일정 설정 메서드 네이밍 변경, city 테이블 반복 조회 개선
hynxp 912d976
test: 존재하지 않는 도시 id로 여행 일정 등록 시 예외 테스트 코드 수정
hynxp 1e7610b
refactor: 테스트 쪽 환경변수 및 스크립트 파일 제거
hynxp 117d0fd
test: argument resolve 모킹 제거, 컨트롤러 테스트 REST-Assured으로 수정
hynxp 354957e
refactor: member.sql 중복 삽입 방지
hynxp 9200d68
refactor: member 내 테스트용 정적 팩토리 메서드 제거
hynxp 5e9c116
refactor: 도메인 MemberTravelSchedule -> TravelSchedule 네이밍 수정
hynxp 6f9420f
refactor: 여행 일정 관련 도메인 지연 로딩으로 변경
hynxp edf2890
test: @DisplayName -> 메서드명으로 변경, RestAssured로 수정
hynxp 3361608
chore: 토큰 시간 관련 임의 환경변수로 세팅 및 테스트 코드 제거
hynxp 4a02c5f
refactor: ~~NotFoundException 통일
hynxp fa4a5a5
refactor: 토큰에서 member추출 메서드 네이밍 변경
hynxp 4fa5360
refactor: 사용하지 않는 에러코드 제거
hynxp 105b7a3
refactor: 여행 일정 도시 추가 메서드 네이밍 변경
hynxp 5686450
refactor: 테스트 환경 h2DB로 변경
hynxp ccafacc
refactor: Member TestFixture 사용, 테스트 데이터 초기화 클래스 추가
hynxp 0865b99
chore: TestOauth 패키지 이동
hynxp 73255cd
refactor: 멤버 id 상수 사용 부분 제거
hynxp 41d769a
refactor: TravelScheduleResponse 변환 책임 이동, 국가 이름도 반환
hynxp 39f0227
Merge branch 'main' of https://github.com/f-lab-edu/Udong into feat/r…
hynxp ef6d45f
refactor: staleObjectStateException, ObjectOptimisticLockingFailureEx…
hynxp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/hyun/udong/auth/exception/UnAuthenticatedMemberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hyun.udong.auth.exception; | ||
|
||
import com.hyun.udong.common.exception.ErrorCode; | ||
import com.hyun.udong.common.exception.UdongException; | ||
|
||
public class UnAuthenticatedMemberException extends UdongException { | ||
public static final UdongException EXCEPTION = new UnAuthenticatedMemberException(); | ||
|
||
private UnAuthenticatedMemberException() { | ||
super(ErrorCode.UNAUTHENTICATED_MEMBER); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/hyun/udong/auth/presentation/resolver/AuthenticationArgumentResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.hyun.udong.auth.presentation.resolver; | ||
|
||
import com.hyun.udong.auth.application.service.AuthService; | ||
import com.hyun.udong.auth.exception.UnAuthenticatedMemberException; | ||
import com.hyun.udong.common.annotation.LoginMember; | ||
import com.hyun.udong.member.domain.Member; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
@Component | ||
public class AuthenticationArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
private static final String PREFIX = "Bearer "; | ||
|
||
private final AuthService authService; | ||
|
||
public AuthenticationArgumentResolver(AuthService authService) { | ||
this.authService = authService; | ||
} | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.hasParameterAnnotation(LoginMember.class) | ||
&& parameter.getParameterType().equals(Member.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, | ||
ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, | ||
WebDataBinderFactory binderFactory) { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
String token = request.getHeader("Authorization"); | ||
|
||
isValidToken(token); | ||
|
||
return authService.getMemberFromToken(token.substring(PREFIX.length())); | ||
} | ||
|
||
private void isValidToken(String token) { | ||
if (token == null || !token.startsWith(PREFIX)) { | ||
throw UnAuthenticatedMemberException.EXCEPTION; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/hyun/udong/common/annotation/DateFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hyun.udong.common.annotation; | ||
|
||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
@JacksonAnnotationsInside | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") | ||
public @interface DateFormat { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/hyun/udong/common/annotation/LoginMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hyun.udong.common.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface LoginMember { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.hyun.udong.common.config; | ||
|
||
import com.hyun.udong.auth.presentation.resolver.AuthenticationArgumentResolver; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
private final AuthenticationArgumentResolver authenticationArgumentResolver; | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(authenticationArgumentResolver); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/hyun/udong/common/entity/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.hyun.udong.common.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
|
||
@Column(updatable = false) | ||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@Column | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hyun/udong/common/exception/NotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hyun.udong.common.exception; | ||
|
||
public class NotFoundException extends UdongException { | ||
public NotFoundException(String message) { | ||
super(ErrorCode.MEMBER_TRAVEL_SCHEDULE_NOT_FOUND, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
src/main/java/com/hyun/udong/member/exception/MemberNotFoundException.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
src/main/java/com/hyun/udong/travelschedule/application/service/TravelScheduleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.hyun.udong.travelschedule.application.service; | ||
|
||
import com.hyun.udong.common.exception.NotFoundException; | ||
import com.hyun.udong.member.domain.Member; | ||
import com.hyun.udong.member.infrastructure.repository.MemberRepository; | ||
import com.hyun.udong.travelschedule.domain.City; | ||
import com.hyun.udong.travelschedule.domain.TravelSchedule; | ||
import com.hyun.udong.travelschedule.domain.TravelScheduleCity; | ||
import com.hyun.udong.travelschedule.infrastructure.repository.CityRepository; | ||
import com.hyun.udong.travelschedule.infrastructure.repository.TravelScheduleRepository; | ||
import com.hyun.udong.travelschedule.presentation.dto.TravelScheduleRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class TravelScheduleService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final TravelScheduleRepository travelScheduleRepository; | ||
private final CityRepository cityRepository; | ||
|
||
@Transactional | ||
public TravelSchedule updateTravelSchedule(Long memberId, TravelScheduleRequest request) { | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException("해당 회원이 존재하지 않습니다.")); | ||
|
||
TravelSchedule travelSchedule = TravelSchedule.builder() | ||
.startDate(request.getStartDate()) | ||
.endDate(request.getEndDate()) | ||
.build(); | ||
|
||
List<City> cities = cityRepository.findAllById(request.getCityIds()); | ||
if (cities.size() != request.getCityIds().size()) { | ||
throw new NotFoundException("해당 도시가 존재하지 않습니다."); | ||
} | ||
hynxp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List<TravelScheduleCity> travelScheduleCities = cities.stream() | ||
.map(city -> new TravelScheduleCity(travelSchedule, city)) | ||
.toList(); | ||
travelSchedule.addTravelScheduleCities(travelScheduleCities); | ||
travelScheduleRepository.save(travelSchedule); | ||
|
||
member.updateTravelSchedule(travelSchedule); | ||
|
||
return travelSchedule; | ||
} | ||
|
||
public TravelSchedule findTravelSchedule(Long memberId) { | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException("해당 회원이 존재하지 않습니다.")); | ||
|
||
TravelSchedule travelSchedule = member.getTravelSchedule(); | ||
if (travelSchedule == null) { | ||
throw new NotFoundException("여행 일정이 존재하지 않습니다."); | ||
} | ||
return travelSchedule; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거는 적용하라는 의미는 아니고 아이디어를 하나 드립니다.
매번 해당하는 ~가 존재하지 않습니다 메시지 적기 귀찮을 수 있으니, NotFoundException 단에서 "해당하는 %이 존재하지 않습니다." 상수를 만들어 놓고 생성자를 통해 문자열만 받거나 클래스 자체를 넘기는 방법도 있어요! 후자를 선택한다면 약간의 리플렉션 작업(클래스 이름 추출)을 하긴 해야하지만요 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오오.. 다른 프로젝트에서 본 것 같아요!
에러 핸들링 이슈(#9)에서 적용해보겠습니다~