File tree Expand file tree Collapse file tree 8 files changed +66
-0
lines changed
apis/src/main/kotlin/org/yapp/apis/test
domain/src/main/kotlin/org/yapp/domain
infra/src/main/kotlin/org/yapp/infra/device Expand file tree Collapse file tree 8 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ package org.yapp.apis.test.controller
2+
3+ import org.springframework.security.core.annotation.AuthenticationPrincipal
4+ import org.springframework.web.bind.annotation.PathVariable
5+ import org.springframework.web.bind.annotation.PutMapping
6+ import org.springframework.web.bind.annotation.RequestMapping
7+ import org.springframework.web.bind.annotation.RequestParam
8+ import org.springframework.web.bind.annotation.RestController
9+ import org.yapp.apis.test.service.TestService
10+ import java.util.UUID
11+
12+ @RestController
13+ @RequestMapping(" /api/v1/test" )
14+ class TestController (
15+ private val testService : TestService
16+ ) {
17+ // Endpoints for testing with authenticated user (userId from @AuthenticationPrincipal)
18+ @PutMapping(" /authenticated-user/last-activity/{days}-days-ago" )
19+ fun setLastActivityForAuthenticatedUser (
20+ @AuthenticationPrincipal userId : UUID ,
21+ @PathVariable days : Int
22+ ) {
23+ testService.updateLastActivityByUserId(userId, days)
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package org.yapp.apis.test.service
2+
3+ import org.springframework.stereotype.Service
4+ import org.yapp.domain.user.UserDomainService
5+ import java.time.LocalDateTime
6+ import java.util.UUID
7+
8+ @Service
9+ class TestService (
10+ private val userDomainService : UserDomainService ,
11+ ) {
12+
13+ fun updateLastActivityByUserId (userId : UUID , days : Int ) {
14+ val newLastActivity = LocalDateTime .now().minusDays(days.toLong())
15+ userDomainService.forceUpdateLastActivity(userId, newLastActivity)
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ class DeviceDomainService(
2121 .map { DeviceVO .from(it) }
2222 }
2323
24+ fun findDeviceByFcmToken (fcmToken : String ): DeviceVO ? {
25+ return deviceRepository.findByFcmToken(fcmToken)
26+ ?.let { DeviceVO .from(it) }
27+ }
28+
2429 fun removeDevicesByTokens (tokens : List <String >) {
2530 if (tokens.isNotEmpty()) {
2631 deviceRepository.deleteByTokens(tokens)
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import java.util.UUID
44
55interface DeviceRepository {
66 fun findByDeviceId (deviceId : String ): Device ?
7+ fun findByFcmToken (fcmToken : String ): Device ?
78 fun save (device : Device ): Device
89 fun findByUserId (userId : UUID ): List <Device >
910 fun deleteByTokens (tokens : List <String >)
Original file line number Diff line number Diff line change @@ -54,6 +54,12 @@ data class User private constructor(
5454 )
5555 }
5656
57+ fun forceUpdateLastActivity (newLastActivity : LocalDateTime ): User {
58+ return this .copy(
59+ lastActivity = newLastActivity
60+ )
61+ }
62+
5763 companion object {
5864 fun create (
5965 email : String ,
Original file line number Diff line number Diff line change @@ -127,6 +127,13 @@ class UserDomainService(
127127 }
128128 }
129129
130+ fun forceUpdateLastActivity (userId : UUID , newLastActivity : LocalDateTime ) {
131+ val user = userRepository.findById(userId)
132+ ? : throw UserNotFoundException (UserErrorCode .USER_NOT_FOUND )
133+
134+ userRepository.save(user.forceUpdateLastActivity(newLastActivity))
135+ }
136+
130137 fun updateNotificationSettings (userId : UUID , notificationEnabled : Boolean ): UserProfileVO {
131138 val user = userRepository.findById(userId)
132139 ? : throw UserNotFoundException (UserErrorCode .USER_NOT_FOUND )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import java.util.UUID
88
99interface DeviceJpaRepository : JpaRepository <DeviceEntity , UUID > {
1010 fun findByDeviceId (deviceId : String ): DeviceEntity ?
11+ fun findByFcmToken (fcmToken : String ): DeviceEntity ?
1112 fun findByUserId (userId : UUID ): List <DeviceEntity >
1213
1314 @Modifying(clearAutomatically = true )
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ class DeviceRepositoryImpl(
1414 return deviceJpaRepository.findByDeviceId(deviceId)?.toDomain()
1515 }
1616
17+ override fun findByFcmToken (fcmToken : String ): Device ? {
18+ return deviceJpaRepository.findByFcmToken(fcmToken)?.toDomain()
19+ }
20+
1721 override fun save (device : Device ): Device {
1822 return deviceJpaRepository.save(DeviceEntity .fromDomain(device)).toDomain()
1923 }
You can’t perform that action at this time.
0 commit comments