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
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ dependencies {
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin"

// xml
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0")

implementation 'org.springframework.boot:spring-boot-starter-webflux'



}

Expand Down
16 changes: 13 additions & 3 deletions src/main/kotlin/busanVibe/busan/domain/festival/domain/Festival.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package busanVibe.busan.domain.festival.domain

import busanVibe.busan.domain.common.BaseEntity
import busanVibe.busan.domain.festival.enums.FestivalStatus
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
Expand All @@ -20,6 +21,9 @@ class Festival (
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@Column(nullable = false, unique = true)
val contentId: Long,

@Column(nullable = false, length = 50)
val name: String,

Expand All @@ -36,7 +40,7 @@ class Festival (
val introduction: String,

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

@Column(nullable = false)
val phone: String,
Expand All @@ -49,15 +53,21 @@ class Festival (
@Column(nullable = false)
val status: FestivalStatus,

@OneToMany(mappedBy = "festival", fetch = FetchType.LAZY)
val festivalImages: Set<FestivalImage>,
@OneToMany(mappedBy = "festival", fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
val festivalImages: MutableSet<FestivalImage> = mutableSetOf(),

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


): BaseEntity(){

fun addFestivalImage(festivalImage: FestivalImage) {
festivalImages.add(festivalImage)
festivalImage.festival = this
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FestivalImage(

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

): BaseEntity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FestivalDetailsDTO {
val endDate: String,
val address: String,
val phone: String,
val fee: Int,
val fee: String,
val siteUrl: String,
val introduce: String
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum class FestivalStatus {
ALL,
IN_PROGRESS,
UPCOMING,
COMPLETE
COMPLETE,
UNKNOWN

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class HomeResponseDTO {
data class MostCongestion(
val placeId: Long?,
val name: String,
val latitude: Double,
val longitude: Double,
val latitude: Double? = null,
val longitude: Double? = null,
val type: String,
val image: String?,
val congestionLevel: Int,
Expand All @@ -31,8 +31,8 @@ class HomeResponseDTO {
val congestionLevel: Int,
val type: String,
val image: String?,
val latitude: Double,
val longitude: Double,
val latitude: Double?,
val longitude: Double?,
val address: String,
@get:JsonProperty("is_liked")
val isLiked: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class HomeQueryService(
HomeResponseDTO.MostCongestion(
placeId = place.id,
name = place.name,
latitude = place.latitude.toDouble(),
longitude = place.longitude.toDouble(),
latitude = place.latitude?.toDouble(),
longitude = place.longitude?.toDouble(),
type = place.type.korean,
image = place.placeImages.firstOrNull()?.imgUrl,
congestionLevel = congestion,
Expand All @@ -71,8 +71,8 @@ class HomeQueryService(
congestionLevel = congestion,
type = place.type.korean,
image = place.placeImages.firstOrNull()?.imgUrl,
latitude = place.latitude.toDouble(),
longitude = place.longitude.toDouble(),
latitude = place.latitude?.toDouble(),
longitude = place.longitude?.toDouble(),
address = place.address,
isLiked = place.placeLikes.any { it.user == currentUser }
)
Expand Down
39 changes: 31 additions & 8 deletions src/main/kotlin/busanVibe/busan/domain/place/domain/Place.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,40 @@ class Place(
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@Column(nullable = false, length = 10)
@Column(nullable = false, unique = true)
val contentId: Long,

@Column(nullable = false, length = 50)
val name: String,

@Column(nullable = false)
@Enumerated(EnumType.STRING)
val type: PlaceType,

@Column(nullable = false)
val latitude: BigDecimal,
val latitude: BigDecimal? = null,

@Column(nullable = false)
val longitude: BigDecimal,
val longitude: BigDecimal? = null,

@Column(nullable = false, length = 50)
val address: String,

@Column(nullable = false, columnDefinition = "TEXT")
val introduction: String,

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

// -----

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

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


// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "region_id", nullable = false)
// val region: Region,
Expand All @@ -56,13 +68,24 @@ class Place(
val placeLikes: Set<PlaceLike>,

@OneToOne(mappedBy = "place", fetch = FetchType.LAZY, optional = true)
val openTime: OpenTime,
val openTime: OpenTime? = null,

@OneToMany(mappedBy="place", fetch = FetchType.LAZY)
val placeImages: Set<PlaceImage>,
@OneToMany(mappedBy = "place", fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
val placeImages: MutableSet<PlaceImage> = mutableSetOf(),

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "visitor_distribution_id")
val visitorDistribution: VisitorDistribution? = null,

) : BaseEntity()
) : BaseEntity(){

fun addImage(imgUrl: String) {
val image = PlaceImage(imgUrl = imgUrl, place = this)
placeImages.add(image)
}

fun removeImage(image: PlaceImage) {
placeImages.remove(image)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.OneToOne

@Entity
//@Entity
class Region(

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class PlaceMapResponseDTO {
val name: String,
val type: String,
val congestionLevel: Int,
val latitude: BigDecimal,
val longitude: BigDecimal
val latitude: BigDecimal? = null,
val longitude: BigDecimal? = null
)

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
Expand All @@ -30,8 +30,8 @@ class PlaceMapResponseDTO {
val congestionLevel: Int,
val grade: Float,
val reviewAmount: Int,
val latitude: BigDecimal,
val longitude: BigDecimal,
val latitude: BigDecimal?,
val longitude: BigDecimal?,
val address: String,
@get:JsonProperty("is_open")
val isOpen: Boolean,
Expand Down
20 changes: 14 additions & 6 deletions src/main/kotlin/busanVibe/busan/domain/place/enums/PlaceType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ import lombok.AllArgsConstructor
@AllArgsConstructor
enum class PlaceType(
val korean: String,
val capitalEnglish: String
val capitalEnglish: String,
val tourApiTypeId: String,
val placeUseTimeColumn: String,
val restDateColumn: String,
) {

ALL("전체", "ALL"),
SIGHT("관광지", "SIGHT"),
RESTAURANT("식당", "RESTAURANT"),
CAFE("카페", "CAFE")
ALL("전체", "ALL", "", "", ""),
SIGHT("관광지", "SIGHT", "12", "useTime", "restDate"),
RESTAURANT("식당", "RESTAURANT", "39", "openTimeFood", "restDateFood"),
CAFE("카페", "CAFE", "00", "openTimeFood", "restDateFood"),
CULTURE("문화시설", "CULTURE", "14", "useTimeCulture", "restDateCulture")
;


companion object{
fun fromTourApiTypeId(code: String): PlaceType? {
return values().find { it.tourApiTypeId == code }
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package busanVibe.busan.domain.place.repository

import busanVibe.busan.domain.place.domain.Place
import org.springframework.jdbc.core.BatchPreparedStatementSetter
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.stereotype.Repository

@Repository
class PlaceJdbcRepository(
private val jdbcTemplate: JdbcTemplate
) {

fun saveAll(places: List<Place>) {
val sql = """
INSERT INTO place (
content_id, name, type, latitude, longitude, address, introduction, phone,
use_time, rest_date, created_at, modified_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""".trimIndent()

jdbcTemplate.batchUpdate(sql, object : BatchPreparedStatementSetter {
override fun getBatchSize(): Int = places.size

override fun setValues(ps: java.sql.PreparedStatement, i: Int) {
val place = places[i]
ps.setLong(1, place.contentId)
ps.setString(2, place.name)
ps.setString(3, place.type.name)
ps.setBigDecimal(4, place.latitude)
ps.setBigDecimal(5, place.longitude)
ps.setString(6, place.address)
ps.setString(7, place.introduction)
ps.setString(8, place.phone)
ps.setString(9, place.useTime)
ps.setString(10, place.restDate)
ps.setTimestamp(11, java.sql.Timestamp.valueOf(place.createdAt))
ps.setTimestamp(12, java.sql.Timestamp.valueOf(place.modifiedAt))
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class SearchQueryService(
typeEn = place.type.capitalEnglish,
id = place.id,
name = place.name,
latitude = place.latitude.toDouble(),
longitude = place.longitude.toDouble(),
latitude = place.latitude?.toDouble(),
longitude = place.longitude?.toDouble(),
address = place.address,
congestionLevel = placeRedisUtil.getRedisCongestion(place.id),
isLiked = place.placeLikes.any { it.user == currentUser },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package busanVibe.busan.domain.tourApi.controller

import busanVibe.busan.domain.place.enums.PlaceType
import busanVibe.busan.domain.tourApi.service.TourCommandService
import io.swagger.v3.oas.annotations.Operation
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/tour-api")
class TourAPIController(
private val tourCommandService: TourCommandService
) {

@PostMapping("/festivals")
// @Operation(hidden = true)
fun saveFestivals(){
tourCommandService.syncFestivalsFromApi()
}

@PostMapping("/place")
fun savePlace(@RequestParam("place-type") placeType: PlaceType ){
tourCommandService.getPlace(placeType)
}


}
Loading