Skip to content

Commit

Permalink
Merge pull request #116 from dnd-side-project/feat/delete_device_token
Browse files Browse the repository at this point in the history
[BLOOM-112] 디바이스 토큰 삭제 구현
  • Loading branch information
stophwan authored Sep 16, 2024
2 parents 8ac0cf4 + 051fc9d commit dfe088e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ interface DeviceTokenApi {
@Schema(hidden = true) user: User,
deviceTokenRequest: DeviceTokenRequest,
): ResponseEntity<Void>

@Operation(summary = "Device Token 삭제 API")
@ApiResponse(responseCode = "204", description = "Device Token 삭제 성공")
fun invalidDeviceToken(
@Schema(hidden = true) user: User,
): ResponseEntity<Void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ class DeviceTokenController(
deviceTokenService.saveToken(user, deviceTokenRequest.deviceToken)
return ResponseEntity.noContent().build()
}

@Secured
@PostMapping("/invalid")
override fun invalidDeviceToken(
@LoginUser user: User,
): ResponseEntity<Void> {
deviceTokenService.invalidToken(user)
return ResponseEntity.noContent().build()
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package dnd11th.blooming.api.service.user

import dnd11th.blooming.domain.entity.devicetoken.DeviceToken
import dnd11th.blooming.domain.entity.user.User
import dnd11th.blooming.domain.repository.devicetoken.DeviceTokenRepository
import dnd11th.blooming.domain.repository.user.UserRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional
class DeviceTokenService(
private val deviceTokenRepository: DeviceTokenRepository,
private val userRepository: UserRepository,
) {
fun saveToken(
loginUser: User,
token: String,
) {
val newToken = DeviceToken.create(loginUser, token)
deviceTokenRepository.save(newToken)
loginUser.updateDeviceToken(token)
userRepository.save(loginUser)
}

fun invalidToken(loginUser: User) {
loginUser.invalidDeviceToken()
userRepository.save(loginUser)
}
}

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/kotlin/dnd11th/blooming/domain/entity/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class User(
var ny: Int = ny
protected set

var deviceToken: String? = null

companion object {
fun create(
email: String,
Expand All @@ -67,4 +69,12 @@ class User(
fun updateAlarmTime(alarmTime: AlarmTime) {
this.alarmTime = alarmTime
}

fun updateDeviceToken(newToken: String) {
this.deviceToken = newToken
}

fun invalidDeviceToken() {
this.deviceToken = null
}
}

This file was deleted.

0 comments on commit dfe088e

Please sign in to comment.