Skip to content

Commit

Permalink
#33 feat: 문의하기 답변 등록 API 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
psyeon1120 committed Aug 2, 2023
1 parent 18504e5 commit b13a4af
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ enum class BaseResponseCode(status: HttpStatus, message: String) {
EXISTS_NICKNAME(HttpStatus.BAD_REQUEST, "이미 가입되어 있는 닉네임입니다."),
NOT_EXIST_EMAIL(HttpStatus.BAD_REQUEST, "해당 이메일로 가입한 사용자를 찾을 수 없습니다."),
INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "사용자의 비밀번호가 일치하지 않습니다."),
NOT_FOUND_USER(HttpStatus.NOT_FOUND, "사용자를 찾을 수 없습니다."),

// User - type
INVALID_USER_TYPE_NAME(HttpStatus.BAD_REQUEST, "올바르지 않은 사용자 역할입니다."),
NOT_MANAGER(HttpStatus.FORBIDDEN, "관리자가 아닙니다."),
INVALID_USER_CATEGORY(HttpStatus.BAD_REQUEST, "올바르지 않은 사용자 카테고리입니다."),

// User - category
INVALID_USER_INTEREST_COUNT(HttpStatus.BAD_REQUEST, "사용자 관심 주제는 1개이상, 3개 이하여야하며, 중복된 값이 포함되어 있지 않아야 합니다"),

// inquiry
NOT_FOUND_INQUIRY(HttpStatus.NOT_FOUND, "해당 문의를 찾을 수 없습니다."),
INVALID_INQUIRY_STATUS(HttpStatus.BAD_REQUEST, "올바르지 않은 문의 상태입니다.");
INVALID_INQUIRY_STATUS(HttpStatus.BAD_REQUEST, "올바르지 않은 문의 상태입니다."),
INQUIRY_ANSWER_ALREADY_COMPLETE(HttpStatus.CONFLICT, "이미 답변 완료된 문의입니다.");

val status: HttpStatus = status
val message: String = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.psr.psr.inquiry.controller

import com.psr.psr.global.dto.BaseResponse
import com.psr.psr.global.jwt.UserAccount
import com.psr.psr.inquiry.dto.InquiryAnswerReq
import com.psr.psr.inquiry.dto.InquiryListRes
import com.psr.psr.inquiry.dto.InquiryReq
import com.psr.psr.inquiry.dto.InquiryRes
Expand Down Expand Up @@ -33,4 +34,10 @@ class InquiryController(
fun getInquiryList (@AuthenticationPrincipal userAccount: UserAccount, @RequestParam status: String) : BaseResponse<List<InquiryListRes>> {
return BaseResponse(inquiryService.getInquiryList(userAccount.getUser(), status))
}

// 문의하기 답변 등록
@PatchMapping("/{inquiryId}")
fun answerInquiry (@AuthenticationPrincipal userAccount: UserAccount, @PathVariable inquiryId: Long, @RequestBody @Valid inquiryAnswerReq: InquiryAnswerReq) : BaseResponse<Unit> {
return BaseResponse(inquiryService.answerInquiry(userAccount.getUser(), inquiryId, inquiryAnswerReq))
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/psr/psr/inquiry/dto/InquiryAnswerReq.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.psr.psr.inquiry.dto

import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size

data class InquiryAnswerReq (
@field:NotBlank(message = "답변을 입력해주세요.")
@field:Size(max = 250, message = "답변은 최대 250자입니다.")
val answer: String
)
5 changes: 5 additions & 0 deletions src/main/kotlin/com/psr/psr/inquiry/entity/Inquiry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ data class Inquiry(
var answer: String? = null

): BaseEntity(){
fun registerAnswer(answer: String){
this.answer = answer
this.inquiryStatus = InquiryStatus.COMPLETED
}

fun toListDto(): InquiryListRes {
return InquiryListRes(
inquiryId = id!!,
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/psr/psr/inquiry/service/InquiryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.psr.psr.inquiry.service
import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS
import com.psr.psr.global.exception.BaseException
import com.psr.psr.global.exception.BaseResponseCode
import com.psr.psr.inquiry.dto.InquiryAnswerReq
import com.psr.psr.inquiry.dto.InquiryListRes
import com.psr.psr.inquiry.dto.InquiryReq
import com.psr.psr.inquiry.entity.Inquiry
Expand Down Expand Up @@ -42,4 +43,16 @@ class InquiryService(

return inquiries.map { inquiry: Inquiry -> inquiry.toListDto() }
}

// 문의 답변 등록
fun answerInquiry(user: User, inquiryId: Long, inquiryAnswerReq: InquiryAnswerReq) {
if (user.type != Type.MANAGER) throw BaseException(BaseResponseCode.NOT_MANAGER)

val inquiry: Inquiry = inquiryRepository.findByIdAndStatus(inquiryId, ACTIVE_STATUS)
?: throw BaseException(BaseResponseCode.NOT_FOUND_INQUIRY)
if (inquiry.inquiryStatus == InquiryStatus.COMPLETED) throw BaseException(BaseResponseCode.INQUIRY_ANSWER_ALREADY_COMPLETE)

inquiry.registerAnswer(inquiryAnswerReq.answer)
inquiryRepository.save(inquiry)
}
}

0 comments on commit b13a4af

Please sign in to comment.