diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/presentation/InquiryController.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/presentation/InquiryController.kt index 3bf8afe6..52efb299 100644 --- a/src/main/kotlin/andreas311/miso/domain/inquiry/presentation/InquiryController.kt +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/presentation/InquiryController.kt @@ -1,5 +1,6 @@ package andreas311.miso.domain.inquiry.presentation +import andreas311.miso.domain.inquiry.enums.InquiryStatus import andreas311.miso.domain.inquiry.presentation.data.request.WriteInquiryRequestDto import andreas311.miso.domain.inquiry.presentation.data.response.DetailInquiryResponseDto import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto @@ -18,11 +19,13 @@ import org.springframework.web.multipart.MultipartFile @RequestController("/inquiry") class InquiryController( + private val listInquiryService: ListInquiryService, private val writeInquiryService: WriteInquiryService, private val listMyInquiryService: ListMyInquiryService, private val detailInquiryService: DetailInquiryService, private val listAllInquiryService: ListAllInquiryService, private val respondInquiryService: RespondInquiryService, + private val listFilterInquiryService: ListFilterInquiryService ) { @PostMapping @@ -43,6 +46,16 @@ class InquiryController( listAllInquiryService.execute() .let { ResponseEntity.status(HttpStatus.OK).body(it) } + @GetMapping("/list") + fun inquiryList(): ResponseEntity = + listInquiryService.execute() + .let { ResponseEntity.status(HttpStatus.OK).body(it) } + + @GetMapping("/filter/{state}") + fun inquiryFilter(@PathVariable(name = "state") inquiryStatus: InquiryStatus): ResponseEntity = + listFilterInquiryService.execute(inquiryStatus) + .let { ResponseEntity.status(HttpStatus.OK).body(it) } + @GetMapping("/{id}") fun detail(@PathVariable id: Long): ResponseEntity = detailInquiryService.execute(id) diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/repository/InquiryRepository.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/repository/InquiryRepository.kt index 2cc10229..5cba1f6c 100644 --- a/src/main/kotlin/andreas311/miso/domain/inquiry/repository/InquiryRepository.kt +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/repository/InquiryRepository.kt @@ -1,6 +1,7 @@ package andreas311.miso.domain.inquiry.repository import andreas311.miso.domain.inquiry.entity.Inquiry +import andreas311.miso.domain.inquiry.enums.InquiryStatus import andreas311.miso.domain.user.entity.User import org.springframework.data.repository.CrudRepository @@ -8,5 +9,9 @@ interface InquiryRepository : CrudRepository { fun findAllByOrderByCreatedDateDesc(): List - fun findByUserOrderByCreatedDateDesc(user: User): List? + fun findByUserOrderByCreatedDateDesc(user: User): List + + fun findAllByInquiryStatusOrderByCreatedDateDesc(inquiryStatus: InquiryStatus): List + + fun findByUserAndInquiryStatusOrderByCreatedDateDesc(user: User, inquiryStatus: InquiryStatus): List } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListFilterInquiryService.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListFilterInquiryService.kt new file mode 100644 index 00000000..3ef415a4 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListFilterInquiryService.kt @@ -0,0 +1,9 @@ +package andreas311.miso.domain.inquiry.service + +import andreas311.miso.domain.inquiry.enums.InquiryStatus +import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto + +interface ListFilterInquiryService { + + fun execute(inquiryStatus: InquiryStatus): ListInquiryResponseDto +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListInquiryService.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListInquiryService.kt new file mode 100644 index 00000000..ffd02275 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/service/ListInquiryService.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.inquiry.service + +import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto + +interface ListInquiryService { + + fun execute(): ListInquiryResponseDto +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListFilterInquiryServiceImpl.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListFilterInquiryServiceImpl.kt new file mode 100644 index 00000000..6ef45f1b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListFilterInquiryServiceImpl.kt @@ -0,0 +1,33 @@ +package andreas311.miso.domain.inquiry.service.impl + +import andreas311.miso.domain.inquiry.enums.InquiryStatus +import andreas311.miso.domain.inquiry.presentation.data.response.InquiryResponseDto +import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto +import andreas311.miso.domain.inquiry.repository.InquiryRepository +import andreas311.miso.domain.inquiry.service.ListFilterInquiryService +import andreas311.miso.domain.user.enums.Role +import andreas311.miso.global.annotation.ReadOnlyService +import andreas311.miso.global.util.UserUtil + +@ReadOnlyService +class ListFilterInquiryServiceImpl( + private val userUtil: UserUtil, + private val inquiryRepository: InquiryRepository +) : ListFilterInquiryService { + + override fun execute(inquiryStatus: InquiryStatus): ListInquiryResponseDto { + + val user = userUtil.currentUser() + + val inquiry = + if (user.role.equals(Role.ROLE_USER)) { + inquiryRepository.findByUserAndInquiryStatusOrderByCreatedDateDesc(user, inquiryStatus) + } else { + inquiryRepository.findAllByInquiryStatusOrderByCreatedDateDesc(inquiryStatus) + } + + return ListInquiryResponseDto( + inquiryList = inquiry.map { InquiryResponseDto(it) } + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListInquiryServiceImpl.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListInquiryServiceImpl.kt new file mode 100644 index 00000000..e5569dd1 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/service/impl/ListInquiryServiceImpl.kt @@ -0,0 +1,32 @@ +package andreas311.miso.domain.inquiry.service.impl + +import andreas311.miso.domain.inquiry.presentation.data.response.InquiryResponseDto +import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto +import andreas311.miso.domain.inquiry.repository.InquiryRepository +import andreas311.miso.domain.inquiry.service.ListInquiryService +import andreas311.miso.domain.user.enums.Role +import andreas311.miso.global.annotation.ReadOnlyService +import andreas311.miso.global.util.UserUtil + +@ReadOnlyService +class ListInquiryServiceImpl( + private val userUtil: UserUtil, + private val inquiryRepository: InquiryRepository +) : ListInquiryService { + + override fun execute(): ListInquiryResponseDto { + + val user = userUtil.currentUser() + + val inquiry = + if (user.role.equals(Role.ROLE_USER)) { + inquiryRepository.findByUserOrderByCreatedDateDesc(user) + } else { + inquiryRepository.findAllByOrderByCreatedDateDesc() + } + + return ListInquiryResponseDto( + inquiryList = inquiry.map { InquiryResponseDto(it) } + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt b/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt index f73ecf54..60855843 100644 --- a/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/SecurityConfig.kt @@ -59,7 +59,9 @@ class SecurityConfig( .antMatchers(HttpMethod.POST, "/inquiry").authenticated() .antMatchers(HttpMethod.GET, "/inquiry").authenticated() + .antMatchers(HttpMethod.GET, "/inquiry/list").authenticated() .antMatchers(HttpMethod.GET, "/inquiry/all").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.GET, "/inquiry/filter/{state}").authenticated() .antMatchers(HttpMethod.GET, "/inquiry/{id}").authenticated() .antMatchers(HttpMethod.PATCH, "/inquiry/respond/{id}").hasAuthority("ROLE_ADMIN")