-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 여행후기(trip_record) service, repository 구현
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/TripRecordRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TripRecord, Long> { | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/haejwo/tripcometrue/domain/triprecord/service/TripRecordService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
|
||
} |