Skip to content

Commit

Permalink
refactor: 여행 상세 생성 서비스 반환 타입 변경 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
linirini authored Jul 24, 2024
1 parent 7ed6b8e commit ab75f64
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
4 changes: 0 additions & 4 deletions backend/src/main/java/com/staccato/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +24,7 @@ public class TravelController {

@PostMapping
public ResponseEntity<Void> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
);
}
}

0 comments on commit ab75f64

Please sign in to comment.