From cb80dcfc6daa9800a94b293cde1d329138df7c8c Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 14:07:13 +0900 Subject: [PATCH 1/7] add :: create faq service --- .../data/request/CreateFAQRequest.kt | 6 ++++ .../team/msg/domain/faq/service/FAQService.kt | 7 ++++ .../msg/domain/faq/service/FAQServiceImpl.kt | 32 +++++++++++++++++++ .../kotlin/team/msg/domain/fAQ/model/FAQ.kt | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt new file mode 100644 index 000000000..b0ecd190f --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt @@ -0,0 +1,6 @@ +package team.msg.domain.faq.presentation.data.request + +data class CreateFAQRequest( + val question: String, + val answer: String +) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt new file mode 100644 index 000000000..ef9e3862b --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt @@ -0,0 +1,7 @@ +package team.msg.domain.faq.service + +import team.msg.domain.faq.presentation.data.request.CreateFAQRequest + +interface FAQService { + fun createFAQ(createFAQRequest: CreateFAQRequest) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt new file mode 100644 index 000000000..291d092f9 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt @@ -0,0 +1,32 @@ +package team.msg.domain.faq.service + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import team.msg.common.util.UserUtil +import team.msg.domain.admin.exception.AdminNotFoundException +import team.msg.domain.admin.repository.AdminRepository +import team.msg.domain.fAQ.model.FAQ +import team.msg.domain.fAQ.repository.FAQRepository +import team.msg.domain.faq.presentation.data.request.CreateFAQRequest + +@Service +class FAQServiceImpl( + private val faqRepository: FAQRepository, + private val userUtil: UserUtil, + private val adminRepository: AdminRepository +) : FAQService { + + @Transactional(rollbackFor = [Exception::class]) + override fun createFAQ(createFAQRequest: CreateFAQRequest) { + val user = userUtil.queryCurrentUser() + val admin = adminRepository.findByUser(user) ?: throw AdminNotFoundException("존재하지 않는 어드민입니다. info : [ userId = ${user.id} ]") + + val faq = FAQ( + question = createFAQRequest.question, + answer = createFAQRequest.answer, + admin = admin + ) + + faqRepository.save(faq) + } +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt index b94561541..639a2143f 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt @@ -15,7 +15,7 @@ class FAQ( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - val id: Long, + val id: Long = 0, @Column(nullable = false) val question: String, From dd24b3a1c625bf634d2ae3c5b69454d81f68effc Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 14:18:21 +0900 Subject: [PATCH 2/7] add :: create faq api --- .../msg/domain/faq/mapper/FAQRequestMapper.kt | 8 +++++++ .../domain/faq/mapper/FAQRequestMapperImpl.kt | 16 +++++++++++++ .../domain/faq/presentation/FAQController.kt | 24 +++++++++++++++++++ .../presentation/web/CreateFAQWebRequest.kt | 9 +++++++ .../kotlin/team/msg/domain/fAQ/model/FAQ.kt | 4 ++-- 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt create mode 100644 bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt new file mode 100644 index 000000000..9916559b7 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt @@ -0,0 +1,8 @@ +package team.msg.domain.faq.mapper + +import team.msg.domain.faq.presentation.data.request.CreateFAQRequest +import team.msg.domain.faq.presentation.web.CreateFAQWebRequest + +interface FAQRequestMapper { + fun createFAQWebRequestToDto(createFAQWebRequest: CreateFAQWebRequest): CreateFAQRequest +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt new file mode 100644 index 000000000..e35db6a7a --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt @@ -0,0 +1,16 @@ +package team.msg.domain.faq.mapper + +import org.springframework.stereotype.Component +import team.msg.domain.faq.presentation.data.request.CreateFAQRequest +import team.msg.domain.faq.presentation.web.CreateFAQWebRequest + +@Component +class FAQRequestMapperImpl : FAQRequestMapper { + + override fun createFAQWebRequestToDto(createFAQWebRequest: CreateFAQWebRequest): CreateFAQRequest = + CreateFAQRequest( + question = createFAQWebRequest.question, + answer = createFAQWebRequest.answer + ) + +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt new file mode 100644 index 000000000..af5f0b804 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt @@ -0,0 +1,24 @@ +package team.msg.domain.faq.presentation + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import team.msg.domain.faq.mapper.FAQRequestMapper +import team.msg.domain.faq.presentation.web.CreateFAQWebRequest +import team.msg.domain.faq.service.FAQService + +@RestController +@RequestMapping("/faq") +class FAQController( + private val faqService: FAQService, + private val faqRequestMapper: FAQRequestMapper +) { + @PostMapping + fun createFAQ(webRequest: CreateFAQWebRequest): ResponseEntity { + val request = faqRequestMapper.createFAQWebRequestToDto(webRequest) + faqService.createFAQ(request) + return ResponseEntity.status(HttpStatus.CREATED).build() + } +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt new file mode 100644 index 000000000..d6bb57a31 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt @@ -0,0 +1,9 @@ +package team.msg.domain.faq.presentation.web + +import javax.validation.constraints.NotBlank + +data class CreateFAQWebRequest( + @field:NotBlank + val question: String, + val answer: String +) \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt index 639a2143f..0740bfbff 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt @@ -17,10 +17,10 @@ class FAQ( @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long = 0, - @Column(nullable = false) + @Column(nullable = false, columnDefinition = "TEXT") val question: String, - @Column(nullable = false) + @Column(nullable = false, columnDefinition = "TEXT") val answer: String, @ManyToOne(fetch = FetchType.LAZY) From 71a73b66b55a4ca00e463bfac71ba45f44fa7ba0 Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 14:45:21 +0900 Subject: [PATCH 3/7] =?UTF-8?q?add=20::=20create=20faq=20api=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=EA=B6=8C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/msg/domain/faq/presentation/FAQController.kt | 4 +++- .../domain/faq/presentation/web/CreateFAQWebRequest.kt | 2 ++ .../kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt | 1 + .../kotlin/team/msg/global/security/SecurityConfig.kt | 3 +++ .../team/msg/global/security/principal/AuthDetails.kt | 9 ++++----- .../msg/global/security/principal/AuthDetailsService.kt | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt index af5f0b804..807ea14e4 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt @@ -1,8 +1,10 @@ package team.msg.domain.faq.presentation +import javax.validation.Valid import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import team.msg.domain.faq.mapper.FAQRequestMapper @@ -16,7 +18,7 @@ class FAQController( private val faqRequestMapper: FAQRequestMapper ) { @PostMapping - fun createFAQ(webRequest: CreateFAQWebRequest): ResponseEntity { + fun createFAQ(@RequestBody @Valid webRequest: CreateFAQWebRequest): ResponseEntity { val request = faqRequestMapper.createFAQWebRequestToDto(webRequest) faqService.createFAQ(request) return ResponseEntity.status(HttpStatus.CREATED).build() diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt index d6bb57a31..4c0675532 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt @@ -5,5 +5,7 @@ import javax.validation.constraints.NotBlank data class CreateFAQWebRequest( @field:NotBlank val question: String, + + @field:NotBlank val answer: String ) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt index 291d092f9..2a2b687e8 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt @@ -22,6 +22,7 @@ class FAQServiceImpl( val admin = adminRepository.findByUser(user) ?: throw AdminNotFoundException("존재하지 않는 어드민입니다. info : [ userId = ${user.id} ]") val faq = FAQ( + id = 1, question = createFAQRequest.question, answer = createFAQRequest.answer, admin = admin diff --git a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt index 0045e89d6..176f2059e 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt @@ -67,6 +67,9 @@ class SecurityConfig( .mvcMatchers(HttpMethod.PATCH, "/lecture/{id}/approve").hasAnyRole(ADMIN) .mvcMatchers(HttpMethod.DELETE, "/lecture/{id}/reject").hasAnyRole(ADMIN) + // + .mvcMatchers(HttpMethod.POST, "/faq").hasRole(ADMIN) + .anyRequest().authenticated() .and() diff --git a/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetails.kt b/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetails.kt index d59fe0936..faf507759 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetails.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetails.kt @@ -3,18 +3,17 @@ package team.msg.global.security.principal import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.userdetails.UserDetails -import team.msg.domain.user.enums.Authority -import java.util.UUID +import team.msg.domain.user.model.User open class AuthDetails( - private val userId: UUID + private val user: User ) : UserDetails { override fun getAuthorities(): MutableCollection = - mutableListOf(SimpleGrantedAuthority(Authority.ROLE_USER.name)) + mutableListOf(SimpleGrantedAuthority(user.authority.name)) override fun getPassword(): String? = null - override fun getUsername(): String = userId.toString() + override fun getUsername(): String = user.id.toString() override fun isAccountNonExpired() = true diff --git a/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetailsService.kt b/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetailsService.kt index 21a781be0..54fbb3754 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetailsService.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/global/security/principal/AuthDetailsService.kt @@ -16,6 +16,6 @@ class AuthDetailsService( ) : UserDetailsService { override fun loadUserByUsername(username: String?): UserDetails { val user = userRepository.findByIdOrNull(UUID.fromString(username)) ?: throw UserNotFoundException("존재하지 않는 유저입니다.") - return AuthDetails(user.id) + return AuthDetails(user) } } \ No newline at end of file From 4c6c18453ee9c9847fa4e130279f97db51d6d39a Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 14:51:03 +0900 Subject: [PATCH 4/7] update :: FAQ -> faq --- .../msg/domain/faq/mapper/FAQRequestMapper.kt | 8 ++++---- .../domain/faq/mapper/FAQRequestMapperImpl.kt | 10 +++++----- .../msg/domain/faq/presentation/FAQController.kt | 16 ++++++++-------- .../data/request/CreateFAQRequest.kt | 2 +- .../faq/presentation/web/CreateFAQWebRequest.kt | 2 +- .../team/msg/domain/faq/service/FAQService.kt | 6 +++--- .../msg/domain/faq/service/FAQServiceImpl.kt | 16 ++++++++-------- .../team/msg/global/security/SecurityConfig.kt | 4 ++-- .../main/kotlin/team/msg/domain/fAQ/model/FAQ.kt | 4 ++-- .../msg/domain/fAQ/repository/FAQRepository.kt | 6 +++--- 10 files changed, 37 insertions(+), 37 deletions(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt index 9916559b7..f6f8e99cf 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt @@ -1,8 +1,8 @@ package team.msg.domain.faq.mapper -import team.msg.domain.faq.presentation.data.request.CreateFAQRequest -import team.msg.domain.faq.presentation.web.CreateFAQWebRequest +import team.msg.domain.faq.presentation.data.request.CreateFaqRequest +import team.msg.domain.faq.presentation.web.CreateFaqWebRequest -interface FAQRequestMapper { - fun createFAQWebRequestToDto(createFAQWebRequest: CreateFAQWebRequest): CreateFAQRequest +interface FaqRequestMapper { + fun createFAQWebRequestToDto(createFAQWebRequest: CreateFaqWebRequest): CreateFaqRequest } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt index e35db6a7a..382f84b4b 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt @@ -1,14 +1,14 @@ package team.msg.domain.faq.mapper import org.springframework.stereotype.Component -import team.msg.domain.faq.presentation.data.request.CreateFAQRequest -import team.msg.domain.faq.presentation.web.CreateFAQWebRequest +import team.msg.domain.faq.presentation.data.request.CreateFaqRequest +import team.msg.domain.faq.presentation.web.CreateFaqWebRequest @Component -class FAQRequestMapperImpl : FAQRequestMapper { +class FaqRequestMapperImpl : FaqRequestMapper { - override fun createFAQWebRequestToDto(createFAQWebRequest: CreateFAQWebRequest): CreateFAQRequest = - CreateFAQRequest( + override fun createFAQWebRequestToDto(createFAQWebRequest: CreateFaqWebRequest): CreateFaqRequest = + CreateFaqRequest( question = createFAQWebRequest.question, answer = createFAQWebRequest.answer ) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt index 807ea14e4..a4af30911 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt @@ -7,18 +7,18 @@ import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import team.msg.domain.faq.mapper.FAQRequestMapper -import team.msg.domain.faq.presentation.web.CreateFAQWebRequest -import team.msg.domain.faq.service.FAQService +import team.msg.domain.faq.mapper.FaqRequestMapper +import team.msg.domain.faq.presentation.web.CreateFaqWebRequest +import team.msg.domain.faq.service.FaqService @RestController -@RequestMapping("/faq") -class FAQController( - private val faqService: FAQService, - private val faqRequestMapper: FAQRequestMapper +@RequestMapping("/FAQ") +class FaqController( + private val faqService: FaqService, + private val faqRequestMapper: FaqRequestMapper ) { @PostMapping - fun createFAQ(@RequestBody @Valid webRequest: CreateFAQWebRequest): ResponseEntity { + fun createFAQ(@RequestBody @Valid webRequest: CreateFaqWebRequest): ResponseEntity { val request = faqRequestMapper.createFAQWebRequestToDto(webRequest) faqService.createFAQ(request) return ResponseEntity.status(HttpStatus.CREATED).build() diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt index b0ecd190f..9a8add618 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt @@ -1,6 +1,6 @@ package team.msg.domain.faq.presentation.data.request -data class CreateFAQRequest( +data class CreateFaqRequest( val question: String, val answer: String ) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt index 4c0675532..1f478e1b5 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt @@ -2,7 +2,7 @@ package team.msg.domain.faq.presentation.web import javax.validation.constraints.NotBlank -data class CreateFAQWebRequest( +data class CreateFaqWebRequest( @field:NotBlank val question: String, diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt index ef9e3862b..d10c0c531 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt @@ -1,7 +1,7 @@ package team.msg.domain.faq.service -import team.msg.domain.faq.presentation.data.request.CreateFAQRequest +import team.msg.domain.faq.presentation.data.request.CreateFaqRequest -interface FAQService { - fun createFAQ(createFAQRequest: CreateFAQRequest) +interface FaqService { + fun createFAQ(createFAQRequest: CreateFaqRequest) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt index 2a2b687e8..6f4c9aaa2 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt @@ -5,23 +5,23 @@ import org.springframework.transaction.annotation.Transactional import team.msg.common.util.UserUtil import team.msg.domain.admin.exception.AdminNotFoundException import team.msg.domain.admin.repository.AdminRepository -import team.msg.domain.fAQ.model.FAQ -import team.msg.domain.fAQ.repository.FAQRepository -import team.msg.domain.faq.presentation.data.request.CreateFAQRequest +import team.msg.domain.faq.model.Faq +import team.msg.domain.faq.repository.FaqRepository +import team.msg.domain.faq.presentation.data.request.CreateFaqRequest @Service -class FAQServiceImpl( - private val faqRepository: FAQRepository, +class FaqServiceImpl( + private val faqRepository: FaqRepository, private val userUtil: UserUtil, private val adminRepository: AdminRepository -) : FAQService { +) : FaqService { @Transactional(rollbackFor = [Exception::class]) - override fun createFAQ(createFAQRequest: CreateFAQRequest) { + override fun createFAQ(createFAQRequest: CreateFaqRequest) { val user = userUtil.queryCurrentUser() val admin = adminRepository.findByUser(user) ?: throw AdminNotFoundException("존재하지 않는 어드민입니다. info : [ userId = ${user.id} ]") - val faq = FAQ( + val faq = Faq( id = 1, question = createFAQRequest.question, answer = createFAQRequest.answer, diff --git a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt index 176f2059e..5ea7fab9e 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt @@ -67,8 +67,8 @@ class SecurityConfig( .mvcMatchers(HttpMethod.PATCH, "/lecture/{id}/approve").hasAnyRole(ADMIN) .mvcMatchers(HttpMethod.DELETE, "/lecture/{id}/reject").hasAnyRole(ADMIN) - // - .mvcMatchers(HttpMethod.POST, "/faq").hasRole(ADMIN) + // faq + .mvcMatchers(HttpMethod.POST, "/FAQ").hasRole(ADMIN) .anyRequest().authenticated() .and() diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt index 0740bfbff..f5e3b09c8 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/model/FAQ.kt @@ -1,4 +1,4 @@ -package team.msg.domain.fAQ.model +package team.msg.domain.faq.model import javax.persistence.Column import javax.persistence.Entity @@ -11,7 +11,7 @@ import javax.persistence.ManyToOne import team.msg.domain.admin.model.Admin @Entity -class FAQ( +class Faq( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/repository/FAQRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/repository/FAQRepository.kt index 2ed16aaee..e8dc379f0 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/repository/FAQRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/repository/FAQRepository.kt @@ -1,8 +1,8 @@ -package team.msg.domain.fAQ.repository +package team.msg.domain.faq.repository import org.springframework.data.repository.CrudRepository -import team.msg.domain.fAQ.model.FAQ +import team.msg.domain.faq.model.Faq import java.util.* -interface FAQRepository : CrudRepository { +interface FaqRepository : CrudRepository { } \ No newline at end of file From 00e45121deeac4cde8228b9477215edea63d61fe Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 14:57:46 +0900 Subject: [PATCH 5/7] =?UTF-8?q?docs=20::=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt | 3 +++ .../kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt index 382f84b4b..f05c393b6 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt @@ -7,6 +7,9 @@ import team.msg.domain.faq.presentation.web.CreateFaqWebRequest @Component class FaqRequestMapperImpl : FaqRequestMapper { + /** + * FAQ 등록 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. + */ override fun createFAQWebRequestToDto(createFAQWebRequest: CreateFaqWebRequest): CreateFaqRequest = CreateFaqRequest( question = createFAQWebRequest.question, diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt index 6f4c9aaa2..f528e9580 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt @@ -16,13 +16,16 @@ class FaqServiceImpl( private val adminRepository: AdminRepository ) : FaqService { + /** + * FAQ 등록을 처리하는 비지니스 로직입니다. + * @param FAQ 등록을 처리하기 위한 request dto 입니다. + */ @Transactional(rollbackFor = [Exception::class]) override fun createFAQ(createFAQRequest: CreateFaqRequest) { val user = userUtil.queryCurrentUser() val admin = adminRepository.findByUser(user) ?: throw AdminNotFoundException("존재하지 않는 어드민입니다. info : [ userId = ${user.id} ]") val faq = Faq( - id = 1, question = createFAQRequest.question, answer = createFAQRequest.answer, admin = admin From d21ba80e4607291df8e61e5aa50090bfdb4d92b5 Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 19:43:54 +0900 Subject: [PATCH 6/7] =?UTF-8?q?update=20::=20faq=20=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt | 2 +- .../team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt | 6 +++--- .../team/msg/domain/faq/presentation/FAQController.kt | 4 ++-- .../main/kotlin/team/msg/domain/faq/service/FAQService.kt | 2 +- .../kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt index f6f8e99cf..f1fd760b0 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt @@ -4,5 +4,5 @@ import team.msg.domain.faq.presentation.data.request.CreateFaqRequest import team.msg.domain.faq.presentation.web.CreateFaqWebRequest interface FaqRequestMapper { - fun createFAQWebRequestToDto(createFAQWebRequest: CreateFaqWebRequest): CreateFaqRequest + fun createFaqWebRequestToDto(createFaqWebRequest: CreateFaqWebRequest): CreateFaqRequest } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt index f05c393b6..69a00282d 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt @@ -10,10 +10,10 @@ class FaqRequestMapperImpl : FaqRequestMapper { /** * FAQ 등록 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. */ - override fun createFAQWebRequestToDto(createFAQWebRequest: CreateFaqWebRequest): CreateFaqRequest = + override fun createFaqWebRequestToDto(createFaqWebRequest: CreateFaqWebRequest): CreateFaqRequest = CreateFaqRequest( - question = createFAQWebRequest.question, - answer = createFAQWebRequest.answer + question = createFaqWebRequest.question, + answer = createFaqWebRequest.answer ) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt index a4af30911..38b3ae125 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt @@ -19,8 +19,8 @@ class FaqController( ) { @PostMapping fun createFAQ(@RequestBody @Valid webRequest: CreateFaqWebRequest): ResponseEntity { - val request = faqRequestMapper.createFAQWebRequestToDto(webRequest) - faqService.createFAQ(request) + val request = faqRequestMapper.createFaqWebRequestToDto(webRequest) + faqService.createFaq(request) return ResponseEntity.status(HttpStatus.CREATED).build() } } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt index d10c0c531..3ec3daab1 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt @@ -3,5 +3,5 @@ package team.msg.domain.faq.service import team.msg.domain.faq.presentation.data.request.CreateFaqRequest interface FaqService { - fun createFAQ(createFAQRequest: CreateFaqRequest) + fun createFaq(createFaqRequest: CreateFaqRequest) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt index f528e9580..d9677e1c0 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt @@ -21,13 +21,13 @@ class FaqServiceImpl( * @param FAQ 등록을 처리하기 위한 request dto 입니다. */ @Transactional(rollbackFor = [Exception::class]) - override fun createFAQ(createFAQRequest: CreateFaqRequest) { + override fun createFaq(createFaqRequest: CreateFaqRequest) { val user = userUtil.queryCurrentUser() val admin = adminRepository.findByUser(user) ?: throw AdminNotFoundException("존재하지 않는 어드민입니다. info : [ userId = ${user.id} ]") val faq = Faq( - question = createFAQRequest.question, - answer = createFAQRequest.answer, + question = createFaqRequest.question, + answer = createFaqRequest.answer, admin = admin ) From 9081db817bfa55a8461d28fc719c863066b5a0cd Mon Sep 17 00:00:00 2001 From: JuuuuHong Date: Wed, 25 Oct 2023 19:44:58 +0900 Subject: [PATCH 7/7] =?UTF-8?q?update=20::=20faq=20=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/domain/faq/presentation/FAQController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt index 38b3ae125..90b34f1ab 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt @@ -18,7 +18,7 @@ class FaqController( private val faqRequestMapper: FaqRequestMapper ) { @PostMapping - fun createFAQ(@RequestBody @Valid webRequest: CreateFaqWebRequest): ResponseEntity { + fun createFaq(@RequestBody @Valid webRequest: CreateFaqWebRequest): ResponseEntity { val request = faqRequestMapper.createFaqWebRequestToDto(webRequest) faqService.createFaq(request) return ResponseEntity.status(HttpStatus.CREATED).build()