Skip to content

Commit

Permalink
Merge pull request #142 from mash-up-kr/fix/jpa-id-type
Browse files Browse the repository at this point in the history
fix: Jpa ID Type Error
  • Loading branch information
K-Diger authored Aug 12, 2024
2 parents d902c5f + 195da66 commit eb0d501
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class Place(
val origin: Origin,
val memo: String?,
val confirmed: Boolean,
val reviewCount: Int?,
val longitude: Double?,
val latitude: Double?,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ data class AddPlaceRequest(
@field:PositiveOrZero(message = "싫어요 수는 0 이상이어야 합니다.")
@field:Schema(description = "싫어요 수", example = "2")
val voteDislikeCount: Short?,
@field:PositiveOrZero(message = "리뷰 수는 0 이상이어야 합니다.")
@field:Schema(description = "리뷰 수", example = "2")
val reviewCount: Int? = 0,
@field:Schema(description = "장소 위치 경도", example = "126.9246033")
val longitude: Double?,
@field:Schema(description = "장소 위치 위도", example = "33.45241976")
Expand All @@ -74,6 +77,7 @@ data class AddPlaceRequest(
origin = Origin.MANUAL,
memo = memo,
confirmed = false,
reviewCount = reviewCount,
longitude = longitude,
latitude = latitude,
)
Expand Down Expand Up @@ -117,6 +121,8 @@ data class ModifyPlaceRequest(
@field:PositiveOrZero(message = "싫어요 수는 0 이상이어야 합니다.")
@field:Schema(description = "싫어요 수", example = "2")
val voteDislikeCount: Short?,
@field:Schema(description = "리뷰 개수", example = "100")
val reviewCount: Int? = 0,
@field:Schema(description = "장소 위치 경도", example = "126.9246033")
val longitude: Double?,
@field:Schema(description = "장소 위치 위도", example = "33.45241976")
Expand All @@ -141,6 +147,7 @@ data class ModifyPlaceRequest(
origin = Origin.MANUAL,
memo = memo,
confirmed = false,
reviewCount = reviewCount,
longitude = longitude,
latitude = latitude,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class VoteSaveRequest(
return this.votes
.map {
Vote(
id = LongTypeId(null),
id = LongTypeId(0L),
userUid = UuidTypeId(userUid),
placeId = LongTypeId(it.placeId),
result = it.voteResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ data class PlaceResponse(
val origin: Origin,
@field:Schema(description = "메모", example = "여기 가보자잇")
val memo: String?,
@field:Schema(description = "투표되었나?", example = "false")
var confirmed: Boolean,
@field:Schema(description = "리뷰 개수", example = "100")
val reviewCount: Int? = 0,
) {
constructor(place: Place) : this(
id = place.id.getValue(),
Expand All @@ -46,6 +50,8 @@ data class PlaceResponse(
starGrade = place.starGrade,
origin = place.origin,
memo = place.memo,
confirmed = place.confirmed,
reviewCount = place.reviewCount,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class CourseServiceTest {
scheduleId = schedules[0].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -179,6 +180,7 @@ class CourseServiceTest {
scheduleId = schedules[0].id,
memo = null,
confirmed = true,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -195,6 +197,7 @@ class CourseServiceTest {
scheduleId = schedules[1].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -211,6 +214,7 @@ class CourseServiceTest {
scheduleId = schedules[1].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -227,6 +231,7 @@ class CourseServiceTest {
scheduleId = schedules[1].id,
memo = null,
confirmed = true,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -243,6 +248,7 @@ class CourseServiceTest {
scheduleId = schedules[2].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -259,6 +265,7 @@ class CourseServiceTest {
scheduleId = schedules[2].id,
memo = null,
confirmed = true,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -275,6 +282,7 @@ class CourseServiceTest {
scheduleId = schedules[3].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -291,6 +299,7 @@ class CourseServiceTest {
scheduleId = schedules[3].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -307,6 +316,7 @@ class CourseServiceTest {
scheduleId = schedules[3].id,
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand Down Expand Up @@ -405,6 +415,7 @@ class CourseServiceTest {
scheduleId = schedules[0].id,
memo = null,
confirmed = true,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -421,6 +432,7 @@ class CourseServiceTest {
scheduleId = schedules[1].id,
memo = null,
confirmed = true,
reviewCount = 0,
longitude = null,
latitude = null,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(0L),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
)
Expand Down Expand Up @@ -165,6 +166,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(0L),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -181,6 +183,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(0L),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand Down Expand Up @@ -232,6 +235,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(0),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -248,6 +252,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(0),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand Down Expand Up @@ -297,6 +302,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(1),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -313,6 +319,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(2),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand All @@ -329,6 +336,7 @@ class VoteServiceTest {
scheduleId = LongTypeId(2),
memo = null,
confirmed = false,
reviewCount = 0,
longitude = 126.9246033,
latitude = 33.45241976,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PlaceAdapter(
place: Place,
): Place {
val placeEntity =
placeRepository.findByIdOrNull(targetPlaceId) ?: throw PiikiiException(
placeRepository.findByIdOrNull(targetPlaceId.getValue()) ?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "targetPlaceId : $targetPlaceId",
)
Expand All @@ -49,30 +49,30 @@ class PlaceAdapter(

@Transactional
override fun delete(targetPlaceId: LongTypeId) {
placeRepository.findByIdOrNull(targetPlaceId) ?: throw PiikiiException(
placeRepository.findByIdOrNull(targetPlaceId.getValue()) ?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "targetPlaceId : $targetPlaceId",
)
placeRepository.deleteById(targetPlaceId)
placeRepository.deleteById(targetPlaceId.getValue())
}

override fun findByPlaceId(placeId: LongTypeId): Place {
return placeRepository.findByIdOrNull(placeId)?.toDomain() ?: throw PiikiiException(
return placeRepository.findByIdOrNull(placeId.getValue())?.toDomain() ?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "placeId : $placeId",
)
}

override fun findAllByPlaceIds(placeIds: List<LongTypeId>): List<Place> {
return placeRepository.findAllById(placeIds).map { it.toDomain() }
return placeRepository.findAllById(placeIds.map { it.getValue() }).map { it.toDomain() }
}

override fun findAllByRoomUid(roomUid: UuidTypeId): List<Place> {
return placeRepository.findAllByRoomUid(roomUid).map { it.toDomain() }
}

override fun findConfirmedByScheduleId(scheduleId: LongTypeId): Place? {
val places = placeRepository.findByScheduleIdAndConfirmed(scheduleId, true)
val places = placeRepository.findByScheduleIdAndConfirmed(scheduleId.getValue(), true)
return places.singleOrNull()?.toDomain()
?: throw PiikiiException(
exceptionCode = ExceptionCode.ACCESS_DENIED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class RoomAdapter(

@Transactional
override fun delete(roomUid: UuidTypeId) {
roomRepository.deleteByroomUid(roomUid)
roomRepository.deleteByroomUid(roomUid.getValue())
}

override fun findById(roomUid: UuidTypeId): Room {
return findByRoomUid(roomUid).toDomain()
}

private fun findByRoomUid(roomUid: UuidTypeId): RoomEntity {
return roomRepository.findByroomUid(roomUid)
return roomRepository.findByroomUid(roomUid.getValue())
?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "roomUid: $roomUid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ class ScheduleAdapter(
}

override fun findAllByRoomUid(roomUid: UuidTypeId): List<Schedule> {
return scheduleRepository.findByroomUidOrderBySequenceAsc(roomUid).map { it.toDomain() }
return scheduleRepository.findByroomUidOrderBySequenceAsc(roomUid.getValue()).map { it.toDomain() }
}

override fun findScheduleById(id: LongTypeId): Schedule {
return scheduleRepository.findByIdOrNull(id)?.toDomain()
return scheduleRepository.findByIdOrNull(id.getValue())?.toDomain()
?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "Schedule ID: $id",
)
}

private fun findScheduleEntityById(id: LongTypeId): ScheduleEntity {
return scheduleRepository.findByIdOrNull(id)
return scheduleRepository.findByIdOrNull(id.getValue())
?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "Schedule ID: $id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VoteAdapter(
}

override fun findAllByPlaceIds(placeIds: List<LongTypeId>): List<Vote> {
return voteRepository.findAllByPlaceIdIn(placeIds).map { it.toDomain() }
return voteRepository.findAllByPlaceIdIn(placeIds.map { it.getValue() }).map { it.toDomain() }
}

override fun findAgreeCountByPlaceId(votes: List<Vote>): Map<Long, Int> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.piikii.output.persistence.postgresql.persistence.common

import com.piikii.application.domain.generic.LongTypeId
import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.GeneratedValue
Expand All @@ -20,7 +19,7 @@ abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
val id: LongTypeId = LongTypeId(0L)
val id: Long = 0L

@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piikii.output.persistence.postgresql.persistence.entity

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.ThumbnailLinks
import com.piikii.application.domain.place.Origin
import com.piikii.application.domain.place.OriginMapId
Expand Down Expand Up @@ -48,7 +49,7 @@ class OriginPlaceEntity(
) : BaseEntity() {
fun toDomain(): OriginPlace {
return OriginPlace(
id = id,
id = LongTypeId(id),
originMapId = originMapId,
name = name,
url = url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class PlaceEntity(
var memo: String?,
@Column(name = "confirmed", nullable = false)
var confirmed: Boolean = false,
@Column(name = "review_count", nullable = false)
val reviewCount: Int?,
@Column(name = "longitude")
val longitude: Double?,
@Column(name = "latitude")
Expand All @@ -61,13 +63,14 @@ class PlaceEntity(
origin = place.origin,
memo = place.memo,
confirmed = place.confirmed,
reviewCount = place.reviewCount,
longitude = place.longitude,
latitude = place.latitude,
)

fun toDomain(): Place {
return Place(
id = id,
id = LongTypeId(id),
roomUid = roomUid,
scheduleId = scheduleId,
name = name,
Expand All @@ -79,6 +82,7 @@ class PlaceEntity(
origin = origin,
memo = memo,
confirmed = confirmed,
reviewCount = reviewCount,
longitude = longitude,
latitude = latitude,
)
Expand Down
Loading

0 comments on commit eb0d501

Please sign in to comment.