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

master 로 머지 #144

Merged
merged 10 commits into from
Jan 4, 2024
Merged
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -43,6 +46,16 @@ class InquiryController(
listAllInquiryService.execute()
.let { ResponseEntity.status(HttpStatus.OK).body(it) }

@GetMapping("/list")
fun inquiryList(): ResponseEntity<ListInquiryResponseDto> =
listInquiryService.execute()
.let { ResponseEntity.status(HttpStatus.OK).body(it) }

@GetMapping("/filter/{state}")
fun inquiryFilter(@PathVariable(name = "state") inquiryStatus: InquiryStatus): ResponseEntity<ListInquiryResponseDto> =
listFilterInquiryService.execute(inquiryStatus)
.let { ResponseEntity.status(HttpStatus.OK).body(it) }

@GetMapping("/{id}")
fun detail(@PathVariable id: Long): ResponseEntity<DetailInquiryResponseDto> =
detailInquiryService.execute(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
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

interface InquiryRepository : CrudRepository<Inquiry, Long> {

fun findAllByOrderByCreatedDateDesc(): List<Inquiry>

fun findByUserOrderByCreatedDateDesc(user: User): List<Inquiry>?
fun findByUserOrderByCreatedDateDesc(user: User): List<Inquiry>

fun findAllByInquiryStatusOrderByCreatedDateDesc(inquiryStatus: InquiryStatus): List<Inquiry>

fun findByUserAndInquiryStatusOrderByCreatedDateDesc(user: User, inquiryStatus: InquiryStatus): List<Inquiry>
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.domain.inquiry.service

import andreas311.miso.domain.inquiry.presentation.data.response.ListInquiryResponseDto

interface ListInquiryService {

fun execute(): ListInquiryResponseDto
}
Original file line number Diff line number Diff line change
@@ -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) }
)
}
}
Original file line number Diff line number Diff line change
@@ -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) }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down