-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#17] 메인페이지 조회
- Loading branch information
Showing
15 changed files
with
380 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/Journey/Together/domain/place/controller/PlaceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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.service.PlaceService; | ||
import Journey.Together.global.common.ApiResponse; | ||
import Journey.Together.global.exception.Success; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
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)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/Journey/Together/domain/place/dto/response/MainRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/Journey/Together/domain/place/dto/response/PlaceRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/Journey/Together/domain/place/entity/DisabilityCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/Journey/Together/domain/place/entity/DisabilityPlaceCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/Journey/Together/domain/place/entity/DisabilitySubCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/Journey/Together/domain/place/entity/DisabilitySubCategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
src/main/java/Journey/Together/domain/place/entity/Place.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 java.util.List; | ||
|
||
public interface DisabilityPlaceCategoryRepository extends JpaRepository<DisabilityPlaceCategory, Long> { | ||
|
||
List<DisabilityPlaceCategory> findAllByPlace(Place place); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/Journey/Together/domain/place/repository/PlaceRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/Journey/Together/domain/place/service/PlaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package Journey.Together.domain.place.service; | ||
|
||
import Journey.Together.domain.place.dto.response.MainRes; | ||
import Journey.Together.domain.place.dto.response.PlaceRes; | ||
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.global.common.ApiResponse; | ||
import Journey.Together.global.exception.Success; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import software.amazon.awssdk.services.s3.endpoints.internal.Value; | ||
|
||
import java.util.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PlaceService { | ||
private final PlaceRepository placeRepository; | ||
private final DisabilityPlaceCategoryRepository disabilityPlaceCategoryRepository; | ||
private final Integer recommnedPlaceNum = 4; | ||
private final Integer aroundPlaceNum = 2; | ||
|
||
// 메인페이지 가져오기 | ||
public MainRes getMainPage(String areacode, String sigungucode){ | ||
|
||
List<Place> recommondPlaces = placeRepository.findRandomProducts(recommnedPlaceNum); | ||
List<Place> aroundPlaces = placeRepository.findAroundProducts(areacode, sigungucode, aroundPlaceNum); | ||
|
||
|
||
return new MainRes(getPlaceRes(recommondPlaces), getPlaceRes(aroundPlaces)); | ||
} | ||
|
||
private List<PlaceRes> getPlaceRes(List<Place> list){ | ||
List<PlaceRes> placeList = new ArrayList<>(); | ||
|
||
for(Place place : list){ | ||
Set<String> disability = new HashSet<>(); | ||
disabilityPlaceCategoryRepository.findAllByPlace(place) | ||
.forEach(disabilityPlaceCategory -> { | ||
disability.add(disabilityPlaceCategory.getSubCategory().getCategory().getId().toString()); | ||
}); | ||
placeList.add(PlaceRes.of(place, new ArrayList<>(disability))); | ||
} | ||
|
||
return placeList; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/Journey/Together/domain/placeBookbark/entity/PlaceBookmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package Journey.Together.domain.placeBookbark.entity; | ||
|
||
import Journey.Together.domain.member.entity.Member; | ||
import Journey.Together.domain.place.entity.Place; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class PlaceBookmark { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
Member member; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "place_id") | ||
Place place; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/Journey/Together/domain/placeReview/entity/PlaceReview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package Journey.Together.domain.placeReview.entity; | ||
|
||
import Journey.Together.domain.member.entity.Member; | ||
import Journey.Together.domain.place.entity.Place; | ||
import Journey.Together.global.common.BaseTimeEntity; | ||
import com.fasterxml.jackson.databind.ser.Serializers; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class PlaceReview extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "place_review_id") | ||
Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
Member member; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "place_id") | ||
Place place; | ||
|
||
Float grade; | ||
|
||
String content; | ||
|
||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/Journey/Together/domain/placeReview/entity/PlaceReviewImg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Journey.Together.domain.placeReview.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class PlaceReviewImg { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "place_review_id") | ||
PlaceReview placeReview; | ||
|
||
String imgUrl; | ||
} |
Oops, something went wrong.