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-164) 공지사항 상세조회 기능 추가 #37

Merged
merged 6 commits into from
Apr 13, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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.presentation.dto.response.FaqTitleAndTypeResponse
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryFaqTitleAndTypeService(
private val faqRepository: FaqRepository
) {

@Transactional(readOnly = true)
fun execute() =
faqRepository.findAll()
.map {
it ->
FaqTitleAndTypeResponse(
it.id!!,
it.faqType,
it.title
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Notice(
content: String,
isPinned: Boolean,
adminId: UUID,
fileName: String,
fileName: String?,
type: NoticeType
) {
this.title = title
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package hs.kr.equus.feed.domain.notice.presentation

import hs.kr.equus.feed.domain.notice.presentation.dto.request.CreateNoticeRequest
import hs.kr.equus.feed.domain.notice.presentation.dto.request.ModifyNoticeRequest
import hs.kr.equus.feed.domain.notice.presentation.dto.request.UpdateNoticeRequest
import hs.kr.equus.feed.domain.notice.presentation.dto.response.GetNoticeResponse
import hs.kr.equus.feed.domain.notice.presentation.dto.response.QueryNoticeTitleResponse
import hs.kr.equus.feed.domain.notice.service.*
import hs.kr.equus.feed.domain.notice.presentation.dto.response.UploadNoticeImageResponse
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
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
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import java.util.UUID
import javax.validation.Valid
Expand All @@ -23,8 +18,9 @@ import javax.validation.Valid
class NoticeController(
private val createNoticeService: CreateNoticeService,
private val uploadNoticeImageService: UploadNoticeImageService,
private val modifyNoticeService: ModifyNoticeService,
private val updateNoticeService: UpdateNoticeService,
private val queryNoticeTitleService: QueryNoticeTitleService,
private val getNoticeService: GetNoticeService,
private val deleteNoticeService: DeleteNoticeService
) {

Expand All @@ -40,19 +36,24 @@ class NoticeController(
@PatchMapping("/{notice-id}")
fun modifyNotice(
@PathVariable(name = "notice-id") id: UUID,
@RequestBody modifyNoticeRequest: ModifyNoticeRequest
) =
modifyNoticeService.execute(id, modifyNoticeRequest)
@RequestBody updateNoticeRequest: UpdateNoticeRequest
): ResponseEntity<String> =
updateNoticeService.execute(id, updateNoticeRequest)

@PostMapping("/image")
fun uploadImage(
@RequestPart(name = "photo") image: MultipartFile
) =
): UploadNoticeImageResponse =
uploadNoticeImageService.execute(image)

@GetMapping("/title")
fun queryTitle() =
queryNoticeTitleService.execute()
fun queryTitle(): List<QueryNoticeTitleResponse> = queryNoticeTitleService.execute()

@GetMapping("/{notice-id}")
fun getNotice(
@PathVariable(name = "notice-id", required = true)
noticeId: UUID
): GetNoticeResponse = getNoticeService.execute(noticeId)

@ResponseStatus(value = HttpStatus.NO_CONTENT)
@DeleteMapping("/{notice-id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size

data class ModifyNoticeRequest(
data class UpdateNoticeRequest(
@field:NotBlank(message = "title은 null, 공백, 띄어쓰기를 허용하지 않습니다.")
@Size(max = 100, message = "title은 최대 100자까지 가능합니다.")
val title: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hs.kr.equus.feed.domain.notice.presentation.dto.response

import hs.kr.equus.feed.domain.notice.domain.type.NoticeType
import java.time.LocalDateTime

data class GetNoticeResponse(
val title: String,
val content: String,
val createdAt: LocalDateTime,
val type: NoticeType,
val imageURL: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package hs.kr.equus.feed.domain.notice.service

import hs.kr.equus.feed.domain.notice.domain.repository.NoticeRepository
import hs.kr.equus.feed.domain.notice.exception.NoticeNotFoundException
import hs.kr.equus.feed.domain.notice.presentation.dto.response.GetNoticeResponse
import hs.kr.equus.feed.infrastructure.s3.util.notice.NoticeS3Util
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Transactional(readOnly = true)
@Service
class GetNoticeService(
private val noticeRepository: NoticeRepository,
private val noticeS3Util: NoticeS3Util
) {
fun execute(noticeId: UUID): GetNoticeResponse {
val notice = noticeRepository.findByIdOrNull(noticeId) ?: throw NoticeNotFoundException
val imageURL = notice.fileName?.let { noticeS3Util.generateObjectUrl(it) }

return notice.run {
GetNoticeResponse(
title = title,
content = content,
createdAt = createdAt,
type = type,
imageURL = imageURL
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@ package hs.kr.equus.feed.domain.notice.service

import hs.kr.equus.feed.domain.notice.domain.repository.NoticeRepository
import hs.kr.equus.feed.domain.notice.exception.NoticeNotFoundException
import hs.kr.equus.feed.domain.notice.presentation.dto.request.ModifyNoticeRequest
import hs.kr.equus.feed.domain.notice.presentation.dto.request.UpdateNoticeRequest
import hs.kr.equus.feed.global.utils.user.UserUtils
import hs.kr.equus.feed.infrastructure.s3.service.S3Service
import hs.kr.equus.feed.infrastructure.s3.PathList
import hs.kr.equus.feed.infrastructure.s3.util.FileUtil
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.UUID

@Service
class ModifyNoticeService(
class UpdateNoticeService(
private val noticeRepository: NoticeRepository,
private val userUtils: UserUtils,
private val s3Service: S3Service
private val fileUtil: FileUtil
) {
companion object {
const val PATH = "notice/"
}

@Transactional
fun execute(id: UUID, request: ModifyNoticeRequest): String {
fun execute(id: UUID, request: UpdateNoticeRequest): ResponseEntity<String> {
val adminId = userUtils.getCurrentUser().id
val notice = noticeRepository.findByIdOrNull(id) ?: throw NoticeNotFoundException
val fileName = request.fileName

request.run {
notice.modifyNotice(
title = title,
content = content,
isPinned = isPinned,
type = type,
fileName = request.fileName!!,
fileName = fileName,
adminId = adminId
)
}
return s3Service.generateObjectUrl(request.fileName!!, PATH)

fileName?.let { return ResponseEntity.ok(fileUtil.generateObjectUrl(it, PathList.NOTICE)) }
?: return ResponseEntity(HttpStatus.NO_CONTENT)
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package hs.kr.equus.feed.domain.notice.service

import hs.kr.equus.feed.domain.notice.presentation.dto.response.UploadNoticeImageResponse
import hs.kr.equus.feed.infrastructure.s3.service.S3Service
import hs.kr.equus.feed.infrastructure.s3.PathList
import hs.kr.equus.feed.infrastructure.s3.util.FileUtil
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile

@Service
class UploadNoticeImageService(
private val s3Service: S3Service
private val fileUtil: FileUtil
) {
companion object {
const val PATH = "notice/"
}

fun execute(image: MultipartFile): UploadNoticeImageResponse {
val fileName = s3Service.upload(image, PATH)
return UploadNoticeImageResponse(s3Service.generateObjectUrl(fileName, PATH), fileName)
val fileName = fileUtil.upload(image, PathList.NOTICE)
return UploadNoticeImageResponse(fileUtil.generateObjectUrl(fileName, PathList.NOTICE), fileName)
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package hs.kr.equus.feed.domain.question.presentation

import hs.kr.equus.feed.domain.question.domain.repository.QuestionRepository
import hs.kr.equus.feed.domain.question.presentation.dto.request.CreateQuestionRequest
import hs.kr.equus.feed.domain.question.presentation.dto.request.UpdateQuestionRequest
import hs.kr.equus.feed.domain.question.presentation.dto.response.QuestionDetailsResponse
import hs.kr.equus.feed.domain.question.presentation.dto.response.QuestionListResponse
import hs.kr.equus.feed.domain.question.service.*
import hs.kr.equus.feed.domain.question.service.CreateQuestionService
import hs.kr.equus.feed.domain.question.service.QueryMyQuestionService
import hs.kr.equus.feed.domain.question.service.QueryQuestionDetailsService
import hs.kr.equus.feed.domain.question.service.QueryQuestionListService
import hs.kr.equus.feed.domain.question.service.UpdateQuestionService
import hs.kr.equus.feed.domain.question.service.DeleteQuestionService
import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.DeleteMapping
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
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PatchMapping
import java.util.UUID

@RequestMapping("/question")
Expand All @@ -27,8 +31,7 @@ class QuestionController(
private val queryQuestionDetailsService: QueryQuestionDetailsService,
private val updateQuestionService: UpdateQuestionService,
private val queryMyQuestionService: QueryMyQuestionService,
private val deleteQuestionService: DeleteQuestionService,
private val questionRepository: QuestionRepository
private val deleteQuestionService: DeleteQuestionService
) {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
Expand All @@ -52,8 +55,7 @@ class QuestionController(
@PathVariable questionId: UUID,
@Validated @RequestBody
updateQuestionRequest: UpdateQuestionRequest
) =
updateQuestionService.execute(questionId, updateQuestionRequest)
) = updateQuestionService.execute(questionId, updateQuestionRequest)

@GetMapping
fun getMyQuestionList(): QuestionListResponse = queryMyQuestionService.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hs.kr.equus.feed.infrastructure.s3

object PathList {
const val NOTICE = "notice/"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hs.kr.equus.feed.infrastructure.s3.service
package hs.kr.equus.feed.infrastructure.s3.util

import com.amazonaws.HttpMethod
import com.amazonaws.services.s3.AmazonS3
Expand All @@ -14,12 +14,10 @@ import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.util.Date
import java.util.Locale
import java.util.UUID
import java.util.*

@Service
class S3Service(
class FileUtil(
private val amazonS3: AmazonS3
) {
@Value("\${cloud.aws.s3.bucket}")
Expand Down
Loading