Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: (#264) 디바이스 토큰 저장 #266

Merged
merged 7 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: CD for Stage
name: CD for Dev

on:
push:
branches:
- main
- develop

jobs:
build:
environment: stage
environment: dev
runs-on: ubuntu-latest

steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.comit.simtong.domain.user.dto

/**
*
* 관리자의 로그인을 정보를 전달하는 AdminSignInRequest
*
* @author kimbeomjin
* @date 2023/01/01
* @version 1.1.0
**/
data class AdminSignInRequest(
val employeeNumber: Int,

val password: String
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ data class SignUpRequest(

val employeeNumber: Int,

val profileImagePath: String?
val profileImagePath: String?,

val deviceToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.comit.simtong.domain.user.dto

/**
*
* 일반 사용자의 로그인을 정보를 전달하는 UserSignInRequest
*
* @author kimbeomjin
* @date 2022/09/08
* @version 1.0.0
**/
data class UserSignInRequest(
val employeeNumber: Int,

val password: String,

val deviceToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.comit.simtong.domain.user.spi

import team.comit.simtong.domain.user.model.DeviceToken

/**
*
* DeviceToken Domain에 관한 명령을 하는 CommandDeviceTokenPort
*
* @author kimbeomjin
* @date 2022/12/31
* @version 1.1.0
**/
interface CommandDeviceTokenPort {

fun save(deviceToken: DeviceToken): DeviceToken

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
* @date 2022/09/18
* @version 1.0.0
**/
interface UserPort : QueryUserPort, CommandUserPort, MenuQueryUserPort, ScheduleQueryUserPort, HolidayQueryUserPort, NotificationQueryUserPort
interface UserPort : QueryUserPort, CommandUserPort, CommandDeviceTokenPort, MenuQueryUserPort, ScheduleQueryUserPort, HolidayQueryUserPort, NotificationQueryUserPort
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team.comit.simtong.domain.user.usecase

import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.user.dto.SignInRequest
import team.comit.simtong.domain.user.dto.AdminSignInRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.spi.QueryUserPort
Expand All @@ -24,7 +24,7 @@ class AdminSignInUseCase(
private val securityPort: UserSecurityPort
) {

fun execute(request: SignInRequest): TokenResponse {
fun execute(request: AdminSignInRequest): TokenResponse {
val admin = queryUserPort.queryUserByEmployeeNumber(request.employeeNumber)
?: throw UserExceptions.NotFound("관리자가 존재하지 않습니다.")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package team.comit.simtong.domain.user.usecase

import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.user.dto.SignInRequest
import team.comit.simtong.domain.user.dto.UserSignInRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.DeviceToken
import team.comit.simtong.domain.user.spi.CommandDeviceTokenPort
import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserJwtPort
import team.comit.simtong.domain.user.spi.UserSecurityPort
Expand All @@ -21,10 +23,11 @@ import team.comit.simtong.global.annotation.UseCase
class SignInUseCase(
private val queryUserPort: QueryUserPort,
private val userSecurityPort: UserSecurityPort,
private val userJwtPort: UserJwtPort
private val userJwtPort: UserJwtPort,
private val commandDeviceTokenPort: CommandDeviceTokenPort
) {

fun execute(request: SignInRequest): TokenResponse {
fun execute(request: UserSignInRequest): TokenResponse {
val user = queryUserPort.queryUserByEmployeeNumber(request.employeeNumber)
?: throw UserExceptions.NotFound()

Expand All @@ -36,6 +39,13 @@ class SignInUseCase(
throw UserExceptions.DifferentPassword()
}

commandDeviceTokenPort.save(
DeviceToken(
userId = user.id,
token = request.deviceToken
)
)

return userJwtPort.receiveToken(
userId = user.id,
authority = Authority.ROLE_COMMON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import team.comit.simtong.domain.team.exception.TeamExceptions
import team.comit.simtong.domain.user.dto.SignUpRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.DeviceToken
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.CommandDeviceTokenPort
import team.comit.simtong.domain.user.spi.CommandUserPort
import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserCommandAuthCodeLimitPort
Expand All @@ -33,6 +35,7 @@ import team.comit.simtong.global.annotation.UseCase
class SignUpUseCase(
private val jwtPort: UserJwtPort,
private val commandUserPort: CommandUserPort,
private val commandDeviceTokenPort: CommandDeviceTokenPort,
private val queryUserPort: QueryUserPort,
private val queryAuthCodeLimitPort: UserQueryAuthCodeLimitPort,
private val commandAuthCodeLimitPort: UserCommandAuthCodeLimitPort,
Expand Down Expand Up @@ -88,6 +91,13 @@ class SignUpUseCase(

commandAuthCodeLimitPort.delete(authCodeLimit)

commandDeviceTokenPort.save(
DeviceToken(
userId = user.id,
token = request.deviceToken
)
)

return jwtPort.receiveToken(
userId = user.id,
authority = user.authority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.jupiter.api.assertThrows
import org.mockito.BDDMockito.given
import org.springframework.boot.test.mock.mockito.MockBean
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.user.dto.SignInRequest
import team.comit.simtong.domain.user.dto.AdminSignInRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
Expand Down Expand Up @@ -64,8 +64,8 @@ class AdminSignInUseCaseTests {
)
}

private val requestStub: SignInRequest by lazy {
SignInRequest(
private val requestStub: AdminSignInRequest by lazy {
AdminSignInRequest(
employeeNumber = employeeNumber,
password = "test password"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import org.junit.jupiter.api.assertThrows
import org.mockito.BDDMockito.given
import org.springframework.boot.test.mock.mockito.MockBean
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.user.dto.SignInRequest
import team.comit.simtong.domain.user.dto.UserSignInRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.CommandDeviceTokenPort
import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserJwtPort
import team.comit.simtong.domain.user.spi.UserSecurityPort
Expand All @@ -30,6 +31,9 @@ class SignInUseCaseTests {
@MockBean
private lateinit var userJwtPort: UserJwtPort

@MockBean
private lateinit var commandDeviceTokenPort: CommandDeviceTokenPort

private lateinit var signInUseCase: SignInUseCase

private val employeeNumber: Int = 1234567891
Expand Down Expand Up @@ -64,10 +68,11 @@ class SignInUseCaseTests {
)
}

private val requestStub: SignInRequest by lazy {
SignInRequest(
private val requestStub: UserSignInRequest by lazy {
UserSignInRequest(
employeeNumber = employeeNumber,
password = "test password"
password = "test password",
deviceToken = "test device token"
)
}

Expand All @@ -81,7 +86,7 @@ class SignInUseCaseTests {

@BeforeEach
fun setUp() {
signInUseCase = SignInUseCase(queryUserPort, userSecurityPort, userJwtPort)
signInUseCase = SignInUseCase(queryUserPort, userSecurityPort, userJwtPort, commandDeviceTokenPort)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import team.comit.simtong.domain.user.dto.SignUpRequest
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.CommandDeviceTokenPort
import team.comit.simtong.domain.user.spi.CommandUserPort
import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserCommandAuthCodeLimitPort
Expand All @@ -41,6 +42,9 @@ class SignUpUseCaseTests {
@MockBean
private lateinit var commandUserPort: CommandUserPort

@MockBean
private lateinit var commandDeviceTokenPort: CommandDeviceTokenPort

@MockBean
private lateinit var userSecurityPort: UserSecurityPort

Expand Down Expand Up @@ -134,7 +138,8 @@ class SignUpUseCaseTests {
email = email,
password = "test password",
employeeNumber = employeeNumber,
profileImagePath = profileImagePath
profileImagePath = profileImagePath,
deviceToken = "test device token"
)
}

Expand All @@ -151,6 +156,7 @@ class SignUpUseCaseTests {
signUpUseCase = SignUpUseCase(
userJwtPort,
commandUserPort,
commandDeviceTokenPort,
queryUserPort,
userQueryAuthCodeLimitPort,
commandAuthCodeLimitPort,
Expand Down Expand Up @@ -222,7 +228,8 @@ class SignUpUseCaseTests {
email = email,
password = "test password",
employeeNumber = employeeNumber,
profileImagePath = null
profileImagePath = null,
deviceToken = "test device token"
)

val userStub = User(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package team.comit.simtong.domain.user.model

import java.util.UUID

/**
*
* User Aggregate의 디바이스 토큰 관리를 담당하는 DeviceToken
*
* @author kimbeomjin
* @date 2023/01/01
* @version 1.1.0
**/
data class DeviceToken(
val userId: UUID,
val token: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class SecurityConfig(
.antMatchers(HttpMethod.POST, "/admins/tokens").permitAll()
.antMatchers(HttpMethod.GET, "/admins/information").hasAnyRole(ROLE_ADMIN.role, ROLE_SUPER.role)

// notifications
.antMatchers(HttpMethod.POST, "/notifications").permitAll()
.antMatchers(HttpMethod.POST, "/notifications/list").permitAll()

.anyRequest().authenticated()

http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package team.comit.simtong.persistence.user

import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Component
import team.comit.simtong.domain.user.model.DeviceToken
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.domain.user.spi.UserPort
import team.comit.simtong.persistence.user.mapper.DeviceTokenMapper
import team.comit.simtong.persistence.user.mapper.UserMapper
import team.comit.simtong.persistence.user.repository.DeviceTokenJpaRepository
import team.comit.simtong.persistence.user.repository.UserJpaRepository
Expand All @@ -22,6 +24,7 @@ import java.util.UUID
class UserPersistenceAdapter(
private val userMapper: UserMapper,
private val userJpaRepository: UserJpaRepository,
private val deviceTokenMapper: DeviceTokenMapper,
private val deviceTokenRepository: DeviceTokenJpaRepository
) : UserPort {

Expand Down Expand Up @@ -77,6 +80,12 @@ class UserPersistenceAdapter(
).let { userMapper.toDomain(it)!! }
}

override fun save(deviceToken: DeviceToken): DeviceToken {
return deviceTokenRepository.save(
deviceTokenMapper.toEntity(deviceToken)
).let { deviceTokenMapper.toDomain(it)!! }
}

override fun queryDeviceTokenByUserId(userId: UUID): String? {
return deviceTokenRepository.findByUserId(userId)?.token
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package team.comit.simtong.persistence.user.mapper

import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.springframework.beans.factory.annotation.Autowired
import team.comit.simtong.domain.user.model.DeviceToken
import team.comit.simtong.persistence.GenericMapper
import team.comit.simtong.persistence.user.entity.DeviceTokenJpaEntity
import team.comit.simtong.persistence.user.repository.UserJpaRepository

/**
*
* DeviceToken Entity와 DeviceToken Aggregate를 변환하는 DeviceTokenMapper
*
* @author kimbeomjin
* @date 2023/01/01
* @version 1.1.0
**/
@Mapper
abstract class DeviceTokenMapper : GenericMapper<DeviceTokenJpaEntity, DeviceToken> {

@Autowired
protected lateinit var userRepository: UserJpaRepository

@Mapping(target = "user", expression = "java(userRepository.findById(model.getUserId()).orElse(null))")
abstract override fun toEntity(model: DeviceToken): DeviceTokenJpaEntity
}
Loading