Skip to content

Commit

Permalink
Merge pull request #52 from pyro-yolog/feat/#51-feat-trip-detail
Browse files Browse the repository at this point in the history
Feat/#51 일기장 개별 조회 구현
  • Loading branch information
yeonjy authored Jul 12, 2024
2 parents 1b91677 + 82d979c commit 02b9a2b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public class InquiryAnswerNotAdminMemberException extends BusinessException {
public InquiryAnswerNotAdminMemberException() {
super(ErrorCode.INQUIRY_NOT_ADMIN_MEMBER);
super(ErrorCode.INQUIRY_NOT_ADMIN_MEMBER_ERROR);
}
}
24 changes: 22 additions & 2 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 @@ -41,7 +42,7 @@ public interface TripApi {
)
})
void updateTrip(
@Parameter(in = ParameterIn.QUERY, description = "일기장 ID", required = true)
@Parameter(in = ParameterIn.PATH, description = "일기장 ID", required = true)
Long id,

@RequestBody TripRequest request
Expand All @@ -59,7 +60,7 @@ void updateTrip(
)
})
void deleteTrip(
@Parameter(in = ParameterIn.QUERY, description = "일기장 ID", required = true)
@Parameter(in = ParameterIn.PATH, description = "일기장 ID", required = true)
Long id
);

Expand All @@ -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.PATH, 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(@PathVariable 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));
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/pyro/yolog/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public enum ErrorCode {

// INQUIRY
INQUIRY_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 문의를 찾지 못했습니다."),
INQUIRY_NOT_ADMIN_MEMBER(HttpStatus.BAD_REQUEST, "문의하기 답변은 관리자만 가능합니다."),
INQUIRY_NOT_ADMIN_MEMBER_ERROR(HttpStatus.BAD_REQUEST, "문의하기 답변은 관리자만 가능합니다."),

// TRIP
TRIP_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 일기장을 찾지 못했습니다."),
REQUEST_COLOR_COVER_INVALID_ERROR(HttpStatus.BAD_REQUEST, "올바른 색상 코드를 입력해야 합니다."),

//DIARY
Expand Down

0 comments on commit 02b9a2b

Please sign in to comment.