-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
426 additions
and
70 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...c/main/kotlin/com/depromeet/whatnow/api/notification/controller/NotificationController.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,30 @@ | ||
package com.depromeet.whatnow.api.notification.controller | ||
|
||
import com.depromeet.whatnow.api.notification.dto.NotificationResponse | ||
import com.depromeet.whatnow.api.notification.usecase.NotificationReadUseCase | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springdoc.api.annotations.ParameterObject | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.web.PageableDefault | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@Tag(name = "8. [알림]") | ||
@RequestMapping("/v1/notifications") | ||
@SecurityRequirement(name = "access-token") | ||
class NotificationController( | ||
val notificationReadUseCase: NotificationReadUseCase, | ||
) { | ||
@Operation(summary = "자신의 알림 조회") | ||
@GetMapping | ||
fun getMyNotifications( | ||
@ParameterObject @PageableDefault | ||
pageable: Pageable, | ||
): NotificationResponse { | ||
return notificationReadUseCase.execute(pageable) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../main/kotlin/com/depromeet/whatnow/api/notification/dto/EndSharingNotificationResponse.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,19 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.EndSharingNotification | ||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import java.time.LocalDateTime | ||
|
||
class EndSharingNotificationResponse( | ||
val promiseId: Long, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.START_SHARING, createdAt) { | ||
companion object { | ||
fun from(notification: EndSharingNotification): EndSharingNotificationResponse { | ||
return EndSharingNotificationResponse( | ||
notification.promiseId, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...i/src/main/kotlin/com/depromeet/whatnow/api/notification/dto/ImageNotificationResponse.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,26 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.ImageNotification | ||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType | ||
import java.time.LocalDateTime | ||
|
||
class ImageNotificationResponse( | ||
val senderUserPromiseUserType: PromiseUserType, | ||
val senderUserId: Long, | ||
val promiseId: Long, | ||
val imageKey: String, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.IMAGE, createdAt) { | ||
companion object { | ||
fun from(notification: ImageNotification): ImageNotificationResponse { | ||
return ImageNotificationResponse( | ||
notification.senderUserPromiseUserType, | ||
notification.senderUserId, | ||
notification.promiseId, | ||
notification.imageKey, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...n/com/depromeet/whatnow/api/notification/dto/InteractionAttainmentNotificationResponse.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,24 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.interaction.domain.InteractionType | ||
import com.depromeet.whatnow.domains.notification.domain.InteractionAttainmentNotification | ||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import java.time.LocalDateTime | ||
|
||
class InteractionAttainmentNotificationResponse( | ||
val promiseId: Long, | ||
val senderUserId: Long, | ||
val interactionType: InteractionType, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.INTERACTION_ATTAINMENT, createdAt) { | ||
companion object { | ||
fun from(notification: InteractionAttainmentNotification): InteractionAttainmentNotificationResponse { | ||
return InteractionAttainmentNotificationResponse( | ||
notification.promiseId, | ||
notification.senderUserId, | ||
notification.interactionType, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/kotlin/com/depromeet/whatnow/api/notification/dto/InteractionNotificationResponse.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,24 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.interaction.domain.InteractionType | ||
import com.depromeet.whatnow.domains.notification.domain.InteractionNotification | ||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import java.time.LocalDateTime | ||
|
||
class InteractionNotificationResponse( | ||
val promiseId: Long, | ||
val senderUserId: Long, | ||
val interactionType: InteractionType, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.INTERACTION, createdAt) { | ||
companion object { | ||
fun from(notification: InteractionNotification): InteractionNotificationResponse { | ||
return InteractionNotificationResponse( | ||
notification.promiseId, | ||
notification.senderUserId, | ||
notification.interactionType, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ow-Api/src/main/kotlin/com/depromeet/whatnow/api/notification/dto/NotificationAbstract.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,9 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import java.time.LocalDateTime | ||
|
||
abstract class NotificationAbstract( | ||
val notificationType: NotificationType, | ||
open val createdAt: LocalDateTime, | ||
) |
7 changes: 7 additions & 0 deletions
7
...ow-Api/src/main/kotlin/com/depromeet/whatnow/api/notification/dto/NotificationResponse.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,7 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import java.time.LocalDate | ||
|
||
data class NotificationResponse( | ||
val notifications: Map<LocalDate, List<NotificationAbstract>>, | ||
) |
19 changes: 19 additions & 0 deletions
19
...ain/kotlin/com/depromeet/whatnow/api/notification/dto/StartSharingNotificationResponse.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,19 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import com.depromeet.whatnow.domains.notification.domain.StartSharingNotification | ||
import java.time.LocalDateTime | ||
|
||
class StartSharingNotificationResponse( | ||
val promiseId: Long, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.START_SHARING, createdAt) { | ||
companion object { | ||
fun from(notification: StartSharingNotification): StartSharingNotificationResponse { | ||
return StartSharingNotificationResponse( | ||
notification.promiseId, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rc/main/kotlin/com/depromeet/whatnow/api/notification/dto/TimeOverNotificationResponse.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,22 @@ | ||
package com.depromeet.whatnow.api.notification.dto | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.NotificationType | ||
import com.depromeet.whatnow.domains.notification.domain.TimeOverNotification | ||
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType | ||
import java.time.LocalDateTime | ||
|
||
class TimeOverNotificationResponse( | ||
val promiseId: Long, | ||
val promiseUserType: PromiseUserType, | ||
override val createdAt: LocalDateTime, | ||
) : NotificationAbstract(NotificationType.TIMEOVER, createdAt) { | ||
companion object { | ||
fun from(notification: TimeOverNotification): TimeOverNotificationResponse { | ||
return TimeOverNotificationResponse( | ||
notification.promiseId, | ||
notification.promiseUserType, | ||
notification.createdAt, | ||
) | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...src/main/kotlin/com/depromeet/whatnow/api/notification/usecase/NotificationReadUseCase.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,56 @@ | ||
package com.depromeet.whatnow.api.notification.usecase | ||
|
||
import com.depromeet.whatnow.annotation.UseCase | ||
import com.depromeet.whatnow.api.notification.dto.EndSharingNotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.ImageNotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.InteractionAttainmentNotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.InteractionNotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.NotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.StartSharingNotificationResponse | ||
import com.depromeet.whatnow.api.notification.dto.TimeOverNotificationResponse | ||
import com.depromeet.whatnow.config.security.SecurityUtils | ||
import com.depromeet.whatnow.domains.notification.domain.EndSharingNotification | ||
import com.depromeet.whatnow.domains.notification.domain.ImageNotification | ||
import com.depromeet.whatnow.domains.notification.domain.InteractionAttainmentNotification | ||
import com.depromeet.whatnow.domains.notification.domain.InteractionNotification | ||
import com.depromeet.whatnow.domains.notification.domain.StartSharingNotification | ||
import com.depromeet.whatnow.domains.notification.domain.TimeOverNotification | ||
import com.depromeet.whatnow.domains.notification.exception.UnknownNotificationTypeException | ||
import com.depromeet.whatnow.domains.notification.service.NotificationDomainService | ||
import org.springframework.data.domain.Pageable | ||
|
||
@UseCase | ||
class NotificationReadUseCase( | ||
val notificationDomainService: NotificationDomainService, | ||
) { | ||
fun execute(pageable: Pageable): NotificationResponse { | ||
val userId = SecurityUtils.currentUserId | ||
val notifications = notificationDomainService.getMyNotifications(userId, pageable) | ||
.map { notification -> | ||
when (notification) { | ||
is ImageNotification -> { | ||
ImageNotificationResponse.from(notification) | ||
} | ||
is InteractionNotification -> { | ||
InteractionNotificationResponse.from(notification) | ||
} | ||
is InteractionAttainmentNotification -> { | ||
InteractionAttainmentNotificationResponse.from(notification) | ||
} | ||
is StartSharingNotification -> { | ||
StartSharingNotificationResponse.from(notification) | ||
} | ||
is EndSharingNotification -> { | ||
EndSharingNotificationResponse.from(notification) | ||
} | ||
is TimeOverNotification -> { | ||
TimeOverNotificationResponse.from(notification) | ||
} | ||
else -> throw UnknownNotificationTypeException.EXCEPTION | ||
} | ||
} | ||
.groupBy { it.createdAt.toLocalDate() } | ||
|
||
return NotificationResponse(notifications) | ||
} | ||
} |
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
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
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
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
26 changes: 26 additions & 0 deletions
26
...main/kotlin/com/depromeet/whatnow/domains/notification/exception/NotificationErrorCode.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,26 @@ | ||
package com.depromeet.whatnow.domains.notification.exception | ||
|
||
import com.depromeet.whatnow.annotation.ExplainError | ||
import com.depromeet.whatnow.consts.BAD_REQUEST | ||
import com.depromeet.whatnow.dto.ErrorReason | ||
import com.depromeet.whatnow.exception.BaseErrorCode | ||
import java.util.* | ||
|
||
enum class NotificationErrorCode(val status: Int, val code: String, val reason: String) : BaseErrorCode { | ||
|
||
@ExplainError("알수 없는 알림 유형 일 경우") | ||
UNKNOWN_NOTIFICATION_TYPE(BAD_REQUEST, "NOTIFICATION_400_1", "알수 없는 알림 유형 입니다."), | ||
; | ||
|
||
override val errorReason: ErrorReason | ||
get() { | ||
return ErrorReason(status, code, reason) | ||
} | ||
|
||
override val explainError: String | ||
get() { | ||
val field = this.javaClass.getField(name) | ||
val annotation = field.getAnnotation(ExplainError::class.java) | ||
return if (Objects.nonNull(annotation)) annotation.value else reason | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../com/depromeet/whatnow/domains/notification/exception/UnknownNotificationTypeException.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,11 @@ | ||
package com.depromeet.whatnow.domains.notification.exception | ||
|
||
import com.depromeet.whatnow.exception.WhatnowCodeException | ||
|
||
class UnknownNotificationTypeException : WhatnowCodeException( | ||
NotificationErrorCode.UNKNOWN_NOTIFICATION_TYPE, | ||
) { | ||
companion object { | ||
val EXCEPTION: WhatnowCodeException = UnknownNotificationTypeException() | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
...in/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.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,6 +1,10 @@ | ||
package com.depromeet.whatnow.domains.notification.repository | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.Notification | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.domain.Slice | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface NotificationRepository : JpaRepository<Notification, Long> | ||
interface NotificationRepository : JpaRepository<Notification, Long> { | ||
fun findAllByTargetUserIdOrderByCreatedAtDesc(targetUserId: Long, pageable: Pageable): Slice<Notification> | ||
} |
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
Oops, something went wrong.