Skip to content

Commit

Permalink
Merge pull request #10 from SOPT-all/feat/8
Browse files Browse the repository at this point in the history
[FEAT] 장소 중복 검사, Entity 구조 변경
  • Loading branch information
airoca authored Jan 15, 2025
2 parents 09e2b15 + ae0e75b commit fb0d6f7
Show file tree
Hide file tree
Showing 27 changed files with 392 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.spoony.spoony_server.domain.location.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "location_dong")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LocationDongEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -12,4 +16,13 @@ public class LocationDongEntity {
private String guAddress;
private Double latitude;
private Double longitude;

@Builder
public LocationDongEntity(String guName, Integer guId, String guAddress, Double latitude, Double longitude) {
this.guName = guName;
this.guId = guId;
this.guAddress = guAddress;
this.latitude = latitude;
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.spoony.spoony_server.domain.location.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "location_gu")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LocationGuEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -12,4 +16,13 @@ public class LocationGuEntity {
private String guAddress;
private Double latitude;
private Double longitude;

@Builder
public LocationGuEntity(Integer guId, String guName, String guAddress, Double latitude, Double longitude) {
this.guId = guId;
this.guName = guName;
this.guAddress = guAddress;
this.latitude = latitude;
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.spoony.spoony_server.domain.location.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "location_station")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LocationStationEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -12,4 +16,13 @@ public class LocationStationEntity {
private String guAddress;
private Double latitude;
private Double longitude;

@Builder
public LocationStationEntity(Integer guId, String guName, String guAddress, Double latitude, Double longitude) {
this.guId = guId;
this.guName = guName;
this.guAddress = guAddress;
this.latitude = latitude;
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import com.spoony.spoony_server.common.dto.ResponseDTO;
import com.spoony.spoony_server.common.exception.BusinessException;
import com.spoony.spoony_server.common.message.PlaceErrorMessage;
import com.spoony.spoony_server.domain.place.dto.PlaceListResponseDTO;
import com.spoony.spoony_server.domain.place.dto.PlaceResponseDTO;
import com.spoony.spoony_server.domain.place.dto.request.PlaceCheckRequestDTO;
import com.spoony.spoony_server.domain.place.dto.request.PlaceCheckResponseDTO;
import com.spoony.spoony_server.domain.place.dto.response.PlaceListResponseDTO;
import com.spoony.spoony_server.domain.place.dto.response.PlaceResponseDTO;
import com.spoony.spoony_server.domain.place.service.PlaceService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
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 org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -26,6 +26,11 @@
@RestController
@RequestMapping("/api/place")
public class PlaceController {
public final PlaceService placeService;

public PlaceController(PlaceService placeService) {
this.placeService = placeService;
}

@GetMapping(value = "/search")
public ResponseEntity<ResponseDTO<PlaceListResponseDTO>> getPlaceList(
Expand Down Expand Up @@ -70,8 +75,8 @@ public ResponseEntity<ResponseDTO<PlaceListResponseDTO>> getPlaceList(
String title = item.get("title").asText().replaceAll("<[^>]*>", ""); // HTML 태그 제거
String address = item.get("address").asText();
String roadAddress = item.get("roadAddress").asText();
String mapx = item.get("mapx").asText();
String mapy = item.get("mapy").asText();
Double mapx = item.get("mapx").asDouble();
Double mapy = item.get("mapy").asDouble();

places.add(new PlaceResponseDTO(title, address, roadAddress, mapx, mapy));
});
Expand All @@ -84,4 +89,15 @@ public ResponseEntity<ResponseDTO<PlaceListResponseDTO>> getPlaceList(
throw new BusinessException(PlaceErrorMessage.JSON_PARSE_ERROR);
}
}

@PostMapping("/check")
public ResponseEntity<ResponseDTO<PlaceCheckResponseDTO>> checkDuplicatePlace(
@RequestBody PlaceCheckRequestDTO placeCheckRequestDTO) {

boolean isDuplicate = placeService.isDuplicate(placeCheckRequestDTO);

PlaceCheckResponseDTO placeCheckResponseDTO = new PlaceCheckResponseDTO(isDuplicate);

return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.success(placeCheckResponseDTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.spoony.spoony_server.domain.place.dto.request;

public record PlaceCheckRequestDTO(long userId, Double latitude, Double longitude) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.spoony.spoony_server.domain.place.dto.request;

public record PlaceCheckResponseDTO(Boolean duplicate) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.spoony.spoony_server.domain.place.dto;
package com.spoony.spoony_server.domain.place.dto.response;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.spoony.spoony_server.domain.place.dto;
package com.spoony.spoony_server.domain.place.dto.response;

public record PlaceResponseDTO(String placeName,
String placeAddress,
String placeRoadAddress,
String latitude,
String longitude) {
Double latitude,
Double longitude) {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.spoony.spoony_server.domain.place.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "place")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -13,4 +19,19 @@ public class PlaceEntity {
private String placeAddress;
private Double latitude;
private Double longitude;

@Builder
public PlaceEntity(Integer placeId,
Integer placeCode,
String placeName,
String placeAddress,
Double latitude,
Double longitude) {
this.placeId = placeId;
this.placeCode = placeCode;
this.placeName = placeName;
this.placeAddress = placeAddress;
this.latitude = latitude;
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.spoony.spoony_server.domain.place.repository;

import com.spoony.spoony_server.domain.place.entity.PlaceEntity;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PlaceRepository extends JpaRepository<PlaceEntity, Long> {
boolean existsByPlaceIdInAndLatitudeAndLongitude(List<Integer> placeIds, Double latitude, Double longitude);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.spoony.spoony_server.domain.place.service;

import com.spoony.spoony_server.domain.place.dto.request.PlaceCheckRequestDTO;
import com.spoony.spoony_server.domain.place.repository.PlaceRepository;
import com.spoony.spoony_server.domain.post.entity.PostEntity;
import com.spoony.spoony_server.domain.post.repository.PostRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlaceService {

public final PlaceRepository placeRepository;
public final PostRepository postRepository;

public PlaceService(PlaceRepository placeRepository, PostRepository postRepository) {
this.placeRepository = placeRepository;
this.postRepository = postRepository;
}

public Boolean isDuplicate(PlaceCheckRequestDTO placeCheckRequestDTO) {
Long userId = placeCheckRequestDTO.userId();
Double latitude = placeCheckRequestDTO.latitude();
Double longitude = placeCheckRequestDTO.longitude();

List<PostEntity> userPosts = postRepository.findByUser_UserId(userId);

List<Integer> placeIds = userPosts.stream()
.map(post -> post.getPlace().getPlaceId())
.toList();

boolean exists = placeRepository.existsByPlaceIdInAndLatitudeAndLongitude(placeIds, latitude, longitude);

return exists;
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.spoony.spoony_server.domain.post.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "category")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CategoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer categoryId;
private String categoryName;

@Builder
public CategoryEntity(Integer categoryId, String categoryName) {
this.categoryId = categoryId;
this.categoryName = categoryName;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package com.spoony.spoony_server.domain.post.entity;

import com.spoony.spoony_server.domain.user.entity.UserEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "feed")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FeedEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer feedId;
private Integer userId;
private Integer postId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private UserEntity user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
private PostEntity post;

@Builder
public FeedEntity(Integer feedId, UserEntity user, PostEntity post) {
this.feedId = feedId;
this.user = user;
this.post = post;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
package com.spoony.spoony_server.domain.post.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "menu")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class MenuEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer menuId;
private Integer postId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
private PostEntity post;

private String menuName;

@Builder
public MenuEntity(Integer menuId, PostEntity post, String menuName) {
this.menuId = menuId;
this.post = post;
this.menuName = menuName;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
package com.spoony.spoony_server.domain.post.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "photo")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PhotoEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer photoId;
private Integer postId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
private PostEntity post;

private String photoUrl;

@Builder
public PhotoEntity(Integer photoId, PostEntity post, String photoUrl) {
this.photoId = photoId;
this.post = post;
this.photoUrl = photoUrl;
}
}
Loading

0 comments on commit fb0d6f7

Please sign in to comment.