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
Expand Up @@ -33,12 +33,11 @@ class FestivalController(
@GetMapping("/{festivalId}")
@Operation(summary = "지역축제 상세 조회")
fun festivalDetails(
@PathVariable("festivalId") festivalId: Long,
@RequestParam("sort") sort: FestivalSortType,
@RequestParam("status")status: FestivalStatus
):ApiResponse<FestivalDetailsDTO.DetailDto>?{
@PathVariable("festivalId") festivalId: Long
):ApiResponse<FestivalDetailsDTO.DetailDto>{

return null;
val festivalDetails = festivalQueryService.getFestivalDetails(festivalId)
return ApiResponse.onSuccess(festivalDetails);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FestivalConverter {
)
}

private fun convertFestivalDate(date: Date): String {
public fun convertFestivalDate(date: Date): String {
val formatter: SimpleDateFormat = SimpleDateFormat("yyyy.MM.dd")
return formatter.format(date)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
import java.util.Date

@Entity
Expand All @@ -33,11 +35,29 @@ class Festival (
@Column(nullable = false, columnDefinition = "TEXT")
val introduction: String,

@Column(nullable = false)
val fee: Int,

@Column(nullable = false)
val phone: String,

@Column(nullable = false)
val siteUrl: String,

// 연관관계
@Enumerated(EnumType.STRING)
@Column(nullable = false)
val status: FestivalStatus,

): BaseEntity(){
@OneToMany(mappedBy = "festival", fetch = FetchType.LAZY)
val festivalImages: Set<FestivalImage>,

@OneToMany(mappedBy = "festival", fetch = FetchType.LAZY)
val festivalLikes: Set<FestivalLike>


): BaseEntity(){



}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FestivalImage(
val imgUrl : String,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "festival_id")
val festival: Festival

): BaseEntity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package busanVibe.busan.domain.festival.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

Expand All @@ -8,15 +9,17 @@ class FestivalDetailsDTO {
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class DetailDto(
val id: Long,
val img: String,
val img: Set<String>,
val name: String,
val likeCount: Integer,
val likeCount: Int,
@get:JsonProperty("is_like")
val isLike: Boolean,
val startDate: String,
val endDate: String,
val region: String,
val phone: String,
val fee: Integer,
val fee: Int,
val siteUrl: String,
val introduce: String
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package busanVibe.busan.domain.festival.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

Expand All @@ -18,6 +19,7 @@ class FestivalListResponseDTO {
val startDate: String,
val endDate: String,
val region: String,
@get:JsonProperty("is_like")
val isLike: Boolean,
val likeCount: Int,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository
interface FestivalLikesRepository: JpaRepository<FestivalLike, String> {

fun findAllByFestivalIn(festivalList: List<Festival>): List<FestivalLike>
fun findAllByFestivalIn(festivalList: Set<Festival>): List<FestivalLike>


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface FestivalRepository: JpaRepository<Festival, String> {
interface FestivalRepository: JpaRepository<Festival, Long> {

@Query(
"""
Expand All @@ -15,4 +15,13 @@ interface FestivalRepository: JpaRepository<Festival, String> {
""")
fun getFestivalList(@Param("status") status: FestivalStatus): List<Festival>

@Query("""
SELECT f FROM Festival f
LEFT JOIN FETCH f.festivalLikes
LEFT JOIN FETCH f.festivalImages
WHERE f.id = :id
""")
fun findByIdWithLikesAndImages(@Param("id") id: Long): Festival?


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package busanVibe.busan.domain.festival.service
import busanVibe.busan.domain.festival.converter.FestivalConverter
import busanVibe.busan.domain.festival.domain.Festival
import busanVibe.busan.domain.festival.domain.FestivalLike
import busanVibe.busan.domain.festival.dto.FestivalDetailsDTO
import busanVibe.busan.domain.festival.dto.FestivalListResponseDTO
import busanVibe.busan.domain.festival.enums.FestivalSortType
import busanVibe.busan.domain.festival.enums.FestivalStatus
Expand All @@ -11,6 +12,9 @@ import busanVibe.busan.domain.festival.repository.FestivalLikesRepository
import busanVibe.busan.domain.festival.repository.FestivalRepository
import busanVibe.busan.domain.user.data.User
import busanVibe.busan.domain.user.service.login.AuthService
import busanVibe.busan.global.apiPayload.code.status.ErrorStatus
import busanVibe.busan.global.apiPayload.exception.handler.ExceptionHandler
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -21,6 +25,8 @@ class FestivalQueryService(
private val festivalLikesRepository: FestivalLikesRepository
) {

val log = LoggerFactory.getLogger(FestivalQueryService::class.java)

@Transactional(readOnly = true)
fun getFestivalList(sort: FestivalSortType?, status: FestivalStatus?): FestivalListResponseDTO.ListDto{

Expand Down Expand Up @@ -79,4 +85,43 @@ class FestivalQueryService(
return FestivalListResponseDTO.ListDto(sortedList)
}

fun getFestivalDetails(festivalId: Long):FestivalDetailsDTO.DetailDto{

// Festival -> id, name, startDate, endDate, place, introduction
// FestivalLike -> count, isLike
// FestivalImage -> img

// user 추출
val currentUser: User = AuthService().getCurrentUser()

// 축제 조회
val festival: Festival? = festivalRepository.findByIdWithLikesAndImages(festivalId)

// 검증
festival ?: throw ExceptionHandler(ErrorStatus.FESTIVAL_NOT_FOUND)

// 이미지 조회
val imgUrlSet: Set<String> = festival.festivalImages
.map { it.imgUrl }
.toSet()

// 좋아요 조회
val likeList: Set<FestivalLike> = festival.festivalLikes

return FestivalDetailsDTO.DetailDto(
id = festivalId,
img = imgUrlSet,
name = festival.name,
likeCount = likeList.size,
isLike = likeList.any { it.user.id == currentUser.id },
startDate = FestivalConverter().convertFestivalDate(festival.startDate),
endDate = FestivalConverter().convertFestivalDate(festival.endDate),
region = festival.place,
fee = festival.fee,
siteUrl = festival.siteUrl,
introduce = festival.introduction,
phone = festival.phone,
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class PlaceDetailsConverter(
): PlaceResponseDTO.PlaceDetailsDto.SightDto = PlaceResponseDTO.PlaceDetailsDto.SightDto(
id = place.id,
name = place.name,
type = place.type.korean,
img = placeImages.firstOrNull()?.imgUrl,
type = place.type.capitalEnglish,
img = placeImages.map { it.imgUrl },
congestionLevel = redisUtil.getRedisCongestion(place.id),
grade = if (placeReviews.isNotEmpty()) {
placeReviews.map { it.score }.average().toFloat()
Expand All @@ -57,8 +57,8 @@ class PlaceDetailsConverter(
): PlaceResponseDTO.PlaceDetailsDto.RestaurantDto = PlaceResponseDTO.PlaceDetailsDto.RestaurantDto(
id = place.id,
name = place.name,
type = place.type.korean,
img = placeImages.firstOrNull()?.imgUrl,
type = place.type.capitalEnglish,
img = placeImages.map { it.imgUrl },
congestionLevel = redisUtil.getRedisCongestion(place.id),
grade = placeReviews.map { it.score }.average().toFloat(),
reviewAmount = placeReviews.size,
Expand Down
15 changes: 8 additions & 7 deletions src/main/kotlin/busanVibe/busan/domain/place/domain/Place.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
import jakarta.persistence.OneToOne
import java.math.BigDecimal

Expand Down Expand Up @@ -47,14 +48,14 @@ class Place(
//
// @OneToMany(mappedBy = "place", fetch = FetchType.LAZY)
// val reviews: List<Review> = emptyList(),
//
// @OneToMany(mappedBy = "place", fetch = FetchType.LAZY)
// val placeLikes: List<PlaceLike> = emptyList(),
//

@OneToMany(mappedBy = "place", fetch = FetchType.LAZY)
val placeLikes: Set<PlaceLike>,

@OneToOne(mappedBy = "place", fetch = FetchType.LAZY)
val openTime: OpenTime,
//
// @OneToMany(mappedBy="place", fetch = FetchType.LAZY)
// val images: List<PlaceImage> = emptyList(),

@OneToMany(mappedBy="place", fetch = FetchType.LAZY)
val placeImages: Set<PlaceImage>

) : BaseEntity()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package busanVibe.busan.domain.place.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

Expand Down Expand Up @@ -31,6 +32,7 @@ class PlaceMapResponseDTO {
val latitude: Double,
val longitude: Double,
val address: String,
@get:JsonProperty("is_open")
val isOpen: Boolean,
val imgList: List<String>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package busanVibe.busan.domain.place.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

Expand All @@ -17,6 +18,7 @@ class PlaceResponseDTO {
val placeId: Long?,
val name: String,
val congestionLevel: Int,
@get:JsonProperty("is_like")
val isLike: Boolean,
val likeAmount: Int,
val type: String,
Expand All @@ -34,7 +36,7 @@ class PlaceResponseDTO {

abstract val type: String

abstract val img: String?
abstract val img: List<String>?

abstract val congestionLevel: Int

Expand All @@ -44,27 +46,31 @@ class PlaceResponseDTO {

abstract val likeAmount: Int

@get:JsonProperty("is_open")
abstract val isOpen: Boolean

abstract val address: String

abstract val phone: String

@get:JsonProperty("is_like")
abstract val isLike: Boolean

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class SightDto(
override val id: Long?,
override val name: String,
override val type: String,
override val img: String?,
override val img: List<String>,
override val congestionLevel: Int,
override val grade: Float?,
override val reviewAmount: Int,
override val likeAmount: Int,
@get:JsonProperty("is_open")
override val isOpen: Boolean,
override val address: String,
override val phone: String,
@get:JsonProperty("is_like")
override val isLike: Boolean,
val introduce: String
) : PlaceDetailsDto()
Expand All @@ -74,14 +80,16 @@ class PlaceResponseDTO {
override val id: Long?,
override val name: String,
override val type: String,
override val img: String?,
override val img: List<String>,
override val congestionLevel: Int,
override val grade: Float?,
override val reviewAmount: Int,
override val likeAmount: Int,
@get:JsonProperty("is_open")
override val isOpen: Boolean,
override val address: String,
override val phone: String,
@get:JsonProperty("is_like")
override val isLike: Boolean,
val monOpen: String,
val tueOpen: String,
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/busanVibe/busan/domain/place/enums/PlaceType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import lombok.AllArgsConstructor

@AllArgsConstructor
enum class PlaceType(
val korean: String
val korean: String,
val capitalEnglish: String
) {

ALL("전체"),
SIGHT("관광지"),
RESTAURANT("식당"),
CAFE("카페")
ALL("전체", "ALL"),
SIGHT("관광지", "SIGHT"),
RESTAURANT("식당", "RESTAURANT"),
CAFE("카페", "CAFE")
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository

interface PlaceImageRepository: JpaRepository<PlaceImage, Long> {

fun findByPlace(place: Place): List<PlaceImage>
fun findByPlaceIn(placeList: List<Place>): List<PlaceImage>

}
Loading