Skip to content

Commit

Permalink
feat: #39 알림 내역, 안 읽는 알림 여부 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
suyeoniii committed Aug 9, 2024
1 parent 90238b9 commit 3008506
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.routebox.routebox.controller.notification

import com.routebox.routebox.controller.notification.dto.GetNotificationHistoryResponse
import com.routebox.routebox.controller.notification.dto.GetUnreadNotificationResponse
import com.routebox.routebox.controller.notification.dto.NotificationHistoryDto
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 org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import kotlin.random.Random

@Tag(name = "알림 관련 API")
@RestController
@Validated
@RequestMapping("/api")
class NotificationController {
@Operation(
summary = "알림 내역 조회",
description = "알림 내역 조회",
)
@ApiResponses(
ApiResponse(responseCode = "200"),
)
@GetMapping("/v1/notifications")
fun getNotificationHistory(): GetNotificationHistoryResponse {
val mockData = listOf(
NotificationHistoryDto.from(1, "알림 내용1", "2024-08-04", false),
NotificationHistoryDto.from(2, "알림 내용2", "2024-08-03", false),
NotificationHistoryDto.from(3, "알림 내용3", "2024-08-02", true),
NotificationHistoryDto.from(4, "알림 내용4", "2024-08-02", true),
NotificationHistoryDto.from(5, "알림 내용5", "2024-08-01", true),
NotificationHistoryDto.from(6, "알림 내용6", "2024-08-01", true),
NotificationHistoryDto.from(7, "알림 내용7", "2024-08-01", true),
NotificationHistoryDto.from(8, "알림 내용8", "2024-07-31", true),
NotificationHistoryDto.from(9, "알림 내용9", "2024-07-30", true),
NotificationHistoryDto.from(10, "알림 내용10", "2024-07-20", true),
)
return GetNotificationHistoryResponse.from(mockData)
}

@Operation(
summary = "안읽은 알림 여부 조회",
description = "안읽은 알림 여부 조회",
)
@ApiResponses(
ApiResponse(responseCode = "200"),
)
@GetMapping("/v1/notifications/unread")
fun checkUnreadNotifications(): GetUnreadNotificationResponse {
val mockData: Boolean = Random.nextBoolean()
return GetUnreadNotificationResponse.from(mockData)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.routebox.routebox.controller.notification.dto

import io.swagger.v3.oas.annotations.media.Schema

data class GetNotificationHistoryResponse(
@Schema(description = "알림 목록")
val notifications: List<NotificationHistoryDto>,
) {
companion object {
fun from(notifications: List<NotificationHistoryDto>): GetNotificationHistoryResponse = GetNotificationHistoryResponse(
notifications = notifications,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.routebox.routebox.controller.notification.dto

import io.swagger.v3.oas.annotations.media.Schema

data class GetUnreadNotificationResponse(
@Schema(description = "읽지 않은 알림 존재 여부")
val hasUnreadNotification: Boolean,
) {
companion object {
fun from(hasUnreadNotification: Boolean): GetUnreadNotificationResponse = GetUnreadNotificationResponse(
hasUnreadNotification = hasUnreadNotification,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.routebox.routebox.controller.notification.dto

import io.swagger.v3.oas.annotations.media.Schema

data class NotificationHistoryDto(
@Schema(description = "알림 ID")
val id: Long,

@Schema(description = "알림 내용")
val content: String,

@Schema(description = "알림 생성일자 (yyyy-MM-dd)")
val date: String,

@Schema(description = "알림 읽음 여부")
val isRead: Boolean,
) {
companion object {
fun from(id: Long, content: String, date: String, isRead: Boolean): NotificationHistoryDto = NotificationHistoryDto(
id = id,
content = content,
date = date,
isRead = isRead,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SecurityConfig {
"/api/v1/users/nickname/*/availability" to HttpMethod.GET,
"/api/v1/routes" to HttpMethod.GET,
"/api/v1/routes/*" to HttpMethod.GET,
"/api/v1/notifications" to HttpMethod.GET,
"/api/v1/notifications/unread" to HttpMethod.GET,
)

@Bean
Expand Down

0 comments on commit 3008506

Please sign in to comment.