Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 :: (ENTRY-32) Faq 수정 API #19

Merged
merged 6 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/kotlin/hs/kr/equus/feed/domain/faq/domain/Faq.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ class Faq(
id: UUID? = null,

@Column(name = "title", length = 100, nullable = false)
val title: String,
var title: String,

@Column(name = "content", length = 5000, nullable = false)
val content: String,
var content: String,

@Enumerated(EnumType.STRING)
val faqType: FaqType,
var faqType: FaqType,

@Column(name = "admin_id", columnDefinition = "BINARY(16)", nullable = false)
val adminId: UUID
) : BaseEntity(id)
var adminId: UUID
) : BaseEntity(id) {
fun updateFaq(title: String, content: String, faqType: FaqType, adminId: UUID) {
this.title = title
this.content = content
this.faqType = faqType
this.adminId = adminId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package hs.kr.equus.feed.domain.faq.presentation

import hs.kr.equus.feed.domain.faq.domain.type.FaqType
import hs.kr.equus.feed.domain.faq.presentation.dto.request.CreateFaqRequest
import hs.kr.equus.feed.domain.faq.presentation.dto.request.UpdateFaqRequest
import hs.kr.equus.feed.domain.faq.presentation.dto.response.FaqDetailsResponse
import hs.kr.equus.feed.domain.faq.presentation.dto.response.FaqListResponse
import hs.kr.equus.feed.domain.faq.service.CreateFaqService
import hs.kr.equus.feed.domain.faq.service.QueryFaqDetailsService
import hs.kr.equus.feed.domain.faq.service.QueryFaqListByTypeService
import hs.kr.equus.feed.domain.faq.service.QueryFaqListService
import hs.kr.equus.feed.domain.faq.service.*
import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
Expand All @@ -22,11 +21,12 @@ import java.util.UUID

@RequestMapping("/faq")
@RestController
class FaqPresentation(
class FaqController(
private val createFaqService: CreateFaqService,
private val queryFaqDetailsService: QueryFaqDetailsService,
private val queryFaqListByTypeService: QueryFaqListByTypeService,
private val queryFaqListService: QueryFaqListService
private val queryFaqListService: QueryFaqListService,
private val updateFaqService: UpdateFaqService
) {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
Expand All @@ -45,4 +45,8 @@ class FaqPresentation(

@GetMapping("/all")
fun queryFaqList(): FaqListResponse = queryFaqListService.execute()

@PatchMapping("/{faq-id}")
fun updateFaq(@PathVariable("faq-id") faqId: UUID, updateFaqRequest: UpdateFaqRequest) =
updateFaqService.execute(faqId, updateFaqRequest)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hs.kr.equus.feed.domain.faq.presentation.dto.request

import hs.kr.equus.feed.domain.faq.domain.type.FaqType
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Size

data class UpdateFaqRequest(
@field:NotBlank(message = "title은 null, 공백, 띄어쓰기를 허용하지 않습니다.")
@field:Size(max = 100, message = "title은 최대 100자까지 가능합니다.")
val title: String,

@field:NotBlank(message = "content은 null, 공백, 띄어쓰기를 허용하지 않습니다.")
@field:Size(max = 5000, message = "content는 최대 5000자까지 가능합니다.")
val content: String,

val faqType: FaqType
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hs.kr.equus.feed.domain.faq.service

import hs.kr.equus.feed.domain.faq.domain.repository.FaqRepository
import hs.kr.equus.feed.domain.faq.exception.FaqNotFoundException
import hs.kr.equus.feed.domain.faq.presentation.dto.request.UpdateFaqRequest
import hs.kr.equus.feed.global.utils.user.UserUtils
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.UUID

@Service
class UpdateFaqService(
private val faqRepository: FaqRepository,
private val userUtils: UserUtils
) {
@Transactional
fun execute(faqId: UUID, updateFaqRequest: UpdateFaqRequest) {
val faq = faqRepository.findByIdOrNull(faqId) ?: throw FaqNotFoundException
updateFaqRequest.run {
faq.updateFaq(
title = title,
content = content,
faqType = faqType,
adminId = userUtils.getCurrentUserId()
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hs.kr.equus.feed.global.security
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.web.SecurityFilterChain
Expand Down Expand Up @@ -32,7 +33,11 @@ class SecurityConfig(
.permitAll()
.antMatchers("/reply/**")
.hasRole(ADMIN_ROLE)
.antMatchers("/faq/**")
.antMatchers(HttpMethod.POST, "/faq/**")
.hasRole(ADMIN_ROLE)
.antMatchers(HttpMethod.PATCH, "/faq/**")
.hasRole(ADMIN_ROLE)
.antMatchers(HttpMethod.DELETE, "/faq/**")
.hasRole(ADMIN_ROLE)
.anyRequest()
.authenticated()
Expand Down
Loading