diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java b/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java index 1f963443..73c602a8 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java @@ -1,7 +1,7 @@ package com.haejwo.tripcometrue.domain.place.controller; -import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDTO; -import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDTO; +import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDto; import com.haejwo.tripcometrue.domain.place.service.PlaceService; import com.haejwo.tripcometrue.global.util.ResponseDTO; import lombok.RequiredArgsConstructor; @@ -26,12 +26,12 @@ public class PlaceController { private final PlaceService placeService; @PostMapping - public ResponseEntity> placeAdd( - @RequestBody PlaceRequestDTO requestDto + public ResponseEntity> placeAdd( + @RequestBody PlaceRequestDto requestDto ) { - PlaceResponseDTO responseDto = placeService.addPlace(requestDto); - ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + PlaceResponseDto responseDto = placeService.addPlace(requestDto); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); return ResponseEntity .status(responseBody.getCode()) @@ -39,12 +39,12 @@ public ResponseEntity> placeAdd( } @GetMapping("/{placeId}") - public ResponseEntity> placeDetails( + public ResponseEntity> placeDetails( @PathVariable Long placeId ) { - PlaceResponseDTO responseDto = placeService.findPlace(placeId); - ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + PlaceResponseDto responseDto = placeService.findPlace(placeId); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); return ResponseEntity .status(responseBody.getCode()) @@ -52,12 +52,12 @@ public ResponseEntity> placeDetails( } @GetMapping - public ResponseEntity>> placeList( + public ResponseEntity>> placeList( Pageable pageable, @RequestParam Integer storedCount ) { - Page placePage = placeService.findPlaces(pageable, storedCount); + Page placePage = placeService.findPlaces(pageable, storedCount); ResponseDTO responseBody = ResponseDTO.okWithData(placePage); @@ -67,13 +67,13 @@ public ResponseEntity>> placeList( } @PutMapping("/{placeId}") - public ResponseEntity> placeModify( + public ResponseEntity> placeModify( @PathVariable Long placeId, - @RequestBody PlaceRequestDTO requestDto + @RequestBody PlaceRequestDto requestDto ) { - PlaceResponseDTO responseDto = placeService.modifyPlace(placeId, requestDto); - ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + PlaceResponseDto responseDto = placeService.modifyPlace(placeId, requestDto); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); return ResponseEntity .status(responseBody.getCode()) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDTO.java b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDto.java similarity index 81% rename from src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDTO.java rename to src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDto.java index d8bd5f1c..adbafccf 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDTO.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDto.java @@ -1,12 +1,12 @@ package com.haejwo.tripcometrue.domain.place.dto.request; -public record PlaceFilterRequestDTO( +public record PlaceFilterRequestDto( Integer stored_count, Integer storedCount ) { // record는 Compact Constructor라는 기능있어, 생성자 내부의 변수에 대한 로직이 마지막으로 동작하여 변수 초기화를 한다. - public PlaceFilterRequestDTO { + public PlaceFilterRequestDto { storedCount = stored_count; } diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDTO.java b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDto.java similarity index 96% rename from src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDTO.java rename to src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDto.java index 38b7b89b..32fefb63 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDTO.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceRequestDto.java @@ -5,7 +5,7 @@ import java.time.LocalTime; import lombok.Builder; -public record PlaceRequestDTO( +public record PlaceRequestDto( String name, String address, String description, @@ -18,7 +18,7 @@ public record PlaceRequestDTO( ) { @Builder - public PlaceRequestDTO( + public PlaceRequestDto( String name, String address, String description, diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDTO.java b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java similarity index 92% rename from src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDTO.java rename to src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java index c631e866..7a9b41a5 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDTO.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java @@ -4,7 +4,7 @@ import com.haejwo.tripcometrue.domain.place.entity.Place; import java.time.LocalTime; import lombok.Builder; -public record PlaceResponseDTO( +public record PlaceResponseDto( Long id, String name, String address, @@ -18,7 +18,7 @@ public record PlaceResponseDTO( ) { @Builder - public PlaceResponseDTO( + public PlaceResponseDto( Long id, String name, String address, @@ -42,8 +42,8 @@ public PlaceResponseDTO( this.cityId = cityId; } - public static PlaceResponseDTO fromEntity(Place entity) { - return PlaceResponseDTO.builder() + public static PlaceResponseDto fromEntity(Place entity) { + return PlaceResponseDto.builder() .id(entity.getId()) .name(entity.getName()) .address(entity.getAddress()) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java b/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java index 20deb3dc..231f4d18 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java @@ -1,6 +1,6 @@ package com.haejwo.tripcometrue.domain.place.entity; -import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDTO; +import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDto; import com.haejwo.tripcometrue.global.entity.BaseTimeEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -60,7 +60,7 @@ public Place( this.cityId = cityId; } - public void update(PlaceRequestDTO requestDto) { + public void update(PlaceRequestDto requestDto) { this.name = requestDto.name(); this.address = requestDto.address(); this.description = requestDto.description(); diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java b/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java index 528ee1cd..fb5f992a 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java @@ -1,7 +1,7 @@ package com.haejwo.tripcometrue.domain.place.service; -import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDTO; -import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDTO; +import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDto; import com.haejwo.tripcometrue.domain.place.entity.Place; import com.haejwo.tripcometrue.domain.place.exception.PlaceNotFoundException; import com.haejwo.tripcometrue.domain.place.repositroy.PlaceRepository; @@ -20,45 +20,43 @@ public class PlaceService { private final PlaceRepository placeRepository; @Transactional - public PlaceResponseDTO addPlace(PlaceRequestDTO requestDto) { + public PlaceResponseDto addPlace(PlaceRequestDto requestDto) { - System.out.println(requestDto.storedCount()); Place requestPlace = requestDto.toEntity(); Place savedPlace = placeRepository.save(requestPlace); - System.out.println(savedPlace.getStoredCount()); - PlaceResponseDTO responseDto = PlaceResponseDTO.fromEntity(savedPlace); + PlaceResponseDto responseDto = PlaceResponseDto.fromEntity(savedPlace); return responseDto; } @Transactional(readOnly = true) - public PlaceResponseDTO findPlace(Long placeId) { + public PlaceResponseDto findPlace(Long placeId) { Place findPlace = findPlaceById(placeId); - PlaceResponseDTO responseDto = PlaceResponseDTO.fromEntity(findPlace); + PlaceResponseDto responseDto = PlaceResponseDto.fromEntity(findPlace); return responseDto; } @Transactional(readOnly = true) - public Page findPlaces(Pageable pageable, Integer storedCount) { + public Page findPlaces(Pageable pageable, Integer storedCount) { Page findPlaces = placeRepository.findPlaceWithFilter(pageable, storedCount); - Page result = findPlaces.map(PlaceResponseDTO::fromEntity); + Page result = findPlaces.map(PlaceResponseDto::fromEntity); return result; } @Transactional - public PlaceResponseDTO modifyPlace(Long placeId, PlaceRequestDTO requestDto) { + public PlaceResponseDto modifyPlace(Long placeId, PlaceRequestDto requestDto) { Place place = findPlaceById(placeId); place.update(requestDto); - PlaceResponseDTO responseDto = PlaceResponseDTO.fromEntity(place); + PlaceResponseDto responseDto = PlaceResponseDto.fromEntity(place); return responseDto; } diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/controller/TripRecordController.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/controller/TripRecordController.java new file mode 100644 index 00000000..455392bb --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/controller/TripRecordController.java @@ -0,0 +1,83 @@ +package com.haejwo.tripcometrue.domain.triprecord.controller; + +import com.haejwo.tripcometrue.domain.triprecord.dto.request.TripRecordRequestDto; +import com.haejwo.tripcometrue.domain.triprecord.dto.response.TripRecordResponseDto; +import com.haejwo.tripcometrue.domain.triprecord.service.TripRecordService; +import com.haejwo.tripcometrue.global.util.ResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/v1/trip-record") +@RequiredArgsConstructor +public class TripRecordController { + + private final TripRecordService tripRecordService; + + @PostMapping + public ResponseEntity> tripRecordAdd( + @RequestBody TripRecordRequestDto requestDto + ) { + + TripRecordResponseDto responseDto = tripRecordService.addTripRecord(requestDto); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + + return ResponseEntity + .status(responseBody.getCode()) + .body(responseBody); + } + + @GetMapping("/{tripRecordId}") + public ResponseEntity> tripRecordDetails( + @PathVariable Long tripRecordId + ) { + + TripRecordResponseDto responseDto = tripRecordService.findTripRecord(tripRecordId); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + + return ResponseEntity + .status(responseBody.getCode()) + .body(responseBody); + } + + @PutMapping("/{tripRecordId}") + public ResponseEntity> tripRecordModify( + @PathVariable Long tripRecordId, + @RequestBody TripRecordRequestDto requestDto + ) { + + TripRecordResponseDto responseDto = tripRecordService.modifyTripRecord(tripRecordId, requestDto); + ResponseDTO responseBody = ResponseDTO.okWithData(responseDto); + + return ResponseEntity + .status(responseBody.getCode()) + .body(responseBody); + + } + + @DeleteMapping("/{tripRecordId}") + public ResponseEntity tripRecordRemove( + @PathVariable Long tripRecordId + ) { + + tripRecordService.removeTripRecord(tripRecordId); + ResponseDTO responseBody = ResponseDTO.ok(); + + return ResponseEntity + .status(responseBody.getCode()) + .body(responseBody); + } + + + + + +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/request/TripRecordRequestDto.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/request/TripRecordRequestDto.java new file mode 100644 index 00000000..61eeabf7 --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/request/TripRecordRequestDto.java @@ -0,0 +1,40 @@ +package com.haejwo.tripcometrue.domain.triprecord.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.haejwo.tripcometrue.domain.triprecord.entity.ExpenseRangeType; +import com.haejwo.tripcometrue.domain.triprecord.entity.TripRecord; +import java.time.LocalDate; +import lombok.Builder; + +public record TripRecordRequestDto( + String title, + String content, + ExpenseRangeType expenseRangeType, + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripStartDay, + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripEndDay, + String countries +) { + + @Builder + public TripRecordRequestDto(String title, String content, ExpenseRangeType expenseRangeType, + LocalDate tripStartDay, LocalDate tripEndDay, String countries) { + this.title = title; + this.content = content; + this.expenseRangeType = expenseRangeType; + this.tripStartDay = tripStartDay; + this.tripEndDay = tripEndDay; + this.countries = countries; + } + + public TripRecord toEntity() { + return TripRecord.builder() + .title(this.title) + .content(this.content) + .expenseRangeType(this.expenseRangeType) + .tripStartDay(this.tripStartDay) + .tripEndDay(this.tripEndDay) + .countries(this.countries) + .build(); + } + +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/TripRecordResponseDto.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/TripRecordResponseDto.java new file mode 100644 index 00000000..7467820e --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/TripRecordResponseDto.java @@ -0,0 +1,56 @@ +package com.haejwo.tripcometrue.domain.triprecord.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.haejwo.tripcometrue.domain.triprecord.entity.ExpenseRangeType; +import com.haejwo.tripcometrue.domain.triprecord.entity.TripRecord; +import java.time.LocalDate; +import lombok.Builder; + +public record TripRecordResponseDto( + Long id, + String title, + String content, + Integer average_rating, + ExpenseRangeType expenseRangeType, + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripStartDay, + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripEndDay, + Integer totalDays, + String countries, + Integer viewCount + +) { + + @Builder + public TripRecordResponseDto(Long id, String title, String content, Integer average_rating, + ExpenseRangeType expenseRangeType, LocalDate tripStartDay, LocalDate tripEndDay, Integer totalDays, + String countries, Integer viewCount) { + this.id = id; + this.title = title; + this.content = content; + this.average_rating = average_rating; + this.expenseRangeType = expenseRangeType; + this.tripStartDay = tripStartDay; + this.tripEndDay = tripEndDay; + this.totalDays = totalDays; + this.countries = countries; + this.viewCount = viewCount; + } + + + public static TripRecordResponseDto fromEntity(TripRecord entity) { + return TripRecordResponseDto.builder() + .id(entity.getId()) + .title(entity.getTitle()) + .content(entity.getContent()) + .average_rating(entity.getAverageRating()) + .expenseRangeType(entity.getExpenseRangeType()) + .tripStartDay(entity.getTripStartDay()) + .tripEndDay(entity.getTripEndDay()) + .totalDays(entity.getTotalDays()) + .countries(entity.getCountries()) + .viewCount(entity.getViewCount()) + .build(); + + } + +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/ExpenseRangeType.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/ExpenseRangeType.java new file mode 100644 index 00000000..20f9da53 --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/ExpenseRangeType.java @@ -0,0 +1,26 @@ +package com.haejwo.tripcometrue.domain.triprecord.entity; + +import java.util.stream.Stream; + +public enum ExpenseRangeType { + + BELOW_50(50), + BELOW_100(100), + BELOW_200(200), + BELOW_300(300), + ABOVE_300(Integer.MAX_VALUE); + + private final int max; + + ExpenseRangeType(int max) { + this.max = max; + } + + public static ExpenseRangeType findByMax(int max) { + return Stream.of(ExpenseRangeType.values()) + .filter(p -> p.max == max) + .findFirst() + .orElseThrow(); // TODO: ExpenseType 예외 추가 + } + +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecord.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecord.java new file mode 100644 index 00000000..3d2a88cc --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecord.java @@ -0,0 +1,97 @@ +package com.haejwo.tripcometrue.domain.triprecord.entity; + +import com.haejwo.tripcometrue.domain.triprecord.dto.request.TripRecordRequestDto; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class TripRecord { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "trip_record_id") + private Long id; + + @Column(nullable = false) + private String title; + private String content; + + @Enumerated(EnumType.STRING) + private ExpenseRangeType expenseRangeType; + + private String countries; + + private LocalDate tripStartDay; + private LocalDate tripEndDay; + + private Integer totalDays; + private Integer averageRating; + private Integer viewCount; + + + @OneToMany(mappedBy = "tripRecord", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + private List tripRecordSchedules =new ArrayList<>(); + + @Builder + public TripRecord(Long id, String title, String content, Integer averageRating, + ExpenseRangeType expenseRangeType, LocalDate tripStartDay, LocalDate tripEndDay, Integer totalDays, + String countries, Integer viewCount) { + this.id = id; + this.title = title; + this.content = content; + this.averageRating = averageRating; + this.expenseRangeType = expenseRangeType; + this.tripStartDay = tripStartDay; + this.tripEndDay = tripEndDay; + this.totalDays = totalDays; + this.countries = countries; + this.viewCount = viewCount; + } + + // TODO: update 함수 + public void update(TripRecordRequestDto requestDto) { + this.title = requestDto.title(); + this.content = requestDto.content(); + this.expenseRangeType = requestDto.expenseRangeType(); + this.tripStartDay = requestDto.tripStartDay(); + this.tripEndDay = requestDto.tripEndDay(); + this.countries = requestDto.countries(); + } + + @PrePersist + public void prePersist() { + this.totalDays = calculateTotalDays(); + } + + @PreUpdate + public void preUpdate() { + this.totalDays = calculateTotalDays(); + } + + private int calculateTotalDays() { + if (this.tripStartDay == null || this.tripEndDay == null) { + return 0; + } + return (int) ChronoUnit.DAYS.between(this.tripStartDay, this.tripEndDay); + } +} diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecordSchedule.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecordSchedule.java new file mode 100644 index 00000000..5cd4c972 --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/entity/TripRecordSchedule.java @@ -0,0 +1,45 @@ +package com.haejwo.tripcometrue.domain.triprecord.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class TripRecordSchedule { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "trip_record_schedule_id") + private Long id; + + @Column(nullable = false) + private Integer dayNumber; + + @Column(nullable = false) + private Integer ordering; + + private String content; + + @ManyToOne + @JoinColumn(name = "tripRecord_id") + private TripRecord tripRecord; + + @Builder + public TripRecordSchedule(Long id, Integer dayNumber, Integer ordering, String content) { + this.id = id; + this.dayNumber = dayNumber; + this.ordering = ordering; + this.content = content; + } + + +} 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; + } + + +} diff --git a/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java b/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java index c97d87bd..19a863f5 100644 --- a/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java +++ b/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java @@ -70,6 +70,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, .requestMatchers(new AntPathRequestMatcher("/v1/member/check-duplicated-email")).permitAll() .requestMatchers(new AntPathRequestMatcher("/v1/places/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/v1/trip-record/**")).permitAll() .anyRequest().authenticated()); http.exceptionHandling(exceptionHandling -> {