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 @@ -22,7 +22,6 @@ abstract class PrimaryKeyEntity {
@Column(nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now()

@LastModifiedDate
@Column(nullable = false)
var lastModifiedAt: LocalDateTime = LocalDateTime.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class Article(
this.type = type
this.category = category
this.isLocationVisible = isLocationVisible
lastModifiedAt = LocalDateTime.now()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import jakarta.persistence.ForeignKey
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import java.time.LocalDateTime

@Entity
@Table(name = "`comment`")
Expand Down Expand Up @@ -59,6 +60,7 @@ class Comment(
fun modifyComment(body: String): Comment {
return this.apply {
this.body = body
lastModifiedAt = LocalDateTime.now()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ interface HomeApiV1 {
fun getStatus(): ApiResult<GetStatusResponse>

@GetMapping("/shelters/{type}")
@Operation(summary = "(재난 발생 시) 홈 대피소 피드 조회", description = "대피소 목록을 조회합니다.")
@Operation(summary = "(재난 발생 시) 홈 대피소 피드 조회", description = """
대피소 목록을 조회합니다.
""")
fun getShelters(
@Schema(
description = "대피소 유형 (temperature | earthquake | tsunami | civil)",
description = "대피소 유형 (all | temperature | earthquake | tsunami | civil)",
example = "temperature"
) @PathVariable type: String,
): ApiResult<GetNearbySheltersResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ interface ShelterApiV1 {
summary = "주변 대피소 목록 조회",
description = """
사용자의 주변 대피소 목록을 조회합니다.
쿼리 파라미터로 대피소 유형을 지정해주세요. (temperature: 쉼터, earthquake: 지진, tsunami: 지진해일, civil: 민방위)
쿼리 파라미터로 대피소 유형을 지정해주세요. (all: 전체, temperature: 쉼터, earthquake: 지진, tsunami: 지진해일, civil: 민방위)
이 api 호출 이전에 gps 정보 업데이트 api를 통해 사용자의 위치 정보를 업데이트 해주세요.
"""
)
fun getNearbyShelters(
@Schema(
description = "대피소 유형 (temperature | earthquake | tsunami | civil)",
description = "대피소 유형 (all | temperature | earthquake | tsunami | civil)",
example = "temperature"
) @PathVariable type: String,
): ApiResult<GetNearbySheltersResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class GetNearbySheltersResponse(
it.latitude
)
)
}
}.distinctBy { it.name }.take(10)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ interface ShelterRepository : JpaRepository<Shelter, Long> {
@Param("latitude") latitude: Double,
@Param("type") type: String
): List<Shelter>

@Query(
value = "SELECT id, name, latitude, longitude, address, type " +
"FROM shelter " +
"ORDER BY (6371 * ACOS(COS(RADIANS(:latitude)) * COS(RADIANS(latitude)) * " +
"COS(RADIANS(longitude) - RADIANS(:longitude)) + " +
"SIN(RADIANS(:latitude)) * SIN(RADIANS(latitude)))) " +
"LIMIT 20",
nativeQuery = true
)
fun findTop20ClosestAllShelters(
@Param("longitude") longitude: Double,
@Param("latitude") latitude: Double,
): List<Shelter>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.numberone.daepiro.domain.shelter.service

import com.numberone.daepiro.domain.shelter.dto.response.GetNearbySheltersResponse
import com.numberone.daepiro.domain.shelter.entity.Shelter
import com.numberone.daepiro.domain.shelter.entity.ShelterType
import com.numberone.daepiro.domain.shelter.repository.ShelterRepository
import com.numberone.daepiro.domain.user.repository.UserRepository
Expand All @@ -26,7 +27,12 @@ class ShelterService(
val longitude = user.longitude!!
val latitude = user.latitude!!

val shelters = shelterRepository.findTop10ClosestShelters(longitude, latitude, ShelterType.word2code(type).name)
var shelters = emptyList<Shelter>()
if (type == "all") {
shelters = shelterRepository.findTop20ClosestAllShelters(longitude, latitude)
} else {
shelters = shelterRepository.findTop10ClosestShelters(longitude, latitude, ShelterType.word2code(type).name)
}
return ApiResult.ok(
GetNearbySheltersResponse.of(
address.toFullAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import jakarta.persistence.FetchType
import jakarta.persistence.ForeignKey
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import java.time.LocalDateTime

@Entity
class Cheering(
Expand All @@ -31,5 +32,6 @@ class Cheering(

fun updateContent(content: String) {
this.content = content
lastModifiedAt = LocalDateTime.now()
}
}
Loading