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

[BG-351]: 디바이스 토큰 등록 API 이슈 (1h / 2h) #82

Merged
merged 3 commits into from
Aug 12, 2024
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
Expand Up @@ -14,6 +14,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

Expand All @@ -38,7 +39,7 @@ class UserController(
@PostMapping("/devices")
override fun registerUserDevice(
@AuthenticationPrincipal token: JwtAuthentication,
@ModelAttribute @Valid userDeviceDto: UserDeviceCreateRequest,
@RequestBody @Valid userDeviceDto: UserDeviceCreateRequest,
): ResponseEntity<Void> {
userFacadeService.registerUserDevice(userDeviceDto.toDto(userId = token.id))
return ResponseEntity.status(HttpStatus.CREATED).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import jakarta.validation.constraints.Email
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.ModelAttribute

@Tag(name = "users", description = "유저 API")
interface UserSwagger {
Expand All @@ -26,9 +22,7 @@ interface UserSwagger {
),
],
)
fun checkEmail(
@Email email: EmailExistsRequest,
): ResponseEntity<ApiResult<EmailExistsResponse>>
fun checkEmail(email: EmailExistsRequest): ResponseEntity<ApiResult<EmailExistsResponse>>

@Operation(summary = "fcm 디바이스 토큰 등록", description = "fcm 푸시 알림 전송용 토큰을 등록합니다.")
@ApiResponses(
Expand All @@ -40,7 +34,7 @@ interface UserSwagger {
],
)
fun registerUserDevice(
@AuthenticationPrincipal token: JwtAuthentication,
@ModelAttribute @Valid userDeviceDto: UserDeviceCreateRequest,
token: JwtAuthentication,
userDeviceDto: UserDeviceCreateRequest,
): ResponseEntity<Void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import com.backgu.amaker.api.user.dto.UserDeviceDto
import com.backgu.amaker.domain.user.Device
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotEmpty
import jakarta.validation.constraints.NotNull

data class UserDeviceCreateRequest(
@field:NotEmpty
@field:NotNull(message = "디바이스 종류는 필수입니다.")
@Schema(description = "디바이스 종류(IOS, ANDROID)", example = "ANDROID")
val device: Device,
@field:NotEmpty
@field:NotEmpty(message = "fcm 디바이스 토큰은 필수입니다.")
@Schema(description = "fcm 디바이스 토큰", example = "jafelijefaeflkefkfeijeif")
val token: String,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class UserFacadeService(
) {
fun existsByEmail(email: String): EmailExistsDto = EmailExistsDto.of(user = userService.findByEmail(email))

@Transactional
fun registerUserDevice(userDeviceDto: UserDeviceDto): UserDeviceDto = UserDeviceDto.of(userDeviceService.save(userDeviceDto.toDomain()))
}
Loading