Skip to content

Commit

Permalink
refactor: DTO 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
linirini committed Jul 24, 2024
1 parent 0a795ec commit 84c3cd4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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.TravelDetailResponses;
import com.staccato.travel.service.dto.response.TravelResponses;

import lombok.RequiredArgsConstructor;

Expand All @@ -32,7 +32,7 @@ public ResponseEntity<Void> createTravel(@Valid @RequestBody TravelRequest trave
}

@GetMapping
public ResponseEntity<TravelDetailResponses> readAllTravels(
public ResponseEntity<TravelResponses> readAllTravels(
@MemberId Long memberId,
@RequestParam(value = "year", required = false) Integer year) {
return ResponseEntity.ok(travelService.readAllTravels(memberId, year));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.staccato.travel.repository.TravelMemberRepository;
import com.staccato.travel.repository.TravelRepository;
import com.staccato.travel.service.dto.request.TravelRequest;
import com.staccato.travel.service.dto.response.TravelDetailResponses;
import com.staccato.travel.service.dto.response.TravelResponses;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -46,26 +46,26 @@ private Member getMemberById(long memberId) {
.orElseThrow(() -> new IllegalArgumentException("Invalid Operation"));
}

public TravelDetailResponses readAllTravels(long memberId, Integer year) {
public TravelResponses readAllTravels(long memberId, Integer year) {
return Optional.ofNullable(year)
.map(y -> readAllByYear(memberId, y))
.orElseGet(() -> readAll(memberId));
}

private TravelDetailResponses readAll(long memberId) {
private TravelResponses readAll(long memberId) {
List<TravelMember> travelMembers = travelMemberRepository.findAllByMemberId(memberId);
return getTravelDetailResponses(travelMembers);
}

private TravelDetailResponses readAllByYear(long memberId, Integer year) {
private TravelResponses readAllByYear(long memberId, Integer year) {
List<TravelMember> travelMembers = travelMemberRepository.findAllByMemberIdAndTravelStartAtYear(memberId, year);
return getTravelDetailResponses(travelMembers);
}

private TravelDetailResponses getTravelDetailResponses(List<TravelMember> travelMembers) {
private TravelResponses getTravelDetailResponses(List<TravelMember> travelMembers) {
List<Travel> travels = travelMembers.stream()
.map(TravelMember::getTravel)
.toList();
return TravelDetailResponses.from(travels);
return TravelResponses.from(travels);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.staccato.member.service.dto.response.MemberResponses;
import com.staccato.travel.domain.Travel;

public record TravelDetailResponse(
public record TravelResponse(
Long travelId,
String travelThumbnail,
String travelTitle,
Expand All @@ -14,7 +14,7 @@ public record TravelDetailResponse(
LocalDate endAt,
MemberResponses mates
) {
public TravelDetailResponse(Travel travel) {
public TravelResponse(Travel travel) {
this(
travel.getId(),
travel.getThumbnailUrl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.staccato.travel.service.dto.response;

import java.util.List;

import com.staccato.travel.domain.Travel;

public record TravelResponses(
List<TravelResponse> travels
) {
public static TravelResponses from(List<Travel> travels) {
return new TravelResponses(travels.stream()
.map(TravelResponse::new)
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.staccato.travel.domain.TravelMember;
import com.staccato.travel.repository.TravelMemberRepository;
import com.staccato.travel.service.dto.request.TravelRequest;
import com.staccato.travel.service.dto.response.TravelDetailResponses;
import com.staccato.travel.service.dto.response.TravelResponses;

class TravelServiceTest extends ServiceSliceTest {
@Autowired
Expand All @@ -45,12 +45,12 @@ void createTravel() {

// when
long travelId = travelService.createTravel(travelRequest, member.getId());
TravelMember travelMember = travelMemberRepostiory.findAll().get(0);
TravelMember travelMember = travelMemberRepository.findAll().get(0);

// then
assertAll(
() -> Assertions.assertThat(travelMember.getMember().getId()).isEqualTo(member.getId()),
() -> Assertions.assertThat(travelMember.getTravel().getId()).isEqualTo(travelId)
() -> assertThat(travelMember.getMember().getId()).isEqualTo(member.getId()),
() -> assertThat(travelMember.getTravel().getId()).isEqualTo(travelId)
);
}

Expand All @@ -64,10 +64,10 @@ void readAllTravels(Integer year, int expectedSize) {
travelService.createTravel(createTravelRequest(2024), member.getId());

// when
TravelDetailResponses travelDetailResponses = travelService.readAllTravels(member.getId(), year);
TravelResponses travelResponses = travelService.readAllTravels(member.getId(), year);

// then
assertThat(travelDetailResponses.travels()).hasSize(expectedSize);
assertThat(travelResponses.travels()).hasSize(expectedSize);
}

private static TravelRequest createTravelRequest(int year) {
Expand Down

0 comments on commit 84c3cd4

Please sign in to comment.