Skip to content

Commit f55eaa3

Browse files
committed
hotfix: apis,domain,infra - test api
1 parent a9260f5 commit f55eaa3

File tree

8 files changed

+66
-0
lines changed

8 files changed

+66
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

domain/src/main/kotlin/org/yapp/domain/device/DeviceDomainService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

domain/src/main/kotlin/org/yapp/domain/device/DeviceRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.util.UUID
44

55
interface 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>)

domain/src/main/kotlin/org/yapp/domain/user/User.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

domain/src/main/kotlin/org/yapp/domain/user/UserDomainService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

infra/src/main/kotlin/org/yapp/infra/device/DeviceJpaRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.util.UUID
88

99
interface 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)

infra/src/main/kotlin/org/yapp/infra/device/DeviceRepositoryImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)