Skip to content

Commit

Permalink
[#20] feat: 관광정보 상세보기 api
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihye committed Jun 2, 2024
1 parent 5596f09 commit 5e73c50
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 1 deletion.
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
Expand Up @@ -4,11 +4,14 @@
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
Expand All @@ -24,4 +27,11 @@ public ApiResponse<MainRes> getMain(@RequestHeader("Authorization") String acces
@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,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,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
Expand Up @@ -3,10 +3,21 @@
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
@@ -1,12 +1,20 @@
package Journey.Together.domain.place.service;

import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.place.dto.response.MainRes;
import Journey.Together.domain.place.dto.response.PlaceDetailRes;
import Journey.Together.domain.place.dto.response.PlaceRes;
import Journey.Together.domain.place.dto.response.PlaceReviewDto;
import Journey.Together.domain.place.entity.DisabilityPlaceCategory;
import Journey.Together.domain.place.entity.Place;
import Journey.Together.domain.place.repository.DisabilityPlaceCategoryRepository;
import Journey.Together.domain.place.repository.PlaceRepository;
import Journey.Together.domain.placeBookbark.entity.PlaceBookmark;
import Journey.Together.domain.placeBookbark.repository.PlaceBookmarkRepository;
import Journey.Together.global.common.ApiResponse;
import Journey.Together.global.exception.ApplicationException;
import Journey.Together.global.exception.ErrorCode;
import Journey.Together.global.exception.ErrorResponse;
import Journey.Together.global.exception.Success;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -19,6 +27,9 @@
public class PlaceService {
private final PlaceRepository placeRepository;
private final DisabilityPlaceCategoryRepository disabilityPlaceCategoryRepository;
private final PlaceBookmarkRepository placeBookmarkRepository;


private final Integer recommnedPlaceNum = 4;
private final Integer aroundPlaceNum = 2;

Expand All @@ -32,6 +43,26 @@ public MainRes getMainPage(String areacode, String sigungucode){
return new MainRes(getPlaceRes(recommondPlaces), getPlaceRes(aroundPlaces));
}

//여행지 상세 정보 가져오기
public PlaceDetailRes getPlaceDetail(Member member, Long placeId){
// PlaceDetailRes of(Place place, Boolean isMark, Integer bookmarkNum, List<String> disability, List<String> subDisability, List< PlaceReviewDto > reviewList)

Place place = placeRepository.findById(placeId).orElseThrow(
()->new ApplicationException(ErrorCode.NOT_FOUND_PLACE_EXCEPTION));

List<PlaceBookmark> placeBookmarkList = placeBookmarkRepository.findAllByPlace(place);
Boolean isMark = placeBookmarkList.stream()
.anyMatch(placeBookmark -> placeBookmark.getMember().equals(member));

List<Long> disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId);
List<Long> subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategoryIds(placeId);

return PlaceDetailRes.of(place, isMark, placeBookmarkList.size(), disability, subDisability, null);



}

private List<PlaceRes> getPlaceRes(List<Place> list){
List<PlaceRes> placeList = new ArrayList<>();

Expand All @@ -47,4 +78,5 @@ private List<PlaceRes> getPlaceRes(List<Place> list){
return placeList;
}


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


import Journey.Together.domain.place.entity.Place;
import Journey.Together.domain.placeBookbark.entity.PlaceBookmark;
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 PlaceBookmarkRepository extends JpaRepository<PlaceBookmark, Long> {

List<PlaceBookmark> findAllByPlace(Place place);


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum ErrorCode {

//4000: Apply Error
NOT_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4000,"지원 기간 지났습니다"),
NOT_FOUND_POST_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 글입니다."),
NOT_FOUND_PLACE_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 여행지입니다."),
NOT_FOUND_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4002,"존재하지 않는 지원서입니다."),
ALREADY_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4003,"이미 지원했습니다."),
ALREADY_DECISION_EXCEPION(HttpStatus.BAD_REQUEST,4004,"이미 지원 결정했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Success {
* 200 OK
*/
GET_MAIN_SUCCESS(HttpStatus.OK, "메인 페이지 정보 조회 성공"),
GET_PLACE_DETAIL_SUCCESS(HttpStatus.OK, "여행지 상세정보 조회 성공"),
GET_MYPAGE_SUCCESS(HttpStatus.OK, "마이 페이지 조회 성공"),
GET_LINKS_SUCCESS(HttpStatus.OK, "이주의 링크 조회 성공"),
GET_SITES_SUCCESS(HttpStatus.OK, "추천 사이트 조회 성공"),
Expand Down

0 comments on commit 5e73c50

Please sign in to comment.