-
Notifications
You must be signed in to change notification settings - Fork 97
[그리디] 정명준 Spring Data JPA 6단계 제출합니다. #270
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
base: htdufhc-bit
Are you sure you want to change the base?
Changes from 70 commits
db19123
b6ba2cb
5e7b687
ec6ee6d
b17debb
6e1c475
ba98c27
2b95ab2
1c8cfde
ab7f70c
eae5e9a
bf6ac7b
fd847c1
8acaa21
787f1a6
6d4cc45
219413c
5d94f7e
7daa481
1e3fdb3
aac8aa3
4093c0b
557971d
1d58693
7c289c3
a5fa426
50a30f4
31bb114
4975da3
5bc54ca
6eb6095
b400cf2
753f82a
dded032
5e0c8a7
ccb028c
e1b65c3
ce5ad9a
0a3086e
0a7c180
da760e9
b325fc5
3c1f8f2
4108114
f7b7531
f16fde7
084d3eb
4b53082
1902301
6813feb
fb8ea71
72a68ca
0a710ce
5a080cf
85ad22d
363a773
436ecde
8d117f1
dc5b5e7
621f6a1
f81cc37
322d8c1
fa7cd36
787091a
2343bc4
e1fac12
c3bda17
6402408
eaec41b
63bc184
6eaf8f3
ca1f694
6e99544
f2fd69f
4ff2550
795d0ad
d1da150
1e36599
69db99b
5b1a969
72349b2
773b636
e385e04
dfba04f
bada4a5
14acc26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| package roomescape.auth.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
| import roomescape.auth.entity.RefreshToken; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface RefreshTokenRepository { | ||
|
|
||
| void save(RefreshToken refreshToken); | ||
| @Repository | ||
| public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long> { | ||
|
|
||
| Optional<RefreshToken> findByToken(String token); | ||
|
|
||
| Optional<RefreshToken> findByMemberId(Long memberId); | ||
|
|
||
| void deleteByMemberId(Long memberId); | ||
|
|
||
| void flush(); | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package roomescape.reservation.exception; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import roomescape.exception.ErrorCode; | ||
|
|
||
| public enum ReservationErrorCode implements ErrorCode { | ||
|
|
||
| DUPLICATE_RESERVATION(HttpStatus.CONFLICT, "해당 시간에 이미 예약이 존재합니다."); | ||
|
|
||
| private HttpStatus httpStatus; | ||
| private String message; | ||
|
|
||
| ReservationErrorCode(HttpStatus httpStatus, String message) { | ||
| this.httpStatus = httpStatus; | ||
| this.message = message; | ||
| } | ||
|
|
||
| @Override | ||
| public HttpStatus getHttpStatus() { | ||
| return httpStatus; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,37 @@ | ||
| package roomescape.reservation.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.stereotype.Repository; | ||
| import roomescape.reservation.entity.Reservation; | ||
| import roomescape.theme.entity.Theme; | ||
| import roomescape.time.entity.Time; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| public interface ReservationRepository { | ||
| @Repository | ||
| public interface ReservationRepository extends JpaRepository<Reservation, Long> { | ||
|
|
||
| @Override | ||
| @Query("SELECT r FROM reservation r " + | ||
| "JOIN FETCH r.member " + | ||
| "JOIN FETCH r.time " + | ||
| "JOIN FETCH r.theme") | ||
| List<Reservation> findAll(); | ||
|
|
||
| List<Reservation> findAllByMemberId(Long memberId); | ||
| @Query("SELECT r FROM reservation r " + | ||
| "JOIN FETCH r.time " + | ||
| "JOIN FETCH r.theme " + | ||
| "WHERE r.member.id = :memberId") | ||
| List<Reservation> findAllByMemberId(@Param("memberId") Long memberId); | ||
|
|
||
| List<Reservation> findByDateAndThemeId(LocalDate date, Long themeId); | ||
|
|
||
| Reservation save(Reservation reservation); | ||
|
|
||
| void deleteById(Long id); | ||
| boolean existsByDateAndTimeAndTheme( | ||
| @Param("date") LocalDate date, | ||
| @Param("time") Time time, | ||
| @Param("theme") Theme theme | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import roomescape.reservation.dto.ReservationRequest; | ||
| import roomescape.reservation.dto.ReservationResponse; | ||
| import roomescape.reservation.entity.Reservation; | ||
| import roomescape.reservation.exception.ReservationErrorCode; | ||
| import roomescape.reservation.repository.ReservationRepository; | ||
| import roomescape.theme.entity.Theme; | ||
| import roomescape.theme.repository.ThemeRepository; | ||
|
|
@@ -23,6 +24,7 @@ | |
| @Service | ||
| @Transactional(readOnly = true) | ||
| public class ReservationService { | ||
|
|
||
| private final ReservationRepository reservationRepository; | ||
| private final MemberRepository memberRepository; | ||
| private final TimeRepository timeRepository; | ||
|
|
@@ -37,12 +39,14 @@ public ReservationService(ReservationRepository reservationRepository, MemberRep | |
|
|
||
| @Transactional | ||
| public ReservationResponse create(ReservationRequest request, LoginMember loginMember) { | ||
| Member member = resolveMember(request, loginMember); | ||
| LocalDate date = LocalDate.parse(request.getDate()); | ||
| Time time = timeRepository.findById(request.getTime()) | ||
| .orElseThrow(); | ||
| Theme theme = themeRepository.findById(request.getTheme()) | ||
| .orElseThrow(); | ||
| validateDuplicateReservation(date, time, theme); | ||
|
|
||
| Member member = resolveMember(request, loginMember); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolveName 대신 더 나은 네이밍으로 지을 수 있어보여요~
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 메서드의 역할이 원하는 멤버의 이름을 받아오는 것이기 때문에 [반영 커밋] - 6eaf8f3 |
||
|
|
||
| Reservation reservation = new Reservation(member, date, time, theme); | ||
| Reservation savedReservation = reservationRepository.save(reservation); | ||
|
|
@@ -95,4 +99,10 @@ private Member resolveMember(ReservationRequest reservationRequest, LoginMember | |
| return memberRepository.findById(loginMember.id()) | ||
| .orElseThrow(() -> new ApplicationException(MemberErrorCode.MEMBER_NOT_FOUND)); | ||
| } | ||
|
|
||
| private void validateDuplicateReservation(LocalDate date, Time time, Theme theme) { | ||
| if (reservationRepository.existsByDateAndTimeAndTheme(date, time, theme)) { | ||
| throw new ApplicationException(ReservationErrorCode.DUPLICATE_RESERVATION); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,10 @@ public Theme(String name, String description) { | |
| this.description = description; | ||
| } | ||
|
|
||
| public void markDeleted() { | ||
| this.deleted = true; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time, Theme처럼 Soft Delete가 필요한 엔티티마다 [반영 커밋] - f2fd69f There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hard Delete, Soft Delete 사용한 근거까지 좋네요 👍 이런 내용들이 코딩하기 전에 설계할 때 중요하더라구요
이거는 본인이 과거에 데이터 삭제한걸 깜빡하고 문의주시는 사용자가 생각보다 있어서 유용했어요 ㅋㅋ.. |
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
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.
시간이 좀 있으면 JpaRepository 내부 구현체가 대략적으로 어떤 클래스로 나뉘고 각각 어떤 역할을 하는지 찾아보시면 좋아보여요~
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.
넵! 한 번 따로 공부해보겠습니다!!