Skip to content

Commit

Permalink
feat: Trip 개별 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed Jul 12, 2024
1 parent 03b2906 commit 2f520e0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/pyro/yolog/domain/trip/api/TripApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pyro.yolog.domain.trip.dto.TripRequest;
import com.pyro.yolog.domain.trip.dto.TripResponse;
import com.pyro.yolog.domain.trip.entity.Trip;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand Down Expand Up @@ -78,4 +79,23 @@ void deleteTrip(
)
List<TripResponse> getTrips();

@Operation(
summary = "일기장 상세 조회",
description = "일기장을 상세 조회합니다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "OK"
)
}
)
TripResponse getTrip(
@Parameter(in = ParameterIn.QUERY, description = "일기장 ID", required = true)
Long id
);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.pyro.yolog.domain.trip.dto.TripRequest;
import com.pyro.yolog.domain.trip.dto.TripResponse;
import com.pyro.yolog.domain.trip.entity.Trip;
import com.pyro.yolog.domain.trip.service.TripService;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -44,5 +46,10 @@ public List<TripResponse> getTrips() {
return tripService.getTrips();
}


@ResponseStatus(HttpStatus.OK)
@GetMapping("/{id}")
@Override
public TripResponse getTrip(@Parameter Long id) {
return tripService.getTripDetail(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pyro.yolog.domain.trip.exception;

import com.pyro.yolog.global.error.ErrorCode;
import com.pyro.yolog.global.error.exception.BusinessException;

public class TripNotFoundException extends BusinessException {
public TripNotFoundException() {
super(ErrorCode.TRIP_NOT_FOUND_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.pyro.yolog.domain.trip.entity.Trip;
import com.pyro.yolog.domain.trip.mapper.TripMapper;
import com.pyro.yolog.domain.trip.repository.TripRepository;
import jakarta.persistence.EntityNotFoundException;
import com.pyro.yolog.domain.trip.exception.TripNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -32,7 +32,7 @@ public void saveTrip(final TripRequest request) {

@Transactional
public void updateTrip(final Long id, final TripRequest request) {
final Trip trip = tripRepository.findById(id).orElseThrow(EntityNotFoundException::new);
final Trip trip = tripRepository.findById(id).orElseThrow(TripNotFoundException::new);
trip.update(request);
diaryService.deleteOutOfDuration(trip);
}
Expand All @@ -43,12 +43,16 @@ public void deleteTrip(Long id) {
}

public Trip getTrip(final Long id) {
return tripRepository.findById(id).orElseThrow(EntityNotFoundException::new);
return tripRepository.findById(id).orElseThrow(TripNotFoundException::new);
}

public List<TripResponse> getTrips() {
Member login = authService.getLoginUser();
return tripRepository.findAllByMember(login).stream()
.map(TripResponse::new).collect(Collectors.toList());
}

public TripResponse getTripDetail(Long id) {
return new TripResponse(getTrip(id));
}
}

0 comments on commit 2f520e0

Please sign in to comment.