Skip to content

Commit

Permalink
Merge pull request #70 from TeamMiso/feat/inquiry-respond
Browse files Browse the repository at this point in the history
문의사항 글 답변하기 api 구현
  • Loading branch information
uuuuuuuk authored Mar 27, 2024
2 parents 17225a3 + ddc663e commit bbe0c80
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ package andreas311.miso.domain.inquiry.adapter.input

import andreas311.miso.common.annotation.RequestController
import andreas311.miso.domain.inquiry.adapter.input.data.request.WriteInquiryRequest
import andreas311.miso.domain.inquiry.adapter.input.data.request.WriteInquiryRespondRequest
import andreas311.miso.domain.inquiry.adapter.input.data.response.DetailInquiryResponse
import andreas311.miso.domain.inquiry.adapter.input.data.response.ListInquiryResponse
import andreas311.miso.domain.inquiry.adapter.input.mapper.InquiryDataMapper
import andreas311.miso.domain.inquiry.application.port.input.DetailInquiryUseCase
import andreas311.miso.domain.inquiry.application.port.input.ListFilterInquiryUseCase
import andreas311.miso.domain.inquiry.application.port.input.ListInquiryUseCase
import andreas311.miso.domain.inquiry.application.port.input.WriteInquiryUseCase
import andreas311.miso.domain.inquiry.application.port.input.*
import andreas311.miso.domain.inquiry.domain.InquiryStatus
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import javax.validation.Valid

Expand All @@ -25,7 +20,8 @@ class InquiryAdapter(
private val listInquiryUseCase: ListInquiryUseCase,
private val writeInquiryUseCase: WriteInquiryUseCase,
private val detailInquiryUseCase: DetailInquiryUseCase,
private val listFilterInquiryUseCase: ListFilterInquiryUseCase
private val listFilterInquiryUseCase: ListFilterInquiryUseCase,
private val writeInquiryRespondUseCase: WriteInquiryRespondUseCase
) {
@PostMapping
fun write(
Expand All @@ -52,4 +48,9 @@ class InquiryAdapter(
detailInquiryUseCase.execute(id)
.let { inquiryDataMapper.toResponse(it) }
.let { ResponseEntity.status(HttpStatus.OK).body(it) }

@PatchMapping("/respond/{id}")
fun respond(@PathVariable id: Long, @RequestBody @Valid writeInquiryRespondRequest: WriteInquiryRespondRequest): ResponseEntity<Void> =
writeInquiryRespondUseCase.execute(id, inquiryDataMapper toDto writeInquiryRespondRequest)
.let { ResponseEntity.status(HttpStatus.OK).build() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.domain.inquiry.adapter.input.data.request

import javax.validation.constraints.NotNull

data class WriteInquiryRespondRequest(
@field:NotNull
val answer: String
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package andreas311.miso.domain.inquiry.adapter.input.mapper

import andreas311.miso.domain.inquiry.adapter.input.data.request.WriteInquiryRequest
import andreas311.miso.domain.inquiry.adapter.input.data.request.WriteInquiryRespondRequest
import andreas311.miso.domain.inquiry.adapter.input.data.response.DetailInquiryResponse
import andreas311.miso.domain.inquiry.adapter.input.data.response.InquiryResponse
import andreas311.miso.domain.inquiry.adapter.input.data.response.ListInquiryResponse
import andreas311.miso.domain.inquiry.application.port.input.dto.DetailInquiryDto
import andreas311.miso.domain.inquiry.application.port.input.dto.ListInquiryDto
import andreas311.miso.domain.inquiry.application.port.input.dto.WriteInquiryDto
import andreas311.miso.domain.inquiry.application.port.input.dto.WriteInquiryRespondDto
import org.springframework.stereotype.Component

@Component
Expand All @@ -17,6 +19,11 @@ class InquiryDataMapper {
content = writeInquiryRequest.content
)

infix fun toDto(writeInquiryRespondRequest: WriteInquiryRespondRequest): WriteInquiryRespondDto =
WriteInquiryRespondDto(
answer = writeInquiryRespondRequest.answer
)

fun toResponse(detailInquiryDto: DetailInquiryDto): DetailInquiryResponse =
DetailInquiryResponse(
id = detailInquiryDto.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package andreas311.miso.domain.inquiry.application.port.input

import andreas311.miso.domain.inquiry.application.port.input.dto.WriteInquiryRespondDto

interface WriteInquiryRespondUseCase {
fun execute(id: Long, writeInquiryRespondDto: WriteInquiryRespondDto)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.inquiry.application.port.input.dto

data class WriteInquiryRespondDto(
val answer: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package andreas311.miso.domain.inquiry.application.port.output

interface DiscordMessageSendPort {
fun sendDiscordMessage(message: String)

fun toSingleDiscordMessage(string: String): String

fun createInquiryMessage(inquiryName: String): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package andreas311.miso.domain.inquiry.application.service

import andreas311.miso.common.annotation.RollbackService
import andreas311.miso.domain.auth.application.port.output.UserSecurityPort
import andreas311.miso.domain.inquiry.application.exception.InquiryNotFoundException
import andreas311.miso.domain.inquiry.application.port.input.WriteInquiryRespondUseCase
import andreas311.miso.domain.inquiry.application.port.input.dto.WriteInquiryRespondDto
import andreas311.miso.domain.inquiry.application.port.output.CommandInquiryPort
import andreas311.miso.domain.inquiry.application.port.output.QueryInquiryPort
import andreas311.miso.domain.inquiry.domain.InquiryStatus
import andreas311.miso.domain.notification.application.port.output.CommandNotificationPort
import andreas311.miso.domain.notification.domain.Notification

@RollbackService
class WriteInquiryRespondService(
private val userSecurityPort: UserSecurityPort,
private val queryInquiryPort: QueryInquiryPort,
private val commandInquiryPort: CommandInquiryPort,
private val commandNotificationPort: CommandNotificationPort
) : WriteInquiryRespondUseCase {
override fun execute(id: Long, writeInquiryRespondDto: WriteInquiryRespondDto) {
val user = userSecurityPort.currentUser()

val inquiry = queryInquiryPort.findByIdOrNull(id)
?: throw InquiryNotFoundException()

commandInquiryPort.saveInquiry(inquiry.updateInquiryStatus(InquiryStatus.COMPLETE))

commandNotificationPort.saveNotification(
Notification(
id = 0L,
answer = writeInquiryRespondDto.answer,
user = user,
inquiry = inquiry
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ data class Inquiry(
val user: User,
val createdDate: LocalDateTime
) {
fun updateInquiryStatus(inquiryStatus: InquiryStatus) {
fun updateInquiryStatus(inquiryStatus: InquiryStatus): Inquiry {
this.inquiryStatus = inquiryStatus
return this
}
}
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.CommandNotificationPort
import andreas311.miso.domain.notification.domain.Notification
import org.springframework.stereotype.Component

@Component
class CommandNotificationPersistenceAdapter(
private val notificationMapper: NotificationMapper,
private val notificationRepository: NotificationRepository
) : CommandNotificationPort {
override fun saveNotification(notification: Notification): Notification {
val notificationEntity = notificationRepository.save(notificationMapper.toEntity(notification))
return notificationMapper.toDomain(notificationEntity)!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package andreas311.miso.domain.notification.adapter.output.persistence.entity

import andreas311.miso.domain.inquiry.adapter.output.persistence.entity.InquiryEntity
import andreas311.miso.domain.user.adapter.output.persistence.entity.UserEntity
import javax.persistence.*

@Entity
@Table(name = "notification")
data class NotificationEntity(
@Id
@Column(name = "notification_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long,

@Column(name = "answer", nullable = false)
val answer: String,

@ManyToOne
@JoinColumn(name = "inquiry_id")
val inquiry: InquiryEntity,

@ManyToOne
@JoinColumn(name = "user_id")
val user: UserEntity
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package andreas311.miso.domain.notification.adapter.output.persistence.mapper

import andreas311.miso.domain.inquiry.adapter.output.persistence.mapper.InquiryMapper
import andreas311.miso.domain.notification.adapter.output.persistence.entity.NotificationEntity
import andreas311.miso.domain.notification.domain.Notification
import andreas311.miso.domain.user.adapter.output.persistence.mapper.UserMapper
import org.springframework.stereotype.Component

@Component
class NotificationMapper(
private val userMapper: UserMapper,
private val inquiryMapper: InquiryMapper
) {
infix fun toEntity(domain: Notification): NotificationEntity =
NotificationEntity(
id = domain.id,
answer = domain.answer,
user = userMapper.toEntity(domain.user),
inquiry = inquiryMapper.toEntity(domain.inquiry)
)

infix fun toDomain(entity: NotificationEntity?): Notification? =
entity?.let {
Notification(
id = entity.id,
answer = entity.answer,
user = userMapper.toDomain(entity.user)!!,
inquiry = inquiryMapper.toDomain(entity.inquiry)!!
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package andreas311.miso.domain.notification.adapter.output.persistence.repository

import andreas311.miso.domain.notification.adapter.output.persistence.entity.NotificationEntity
import org.springframework.data.repository.CrudRepository

interface NotificationRepository : CrudRepository<NotificationEntity, Long>
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 CommandNotificationPort {
fun saveNotification(notification: Notification): Notification
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import andreas311.miso.domain.notification.domain.NotificationAlarm

interface FcmNotificationPort {
fun sendInquiryNotification(deviceToken: String, notificationAlarm: NotificationAlarm)

fun sendEnvironmentNotification(deviceTokens: List<String>, notificationAlarm: NotificationAlarm)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package andreas311.miso.domain.notification.domain

import andreas311.miso.domain.inquiry.domain.Inquiry
import andreas311.miso.domain.user.domain.User

data class Notification(
val id: Long,
val answer: String,
val inquiry: Inquiry,
val user: User
)

0 comments on commit bbe0c80

Please sign in to comment.