Skip to content

Commit

Permalink
Merge pull request #72 from TeamMiso/feat/notification-detail
Browse files Browse the repository at this point in the history
🔀 :: 문의사항 답변 글 상세보기 API 구현
  • Loading branch information
uuuuuuuk authored Mar 28, 2024
2 parents bbe0c80 + 5b401ed commit f116b29
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package andreas311.miso.domain.notification.adapter.input

import andreas311.miso.common.annotation.RequestController
import andreas311.miso.domain.notification.adapter.input.data.DetailNotificationResponse
import andreas311.miso.domain.notification.adapter.input.mapper.NotificationDataMapper
import andreas311.miso.domain.notification.application.port.input.DetailNotificationUseCase
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable

@RequestController("/notification")
class NotificationAdapter(
private val notificationDataMapper: NotificationDataMapper,
private val detailNotificationUseCase: DetailNotificationUseCase
) {
@GetMapping("/{id}")
fun detail(@PathVariable id: Long): ResponseEntity<DetailNotificationResponse> =
detailNotificationUseCase.execute(id)
.let { notificationDataMapper.toResponse(it) }
.let { ResponseEntity.status(HttpStatus.OK).body(it) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.notification.adapter.input.data

data class DetailNotificationResponse(
val answer: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package andreas311.miso.domain.notification.adapter.input.mapper

import andreas311.miso.domain.notification.adapter.input.data.DetailNotificationResponse
import andreas311.miso.domain.notification.application.port.input.dto.DetailNotificationDto
import org.springframework.stereotype.Component

@Component
class NotificationDataMapper {
fun toResponse(detailNotificationDto: DetailNotificationDto): DetailNotificationResponse =
DetailNotificationResponse(
answer = detailNotificationDto.answer
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package andreas311.miso.domain.notification.adapter.output.persistence

import andreas311.miso.domain.notification.adapter.output.persistence.mapper.NotificationMapper
import andreas311.miso.domain.notification.adapter.output.persistence.repository.NotificationRepository
import andreas311.miso.domain.notification.application.port.output.QueryNotificationPort
import andreas311.miso.domain.notification.domain.Notification
import org.springframework.stereotype.Component

@Component
class QueryNotificationPersistenceAdapter(
private val notificationMapper: NotificationMapper,
private val notificationRepository: NotificationRepository
) : QueryNotificationPort {
override fun findByInquiryIdOrNull(id: Long): Notification? {
val notificationEntity = notificationRepository.findByInquiryId(id)
return notificationMapper.toDomain(notificationEntity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package andreas311.miso.domain.notification.adapter.output.persistence.repositor
import andreas311.miso.domain.notification.adapter.output.persistence.entity.NotificationEntity
import org.springframework.data.repository.CrudRepository

interface NotificationRepository : CrudRepository<NotificationEntity, Long>
interface NotificationRepository : CrudRepository<NotificationEntity, Long> {
fun findByInquiryId(id: Long): NotificationEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package andreas311.miso.domain.notification.application.exception

import andreas311.miso.global.error.ErrorCode
import andreas311.miso.global.error.exception.MisoException

class NotificationNotFoundException : MisoException(ErrorCode.NOTIFICATION_NOT_FOUND)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package andreas311.miso.domain.notification.application.port.input

import andreas311.miso.domain.notification.application.port.input.dto.DetailNotificationDto

interface DetailNotificationUseCase {
fun execute(id: Long): DetailNotificationDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package andreas311.miso.domain.notification.application.port.input.dto

import andreas311.miso.domain.notification.domain.Notification

data class DetailNotificationDto(
val answer: String
) {
constructor(notification: Notification) : this(
answer = notification.answer
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package andreas311.miso.domain.notification.application.port.output

import andreas311.miso.domain.notification.domain.Notification

interface QueryNotificationPort {
fun findByInquiryIdOrNull(id: Long): Notification?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package andreas311.miso.domain.notification.application.service

import andreas311.miso.common.annotation.ReadOnlyRollbackService
import andreas311.miso.domain.notification.application.exception.NotificationNotFoundException
import andreas311.miso.domain.notification.application.port.input.DetailNotificationUseCase
import andreas311.miso.domain.notification.application.port.input.dto.DetailNotificationDto
import andreas311.miso.domain.notification.application.port.output.QueryNotificationPort

@ReadOnlyRollbackService
class DetailNotificationService(
private val queryNotificationPort: QueryNotificationPort
) : DetailNotificationUseCase {
override fun execute(id: Long): DetailNotificationDto {
val notification = queryNotificationPort.findByInquiryIdOrNull(id)
?: throw NotificationNotFoundException()

return DetailNotificationDto(notification)
}
}

0 comments on commit f116b29

Please sign in to comment.