-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from kw-notice/refactor/issue-8
fix : fix alarm controller
- Loading branch information
Showing
3 changed files
with
40 additions
and
32 deletions.
There are no files selected for viewing
32 changes: 0 additions & 32 deletions
32
api-server-mvc/src/main/kotlin/com/knet/dormitory/web/alarm/AlarmController.kt
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
api-server-mvc/src/main/kotlin/com/knet/dormitory/web/alarm/dto/SendMessageRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package com.knet.dormitory.web.alarm.dto | ||
|
||
import com.knet.dormitory.domain.alarm.AlarmTopic | ||
import jakarta.validation.constraints.NotNull | ||
|
||
class SendMessageRequest( | ||
@field:NotNull(message = "title is null") | ||
val title: String? = null, | ||
@field:NotNull(message = "body is null") | ||
val body: String? = null, | ||
@field:NotNull(message = "topic is null") | ||
val topic: AlarmTopic? = null | ||
) |
36 changes: 36 additions & 0 deletions
36
...ver-mvc/src/main/kotlin/com/knet/dormitory/web/shared/exception/GlobalExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.knet.dormitory.web.shared.exception | ||
|
||
import com.knet.dormitory.web.shared.dto.ErrorResponse | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.MethodArgumentNotValidException | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
|
||
@RestControllerAdvice | ||
class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException::class) | ||
fun methodArgumentNotValidException( | ||
exception: MethodArgumentNotValidException | ||
): ResponseEntity<ErrorResponse> = ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body( | ||
ErrorResponse( | ||
status = HttpStatus.BAD_REQUEST, | ||
message = exception.bindingResult.allErrors[0].defaultMessage ?: "" | ||
) | ||
) | ||
|
||
@ExceptionHandler(IllegalArgumentException::class) | ||
fun illegalArgumentException( | ||
exception: IllegalArgumentException | ||
): ResponseEntity<ErrorResponse> = ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body( | ||
ErrorResponse( | ||
status = HttpStatus.BAD_REQUEST, | ||
message = exception.message ?: "" | ||
) | ||
) | ||
} |