From ab75f649b941920313671f056ec14f3607aac053 Mon Sep 17 00:00:00 2001 From: linirini <101927543+linirini@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:58:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=97=AC=ED=96=89=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=83=9D=EC=84=B1=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/staccato/member/domain/Member.java | 4 ---- .../travel/controller/TravelController.java | 5 ++-- .../travel/service/TravelService.java | 5 ++-- .../service/dto/response/TravelResponse.java | 24 ------------------- .../travel/service/TravelServiceTest.java | 5 ++-- 5 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 backend/src/main/java/com/staccato/travel/service/dto/response/TravelResponse.java diff --git a/backend/src/main/java/com/staccato/member/domain/Member.java b/backend/src/main/java/com/staccato/member/domain/Member.java index 07cf5d35d..845ed0965 100644 --- a/backend/src/main/java/com/staccato/member/domain/Member.java +++ b/backend/src/main/java/com/staccato/member/domain/Member.java @@ -1,18 +1,14 @@ package com.staccato.member.domain; -import java.util.List; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; import org.hibernate.annotations.SQLDelete; import com.staccato.config.domain.BaseEntity; -import com.staccato.travel.domain.TravelMember; import lombok.AccessLevel; import lombok.Builder; diff --git a/backend/src/main/java/com/staccato/travel/controller/TravelController.java b/backend/src/main/java/com/staccato/travel/controller/TravelController.java index 2bf37f80e..577df80aa 100644 --- a/backend/src/main/java/com/staccato/travel/controller/TravelController.java +++ b/backend/src/main/java/com/staccato/travel/controller/TravelController.java @@ -13,7 +13,6 @@ import com.staccato.config.auth.MemberId; import com.staccato.travel.service.TravelService; import com.staccato.travel.service.dto.request.TravelRequest; -import com.staccato.travel.service.dto.response.TravelResponse; import lombok.RequiredArgsConstructor; @@ -25,7 +24,7 @@ public class TravelController { @PostMapping public ResponseEntity createTravel(@Valid @RequestBody TravelRequest travelRequest, @MemberId Long memberId) { - TravelResponse travelResponse = travelService.createTravel(travelRequest, memberId); - return ResponseEntity.created(URI.create("/travels/" + travelResponse.travelId())).build(); + long travelId = travelService.createTravel(travelRequest, memberId); + return ResponseEntity.created(URI.create("/travels/" + travelId)).build(); } } diff --git a/backend/src/main/java/com/staccato/travel/service/TravelService.java b/backend/src/main/java/com/staccato/travel/service/TravelService.java index b570942f5..ac762ed90 100644 --- a/backend/src/main/java/com/staccato/travel/service/TravelService.java +++ b/backend/src/main/java/com/staccato/travel/service/TravelService.java @@ -10,7 +10,6 @@ import com.staccato.travel.repository.TravelMemberRepostiory; import com.staccato.travel.repository.TravelRepository; import com.staccato.travel.service.dto.request.TravelRequest; -import com.staccato.travel.service.dto.response.TravelResponse; import lombok.RequiredArgsConstructor; @@ -23,10 +22,10 @@ public class TravelService { private final MemberRepository memberRepository; @Transactional - public TravelResponse createTravel(TravelRequest travelRequest, Long memberId) { + public long createTravel(TravelRequest travelRequest, Long memberId) { Travel travel = travelRepository.save(travelRequest.toTravel()); saveTravelMember(memberId, travel); - return new TravelResponse(travel); + return travel.getId(); } private TravelMember saveTravelMember(Long memberId, Travel travel) { diff --git a/backend/src/main/java/com/staccato/travel/service/dto/response/TravelResponse.java b/backend/src/main/java/com/staccato/travel/service/dto/response/TravelResponse.java deleted file mode 100644 index 91977fb3c..000000000 --- a/backend/src/main/java/com/staccato/travel/service/dto/response/TravelResponse.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.staccato.travel.service.dto.response; - -import java.time.LocalDate; - -import com.staccato.travel.domain.Travel; - -public record TravelResponse( - Long travelId, - String travelThumbnail, - String travelTitle, - String description, - LocalDate startAt, - LocalDate endAt) { - public TravelResponse(Travel travel) { - this( - travel.getId(), - travel.getThumbnailUrl(), - travel.getTitle(), - travel.getDescription(), - travel.getStartAt(), - travel.getEndAt() - ); - } -} diff --git a/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java b/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java index fb3a9d004..cdf16d399 100644 --- a/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java +++ b/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java @@ -15,7 +15,6 @@ import com.staccato.travel.domain.TravelMember; import com.staccato.travel.repository.TravelMemberRepostiory; import com.staccato.travel.service.dto.request.TravelRequest; -import com.staccato.travel.service.dto.response.TravelResponse; class TravelServiceTest extends ServiceSliceTest { @Autowired @@ -39,13 +38,13 @@ void createTravel() { Member member = memberRepository.save(Member.builder().nickname("staccato").build()); // when - TravelResponse travel = travelService.createTravel(travelRequest, member.getId()); + long travelId = travelService.createTravel(travelRequest, member.getId()); TravelMember travelMember = travelMemberRepostiory.findAll().get(0); // then assertAll( () -> Assertions.assertThat(travelMember.getMember().getId()).isEqualTo(member.getId()), - () -> Assertions.assertThat(travelMember.getTravel().getId()).isEqualTo(travel.travelId()) + () -> Assertions.assertThat(travelMember.getTravel().getId()).isEqualTo(travelId) ); } }