-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
6 changes: 6 additions & 0 deletions
6
backend/application/api/src/main/kotlin/io/raemian/api/goal/event/CreateGoalEvent.kt
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 io.raemian.api.goal.event | ||
|
||
data class CreateGoalEvent( | ||
val goalId: Long, | ||
val lifeMapId: Long, | ||
) |
32 changes: 32 additions & 0 deletions
32
backend/application/api/src/main/kotlin/io/raemian/api/goal/event/GoalEventHandler.kt
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,32 @@ | ||
package io.raemian.api.goal.event | ||
|
||
import io.raemian.storage.db.core.goal.GoalRepository | ||
import io.raemian.storage.db.core.lifemap.LifeMapCount | ||
import io.raemian.storage.db.core.lifemap.LifeMapCountRepository | ||
import io.raemian.storage.db.core.lifemap.LifeMapRepository | ||
import jakarta.transaction.Transactional | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class GoalEventHandler( | ||
private val lifeMapCountRepository: LifeMapCountRepository, | ||
private val goalRepository: GoalRepository, | ||
private val lifeMapRepository: LifeMapRepository, | ||
) { | ||
private val log = LoggerFactory.getLogger(javaClass) | ||
|
||
@Transactional | ||
@EventListener | ||
fun addGoalCount(createGoalEvent: CreateGoalEvent) { | ||
// TODO goal 테이블에서 life map 기준으로 전체 count 한 값으로 업데이트 | ||
val mapCount = lifeMapCountRepository.findByLifeMapId(createGoalEvent.lifeMapId) | ||
?: LifeMapCount.of(createGoalEvent.lifeMapId) | ||
|
||
val added = mapCount.addGoalCount() | ||
|
||
lifeMapCountRepository.save(added) | ||
log.info("life map id: ${createGoalEvent.lifeMapId}, added goal count : ${added.goalCount}") | ||
} | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
backend/application/api/src/main/kotlin/io/raemian/api/lifemap/domain/CountResponse.kt
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,19 @@ | ||
package io.raemian.api.lifemap.domain | ||
|
||
import io.raemian.api.cheer.controller.response.CheeringCountResponse | ||
|
||
data class CountResponse( | ||
val view: Long, | ||
val cheering: Long, | ||
val history: Long? = null, | ||
) { | ||
constructor(lifeMapCountDTO: LifeMapCountDTO, cheeringCount: Long) : this( | ||
view = lifeMapCountDTO.viewCount, | ||
cheering = cheeringCount, | ||
history = lifeMapCountDTO.historyCount, | ||
) | ||
constructor(viewCount: Long, cheeringCountResponse: CheeringCountResponse) : this( | ||
view = viewCount, | ||
cheering = cheeringCountResponse.count, | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/application/api/src/main/kotlin/io/raemian/api/lifemap/domain/ExploreDTO.kt
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,17 @@ | ||
package io.raemian.api.lifemap.domain | ||
|
||
import io.raemian.api.user.domain.UserSubset | ||
|
||
data class ExploreDTO( | ||
val lifeMapId: Long, | ||
val goals: List<GoalDto>, | ||
val count: LifeMapCountDTO, | ||
val user: UserSubset?, | ||
) { | ||
constructor(lifeMapDTO: LifeMapDTO, lifeMapCountDTO: LifeMapCountDTO) : this( | ||
lifeMapId = lifeMapDTO.lifeMapId, | ||
goals = lifeMapDTO.goals, | ||
count = lifeMapCountDTO, | ||
user = lifeMapDTO.user, | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/application/api/src/main/kotlin/io/raemian/api/lifemap/domain/ExploreResponse.kt
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 io.raemian.api.lifemap.domain | ||
|
||
import io.raemian.api.user.domain.UserSubset | ||
|
||
data class ExploreResponse( | ||
val lifeMapId: Long, | ||
val goals: List<GoalDto>, | ||
val count: CountResponse, | ||
val user: UserSubset?, | ||
) { | ||
|
||
constructor(exploreDTO: ExploreDTO) : this( | ||
lifeMapId = exploreDTO.lifeMapId, | ||
goals = exploreDTO.goals, | ||
user = exploreDTO.user, | ||
count = CountResponse(exploreDTO.count, 0), | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/application/api/src/main/kotlin/io/raemian/api/lifemap/domain/ExploreResponses.kt
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 io.raemian.api.lifemap.domain | ||
|
||
data class ExploreResponses( | ||
val lifeMaps: List<ExploreResponse>, | ||
val cursor: Cursor, | ||
) { | ||
constructor(exploreDTOs: List<ExploreDTO>) : this( | ||
lifeMaps = exploreDTOs.map { ExploreResponse(it) }, | ||
cursor = Cursor(exploreDTOs), | ||
) | ||
|
||
data class Cursor( | ||
val next: Long, | ||
// val prev: Long | ||
) { | ||
constructor(exploreDTOs: List<ExploreDTO>) : this( | ||
next = exploreDTOs.lastOrNull()?.lifeMapId ?: Long.MIN_VALUE, | ||
// prev = exploreDTOs.firstOrNull()?.lifeMapId ?: Long.MAX_VALUE | ||
) | ||
} | ||
} |
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
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
3 changes: 3 additions & 0 deletions
3
backend/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/goal/GoalRepository.kt
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package io.raemian.storage.db.core.goal | ||
|
||
import io.raemian.storage.db.core.lifemap.LifeMap | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.time.LocalDateTime | ||
|
||
interface GoalRepository : JpaRepository<Goal, Long> { | ||
fun findUserByCreatedAtGreaterThanEqual(createdAt: LocalDateTime): List<Goal> | ||
|
||
fun countGoalByLifeMap(lifeMap: LifeMap): Int | ||
|
||
override fun getById(id: Long): Goal = | ||
findById(id).orElseThrow() { NoSuchElementException("목표가 없습니다 $id") } | ||
} |
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
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
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
25 changes: 25 additions & 0 deletions
25
...d/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/lifemap/LifeMapRepository.kt
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 |
---|---|---|
@@ -1,10 +1,35 @@ | ||
package io.raemian.storage.db.core.lifemap | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.data.repository.query.Param | ||
|
||
interface LifeMapRepository : JpaRepository<LifeMap, Long> { | ||
|
||
fun findFirstByUserId(userId: Long): LifeMap? | ||
|
||
fun findFirstByUserUsername(username: String): LifeMap? | ||
|
||
fun findAllByIdInOrderByIdDesc(ids: List<Long>): List<LifeMap> | ||
|
||
@Query( | ||
""" | ||
SELECT | ||
map.id | ||
FROM | ||
LifeMap as map, | ||
LifeMapCount as count | ||
WHERE 1 = 1 | ||
AND map.id = count.lifeMapId | ||
AND count.goalCount > 2 | ||
AND map.id < :cursor | ||
AND map.isPublic = true | ||
ORDER BY | ||
map.id DESC | ||
LIMIT 5 | ||
""", | ||
) | ||
fun explore( | ||
@Param("cursor") lifeMapId: Long, | ||
): List<Long> | ||
} |