Skip to content

Commit

Permalink
Merge branch 'main' into feature/#15
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui authored Jun 3, 2024
2 parents fc139c3 + e495f66 commit 7c40fe6
Show file tree
Hide file tree
Showing 20 changed files with 509 additions and 2 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ dependencies {
// MAC OS
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64'

//Querydsl 추가
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor """com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"""
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Journey.Together.domain.place.controller;

import Journey.Together.domain.member.dto.LoginReq;
import Journey.Together.domain.member.dto.MemberRes;
import Journey.Together.domain.member.service.MemberService;
import Journey.Together.domain.place.dto.response.MainRes;
import Journey.Together.domain.place.dto.response.PlaceDetailRes;
import Journey.Together.domain.place.service.PlaceService;
import Journey.Together.global.common.ApiResponse;
import Journey.Together.global.exception.Success;
import Journey.Together.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/place")
@Tag(name = "Place", description = "여행지 정보 API")
public class PlaceController {

private final PlaceService placeService;

@GetMapping("/main")
public ApiResponse<MainRes> getMain(@RequestHeader("Authorization") String accesstoken,
@RequestParam String areacode, @RequestParam String sigungucode) {
return ApiResponse.success(Success.GET_MAIN_SUCCESS, placeService.getMainPage(areacode, sigungucode));
}

@GetMapping("/{placeId}")
public ApiResponse<PlaceDetailRes> getPlaceDetail(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable Long placeId){
return ApiResponse.success(Success.GET_PLACE_DETAIL_SUCCESS, placeService.getPlaceDetail(principalDetails.getMember(), placeId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Journey.Together.domain.place.dto.response;

import java.util.List;

public record MainRes(
List<PlaceRes> recommendPlaceList,
List<PlaceRes> aroundPlaceList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Journey.Together.domain.place.dto.response;

import Journey.Together.domain.place.entity.Place;

import java.util.List;

public record PlaceDetailRes(
Long placeId,
String name,
String imgae,
String address,
String category,
String overview,
String mapX,
String mapY,

Boolean isMark,

Integer bookmarkNum,

List<Long> disability,
List<Long> subDisability,
List<PlaceReviewDto> reviewList
) {
static String cat = "관광지";
public static PlaceDetailRes of(Place place, Boolean isMark, Integer bookmarkNum, List<Long> disability, List<Long> subDisability, List<PlaceReviewDto> reviewList){
if(place.getCategory().equals("B02"))
cat = "숙소";
else if (place.getCategory().equals("A05"))
cat = "맛집";



return new PlaceDetailRes(place.getId(), place.getName(), place.getFirstImg(), place.getAddress(), cat, place.getOverview(), place.getMapX(), place.getMapY(), isMark,
bookmarkNum, disability, subDisability, reviewList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Journey.Together.domain.place.dto.response;

import Journey.Together.domain.place.entity.Place;

import java.util.List;

public record PlaceRes(
Long placeId,
String name,
String image,
List<String> disability,
String address
) {
public static PlaceRes of(Place place, List<String> disability){

return new PlaceRes(place.getId(), place.getName(), place.getFirstImg(), disability,place.getAddress());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Journey.Together.domain.place.dto.response;

import java.time.LocalDateTime;

public record PlaceReviewDto(
Long reviewId,
String nickname,
String profileImg,
String content,
String reviewImg,
Float grade,
LocalDateTime date) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Journey.Together.domain.place.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DisabilityCategory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package Journey.Together.domain.place.entity;

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

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DisabilityPlaceCategory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_id")
private Place place;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "subCategory_id")
private DisabilitySubCategory subCategory;

@Builder
public DisabilityPlaceCategory(Place place, DisabilitySubCategory subCategory){
this.place=place;
this.subCategory=subCategory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Journey.Together.domain.place.entity;

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

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DisabilitySubCategory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String subname;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private DisabilityCategory category;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Journey.Together.domain.place.entity;

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

public interface DisabilitySubCategoryRepository extends JpaRepository<DisabilitySubCategory,Long> {
}
75 changes: 75 additions & 0 deletions src/main/java/Journey/Together/domain/place/entity/Place.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package Journey.Together.domain.place.entity;

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

import java.util.HashSet;
import java.util.Set;

@Entity
@Getter
@Table(name = "place")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Place {

@Id
private Long id;

private String name;

private String address;
@Column(columnDefinition = "TEXT")
private String firstImg;
private String category;
private String mapX;
private String mapY;
private String createdAt;
@Column(columnDefinition = "TEXT")
private String overview;

private String areaCode;

private String sigunguCode;


private Boolean settingDisability;


@OneToMany(mappedBy = "place", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DisabilityPlaceCategory> placeDisabilityCategories = new HashSet<>();

public void setArea(String areaCode, String sigunguCode) {
this.areaCode = areaCode;
this.sigunguCode = sigunguCode;
}

public void setOverview(String overview){
this.overview = overview;
}

public void setting(){
this.settingDisability = true;
}

@Builder
public Place(Long id, String name, String address, String firstImg, String category, String mapX, String mapY, String createdAt, String areaCode, String sigunguCode){
this.id =id;
this.name=name;
this.address=address;
this.firstImg=firstImg;
this.category=category;
this.mapX=mapX;
this.mapY=mapY;
this.createdAt=createdAt;
this.areaCode = areaCode;
this.sigunguCode = sigunguCode;
}

public Long getId() {
return id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Journey.Together.domain.place.repository;

import Journey.Together.domain.place.entity.DisabilityPlaceCategory;
import Journey.Together.domain.place.entity.Place;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DisabilityPlaceCategoryRepository extends JpaRepository<DisabilityPlaceCategory, Long> {

List<DisabilityPlaceCategory> findAllByPlace(Place place);


@Query("SELECT DISTINCT dpc.subCategory.category.id FROM DisabilityPlaceCategory dpc " +
"WHERE dpc.place.id = :placeId")
List<Long> findDisabilityCategoryIds(@Param("placeId") long placeId);

@Query("SELECT DISTINCT dpc.subCategory.id FROM DisabilityPlaceCategory dpc " +
"WHERE dpc.place.id = :placeId")
List<Long> findDisabilitySubCategoryIds(@Param("placeId") long placeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Journey.Together.domain.place.repository;


import Journey.Together.domain.place.entity.Place;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PlaceRepository extends JpaRepository<Place, Long> {

@Query(value = "SELECT * FROM place p ORDER BY RAND() LIMIT :count", nativeQuery = true)
List<Place> findRandomProducts(@Param("count") int count);

@Query(value = "SELECT * FROM place p WHERE area_code = :areacode AND sigungu_code = :sigungucode " +
"ORDER BY RAND() LIMIT :count", nativeQuery = true)
List<Place> findAroundProducts(@Param("areacode") String areacode, @Param("sigungucode") String sigungucode,
@Param("count") int count);

}
Loading

0 comments on commit 7c40fe6

Please sign in to comment.