Skip to content

Commit

Permalink
chore: 머지 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Libienz committed Jul 18, 2024
2 parents 4b52f2c + 15f9822 commit 8e979a2
Show file tree
Hide file tree
Showing 44 changed files with 926 additions and 113 deletions.
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
runtimeOnly 'com.h2database:h2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.5.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package woowacourse.touroot.global.exception;

public class BadRequestException extends RuntimeException {

public BadRequestException(String message) {
super(message);
}
}
19 changes: 14 additions & 5 deletions backend/src/main/java/woowacourse/touroot/place/domain/Place.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package woowacourse.touroot.place.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import woowacourse.touroot.entity.BaseEntity;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
public class Place extends BaseEntity {

Expand All @@ -26,4 +27,12 @@ public class Place extends BaseEntity {
private String longitude;

private String googlePlaceId;

public Place(String name, String latitude, String longitude, String googlePlaceId) {
this(null, name, latitude, longitude, googlePlaceId);
}

public Place(String name, String latitude, String longitude) {
this(null, name, latitude, longitude, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import woowacourse.touroot.place.domain.Place;

import java.util.Optional;

public interface PlaceRepository extends JpaRepository<Place, Long> {

Optional<Place> findByNameAndLatitudeAndLongitude(String name, String lat, String lng);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package woowacourse.touroot.travelogue.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import woowacourse.touroot.travelogue.dto.TravelogueResponse;
import woowacourse.touroot.travelogue.service.TravelogueService;
import woowacourse.touroot.travelogue.service.TravelogueFacadeService;

@Tag(name = "여행기")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/travelogues")
public class TravelogueController {

private final TravelogueService travelogueService;
private final TravelogueFacadeService travelogueFacadeService;

@Operation(description = "여행기 상세 조회")
@GetMapping("/{id}")
public ResponseEntity<TravelogueResponse> findTravelogue(@PathVariable Long id) {
return ResponseEntity.ok(travelogueService.findTravelogueById(id));
public ResponseEntity<TravelogueResponse> findTravelogue(@Valid @PathVariable Long id) {
return ResponseEntity.ok(travelogueFacadeService.findTravelogueById(id));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import woowacourse.touroot.entity.BaseEntity;
import woowacourse.touroot.travelogue.day.domain.TravelogueDay;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
public class Travelogue extends BaseEntity {

Expand All @@ -25,6 +27,7 @@ public class Travelogue extends BaseEntity {
@Column(nullable = false)
private String thumbnail;

@OneToMany(mappedBy = "travelogue")
private List<TravelogueDay> travelogueDays;
public Travelogue(String title, String thumbnail) {
this(null, title, thumbnail);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.touroot.travelogue.day.domain;
package woowacourse.touroot.travelogue.domain.day.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -8,14 +8,16 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import woowacourse.touroot.entity.BaseEntity;
import woowacourse.touroot.travelogue.domain.Travelogue;
import woowacourse.touroot.travelogue.place.domain.TraveloguePlace;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
public class TravelogueDay extends BaseEntity {

Expand All @@ -30,6 +32,7 @@ public class TravelogueDay extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Travelogue travelogue;

@OneToMany(mappedBy = "travelogueDay")
private List<TraveloguePlace> traveloguePlaces;
public TravelogueDay(Integer order, Travelogue travelogue) {
this(null, order, travelogue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package woowacourse.touroot.travelogue.domain.day.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Builder;
import woowacourse.touroot.travelogue.domain.place.dto.TraveloguePlaceResponse;

@Builder
public record TravelogueDayResponse(
@Schema(description = "여행기 일자 ID", example = "1")
@NotNull(message = "ID는 비어있을 수 없습니다.")
Long id,
@Schema(description = "여행기 장소 목록")
@NotNull(message = "여행기 장소 정보는 비어있을 수 없습니다.")
List<TraveloguePlaceResponse> places
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package woowacourse.touroot.travelogue.domain.day.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import woowacourse.touroot.travelogue.domain.Travelogue;
import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay;

public interface TravelogueDayRepository extends JpaRepository<TravelogueDay, Long> {

List<TravelogueDay> findByTravelogue(Travelogue travelogue);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package woowacourse.touroot.travelogue.domain.day.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import woowacourse.touroot.global.exception.BadRequestException;
import woowacourse.touroot.travelogue.domain.Travelogue;
import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay;
import woowacourse.touroot.travelogue.domain.day.repository.TravelogueDayRepository;

@RequiredArgsConstructor
@Service
public class TravelogueDayService {

private final TravelogueDayRepository travelogueDayRepository;

@Transactional(readOnly = true)
public List<TravelogueDay> findDaysByTravelogue(Travelogue travelogue) {
return travelogueDayRepository.findByTravelogue(travelogue);
}

@Transactional(readOnly = true)
public TravelogueDay findDayById(Long id) {
return travelogueDayRepository.findById(id)
.orElseThrow(() -> new BadRequestException("존재하지 않는 여행 일자입니다."));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.touroot.travelogue.photo.domain;
package woowacourse.touroot.travelogue.domain.photo.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -8,11 +8,16 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import woowacourse.touroot.entity.BaseEntity;
import woowacourse.touroot.travelogue.place.domain.TraveloguePlace;
import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
public class TraveloguePhoto extends BaseEntity {

Expand All @@ -29,4 +34,8 @@ public class TraveloguePhoto extends BaseEntity {
@JoinColumn(nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
private TraveloguePlace traveloguePlace;

public TraveloguePhoto(String key, Integer order, TraveloguePlace traveloguePlace) {
this(null, key, order, traveloguePlace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package woowacourse.touroot.travelogue.domain.photo.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto;
import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace;

public interface TraveloguePhotoRepository extends JpaRepository<TraveloguePhoto, Long> {

List<TraveloguePhoto> findByTraveloguePlace(TraveloguePlace traveloguePlace);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package woowacourse.touroot.travelogue.domain.photo.service;

import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto;
import woowacourse.touroot.travelogue.domain.photo.repository.TraveloguePhotoRepository;
import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace;

@RequiredArgsConstructor
@Service
public class TraveloguePhotoService {

private final TraveloguePhotoRepository traveloguePhotoRepository;

public List<String> findPhotoUrlsByPlace(TraveloguePlace traveloguePlace) {
List<TraveloguePhoto> photos = traveloguePhotoRepository.findByTraveloguePlace(traveloguePlace);

return photos.stream()
.sorted(Comparator.comparing(TraveloguePhoto::getOrder))
.map(TraveloguePhoto::getKey)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.touroot.travelogue.place.domain;
package woowacourse.touroot.travelogue.domain.place.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -8,15 +8,17 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import woowacourse.touroot.entity.BaseEntity;
import woowacourse.touroot.place.domain.Place;
import woowacourse.touroot.travelogue.day.domain.TravelogueDay;
import woowacourse.touroot.travelogue.photo.domain.TraveloguePhoto;
import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
public class TraveloguePlace extends BaseEntity {

Expand All @@ -37,6 +39,19 @@ public class TraveloguePlace extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private TravelogueDay travelogueDay;

@OneToMany(mappedBy = "traveloguePlace")
private List<TraveloguePhoto> traveloguePhotos;
public TraveloguePlace(Integer order, String description, Place place, TravelogueDay travelogueDay) {
this(null, order, description, place, travelogueDay);
}

public String getName() {
return place.getName();
}

public String getLatitude() {
return place.getLatitude();
}

public String getLongitude() {
return place.getLongitude();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package woowacourse.touroot.travelogue.domain.place.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Builder;

@Builder
public record TraveloguePlaceResponse(
@Schema(description = "여행기 장소 ID", example = "1")
@NotNull(message = "ID는 비어있을 수 없습니다.")
Long id,
@Schema(description = "여행기 장소 이름", example = "선릉 캠퍼스")
@NotBlank(message = "여행기 장소 이름은 비어있을 수 없습니다.")
String name,
@Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.")
@NotBlank(message = "여행기 장소 설명은 비어있을 수 없습니다.")
String description,
@Schema(description = "여행기 장소 위도", example = "37.5175896")
@NotBlank(message = "여행기 장소 위도는 비어있을 수 없습니다.")
String lat,
@Schema(description = "여행기 장소 설명", example = "127.0867236")
@NotBlank(message = "여행기 장소 경도는 비어있을 수 없습니다.")
String lng,
List<String> photoUrls
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package woowacourse.touroot.travelogue.domain.place.repsitory;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay;
import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace;

public interface TraveloguePlaceRepository extends JpaRepository<TraveloguePlace, Long> {

List<TraveloguePlace> findByTravelogueDay(TravelogueDay travelogueDay);
}
Loading

0 comments on commit 8e979a2

Please sign in to comment.