generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from GSM-MSG/70-feat/post-faq
70 �FAQ 등록 api
- Loading branch information
Showing
12 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
19 changes: 19 additions & 0 deletions
19
bitgouel-api/src/main/kotlin/team/msg/domain/faq/mapper/FAQRequestMapperImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 { | ||
|
||
/** | ||
* FAQ 등록 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. | ||
*/ | ||
override fun createFaqWebRequestToDto(createFaqWebRequest: CreateFaqWebRequest): CreateFaqRequest = | ||
CreateFaqRequest( | ||
question = createFaqWebRequest.question, | ||
answer = createFaqWebRequest.answer | ||
) | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/FAQController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 | ||
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(@RequestBody @Valid webRequest: CreateFaqWebRequest): ResponseEntity<Void> { | ||
val request = faqRequestMapper.createFaqWebRequestToDto(webRequest) | ||
faqService.createFaq(request) | ||
return ResponseEntity.status(HttpStatus.CREATED).build() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...uel-api/src/main/kotlin/team/msg/domain/faq/presentation/data/request/CreateFAQRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package team.msg.domain.faq.presentation.data.request | ||
|
||
data class CreateFaqRequest( | ||
val question: String, | ||
val answer: String | ||
) |
11 changes: 11 additions & 0 deletions
11
bitgouel-api/src/main/kotlin/team/msg/domain/faq/presentation/web/CreateFAQWebRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package team.msg.domain.faq.presentation.web | ||
|
||
import javax.validation.constraints.NotBlank | ||
|
||
data class CreateFaqWebRequest( | ||
@field:NotBlank | ||
val question: String, | ||
|
||
@field:NotBlank | ||
val answer: String | ||
) |
7 changes: 7 additions & 0 deletions
7
bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
36 changes: 36 additions & 0 deletions
36
bitgouel-api/src/main/kotlin/team/msg/domain/faq/service/FAQServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 { | ||
|
||
/** | ||
* 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( | ||
question = createFaqRequest.question, | ||
answer = createFaqRequest.answer, | ||
admin = admin | ||
) | ||
|
||
faqRepository.save(faq) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
bitgouel-domain/src/main/kotlin/team/msg/domain/fAQ/repository/FAQRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FAQ, UUID> { | ||
interface FaqRepository : CrudRepository<Faq, UUID> { | ||
} |