diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/TripRecordRepository.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/TripRecordRepository.java new file mode 100644 index 00000000..61051e67 --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/TripRecordRepository.java @@ -0,0 +1,8 @@ +package com.haejwo.tripcometrue.domain.triprecord.repository; + +import com.haejwo.tripcometrue.domain.triprecord.entity.TripRecord; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TripRecordRepository extends JpaRepository { + +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/service/TripRecordService.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/service/TripRecordService.java new file mode 100644 index 00000000..b91a8904 --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/service/TripRecordService.java @@ -0,0 +1,58 @@ +package com.haejwo.tripcometrue.domain.triprecord.service; + +import com.haejwo.tripcometrue.domain.triprecord.dto.request.TripRecordRequestDto; +import com.haejwo.tripcometrue.domain.triprecord.dto.response.TripRecordResponseDto; +import com.haejwo.tripcometrue.domain.triprecord.entity.TripRecord; +import com.haejwo.tripcometrue.domain.triprecord.repository.TripRecordRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class TripRecordService { + + private final TripRecordRepository tripRecordRepository; + + @Transactional + public TripRecordResponseDto addTripRecord(TripRecordRequestDto requestDto) { + + TripRecord requestTripRecord = requestDto.toEntity(); + TripRecord savedTripRecord = tripRecordRepository.save(requestTripRecord); + TripRecordResponseDto responseDto = TripRecordResponseDto.fromEntity(savedTripRecord); + + return responseDto; + } + + @Transactional(readOnly = true) + public TripRecordResponseDto findTripRecord(Long tripRecordId) { + + TripRecord findTripRecord = findTripRecordById(tripRecordId); + TripRecordResponseDto responseDto = TripRecordResponseDto.fromEntity(findTripRecord); + + return responseDto; + } + + @Transactional + public TripRecordResponseDto modifyTripRecord(Long tripRecordId, TripRecordRequestDto requestDto) { + + TripRecord findTripRecord = findTripRecordById(tripRecordId); + findTripRecord.update(requestDto); + TripRecordResponseDto responseDto = TripRecordResponseDto.fromEntity(findTripRecord); + + return responseDto; + } + + public void removeTripRecord(Long tripRecordId) { + TripRecord findTripRecord = findTripRecordById(tripRecordId); + tripRecordRepository.delete(findTripRecord); + } + + private TripRecord findTripRecordById(Long tripRecordId) { + TripRecord findTripRecord = tripRecordRepository.findById(tripRecordId) + .orElseThrow(); // TODO: 여행후기 조회 예외 추가 + return findTripRecord; + } + + +}