Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
package com.sopkathon.domain.place.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sopkathon.domain.place.dto.GetPlaceListResponse;
import com.sopkathon.domain.place.service.PlaceService;
import com.sopkathon.global.error.code.SuccessCode;
import com.sopkathon.global.error.dto.SuccessResponse;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/places")
public class PlaceController {
private final PlaceService placeService;

@GetMapping
public ResponseEntity<SuccessResponse<?>> getPlaceList(@RequestParam(name = "category", defaultValue = "ALL") String category,
@RequestParam(name = "subway") String subway){
GetPlaceListResponse getPlaceListResponse = placeService.getPlaceList(category, subway);
return ResponseEntity.ok(SuccessResponse.of(SuccessCode.SUCCESS_FETCH, getPlaceListResponse));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopkathon.domain.place.dto;

import java.util.List;

public record GetPlaceListResponse(
List<GetPlaceResponse> getPlaceResponseList
) {
public static GetPlaceListResponse of(List<GetPlaceResponse> getPlaceResponseList) {
return new GetPlaceListResponse(getPlaceResponseList);
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/sopkathon/domain/place/dto/GetPlaceResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sopkathon.domain.place.dto;


import com.sopkathon.domain.place.entity.PlaceEntity;

import lombok.Builder;

@Builder
public record GetPlaceResponse(
Long placeId,
String name,
String description,
String mapLink,
String photoUrl
) {

public static GetPlaceResponse of(PlaceEntity placeEntity) {
return GetPlaceResponse.builder()
.placeId(placeEntity.getId())
.name(placeEntity.getName())
.description(placeEntity.getDescription())
.mapLink(placeEntity.getMapLink())
.photoUrl(placeEntity.getPhotoUrl())
.build();
}
}
31 changes: 21 additions & 10 deletions src/main/java/com/sopkathon/domain/place/entity/Category.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sopkathon.domain.place.entity;

import java.util.Arrays;

import com.sopkathon.global.error.code.ErrorCode;
import com.sopkathon.global.error.exception.BusinessException;

Expand All @@ -9,18 +11,27 @@

@Getter
public enum Category {
NATURAL("자연");
ORCHARD("과수원"),
CROPS("밭작물"),
LIVESTOCK("축산"),
PLANTS_AND_FLOWERS("식물·꽃"),
OTHER("기타");

private String korName;

private String name;
Category(String korName) {
this.korName = korName;
}

Category(String name) {}

public static Category fromName(String name) {
for (Category category : values()) {
if(category.name.equals(name)) {
return category;
}
}
throw new BusinessException(ErrorCode.DATA_NOT_FOUND);
public String getKorName() {
return korName;
}

public static Category fromKorName(String korName) {
return Arrays.stream(Category.values())
.filter(c -> c.korName.equals(korName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unknown category: " + korName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sopkathon.domain.place.entity;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class CategoryConverter implements AttributeConverter<Category, String> {
@Override
public String convertToDatabaseColumn(Category attribute) {
return attribute.getKorName(); // 한글로 저장
}

@Override
public Category convertToEntityAttribute(String dbData) {
return Category.fromKorName(dbData); // 한글 → Enum으로 복원
}
}
19 changes: 6 additions & 13 deletions src/main/java/com/sopkathon/domain/place/entity/PlaceEntity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.sopkathon.domain.place.entity;

import com.sopkathon.domain.review.entity.ReviewEntity;
import com.sopkathon.domain.similarPlace.entity.SimilarPlaceEntity;
import com.sopkathon.domain.subway.entity.SubwayEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand All @@ -29,6 +29,9 @@ public class PlaceEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(name = "duration", nullable = false)
private int duration;

Expand All @@ -41,33 +44,23 @@ public class PlaceEntity {
@Column(name = "photo_url", nullable = false)
private String photoUrl;

@Enumerated(EnumType.STRING)
@Convert(converter = CategoryConverter.class)
@Column(name = "category", nullable = false)
private Category category;

@ManyToOne(targetEntity = SubwayEntity.class, fetch = FetchType.LAZY)
@JoinColumn(name = "subway_id", nullable = false)
private SubwayEntity subwayEntity;

@ManyToOne(targetEntity = ReviewEntity.class, fetch = FetchType.LAZY)
@JoinColumn(name = "review_id", nullable = false)
private ReviewEntity reviewEntity;

@ManyToOne(targetEntity = SimilarPlaceEntity.class, fetch = FetchType.LAZY)
@JoinColumn(name = "similar_place_id", nullable = false)
private SimilarPlaceEntity similarPlaceEntity;

@Builder

public PlaceEntity(int duration, String description, String mapLink, String photoUrl, Category category,
SubwayEntity subwayEntity, ReviewEntity reviewEntity, SimilarPlaceEntity similarPlaceEntity) {
SubwayEntity subwayEntity) {
this.duration = duration;
this.description = description;
this.mapLink = mapLink;
this.photoUrl = photoUrl;
this.category = category;
this.subwayEntity = subwayEntity;
this.reviewEntity = reviewEntity;
this.similarPlaceEntity = similarPlaceEntity;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.sopkathon.domain.place.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.sopkathon.domain.place.entity.Category;
import com.sopkathon.domain.place.entity.PlaceEntity;
import com.sopkathon.domain.subway.entity.SubwayEntity;

@Repository
public interface PlaceRepository extends JpaRepository<PlaceEntity,Long> {
List<PlaceEntity> findAllBySubwayEntity(SubwayEntity subwayEntity);
List<PlaceEntity> findAllBySubwayEntityAndCategory(SubwayEntity subwayEntity, Category category);
}
36 changes: 36 additions & 0 deletions src/main/java/com/sopkathon/domain/place/service/PlaceService.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
package com.sopkathon.domain.place.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.sopkathon.domain.place.dto.GetPlaceListResponse;
import com.sopkathon.domain.place.dto.GetPlaceResponse;
import com.sopkathon.domain.place.entity.Category;
import com.sopkathon.domain.place.entity.PlaceEntity;
import com.sopkathon.domain.place.repository.PlaceRepository;
import com.sopkathon.domain.subway.entity.SubwayEntity;
import com.sopkathon.domain.subway.service.SubwayService;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class PlaceService {
private final PlaceRepository placeRepository;
private final SubwayService SubwayService;

public GetPlaceListResponse getPlaceList(String category, String subway){
SubwayEntity subwayEntity = SubwayService.getSubwayEntity(subway);
List<PlaceEntity> placeEntityList = getPlacesByCategory(subwayEntity, category);

List<GetPlaceResponse> getPlaceResponseList = placeEntityList.stream()
.map(GetPlaceResponse::of)
.toList();

return new GetPlaceListResponse(getPlaceResponseList);
}

private List<PlaceEntity> getPlacesByCategory(SubwayEntity subwayEntity, String category) {
if ("ALL".equals(category)) {
return placeRepository.findAllBySubwayEntity(subwayEntity);
}
return placeRepository.findAllBySubwayEntityAndCategory(subwayEntity, Category.fromKorName(category));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.time.LocalDate;

import com.sopkathon.domain.place.entity.PlaceEntity;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -17,7 +19,7 @@ public class ReviewEntity {
private Long id;

@Column(name = "createdAt", nullable = false)
private LocalDate createdAt;
private String createdAt;

@Column(name = "author", nullable = false)
private String author;
Expand All @@ -27,4 +29,8 @@ public class ReviewEntity {

@Column(name = "profile_image_url", nullable = false)
private String profileImageUrl;

@ManyToOne(targetEntity = PlaceEntity.class, fetch = FetchType.LAZY)
@JoinColumn(name = "place_id", nullable = false)
private PlaceEntity placeEntity;
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
@Repository
public interface SubwayRepository extends JpaRepository<SubwayEntity, Long> {
List<SubwayEntity> findBySubwayNameContaining(String keyword);
SubwayEntity findBySubwayName(String subwayName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.stream.Collectors;


@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -35,4 +36,8 @@ public SubwayListRes getSubwayListByKeyword(String keyword) {

return SubwayListRes.from(subwayList);
}

public SubwayEntity getSubwayEntity(String subwayName) {
return subwayRepository.findBySubwayName(subwayName);
}
}