Skip to content

Commit

Permalink
๐Ÿ› ์ปค๋ฎค๋‹ˆํ‹ฐ ๊ธ€ ์ž‘์„ฑ/์ˆ˜์ • API ๋ฒ„๊ทธ ์ˆ˜์ • (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwgyun authored Feb 2, 2025
1 parent e20eee4 commit ea3a234
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import backend.team.ahachul_backend.api.community.adapter.web.`in`.dto.*
import backend.team.ahachul_backend.api.community.application.command.`in`.DeleteCommunityPostCommand
import backend.team.ahachul_backend.api.community.application.command.`in`.GetCommunityPostCommand
import backend.team.ahachul_backend.api.community.application.port.`in`.CommunityPostUseCase
import backend.team.ahachul_backend.api.lost.adapter.web.`in`.dto.CreateLostPostDto
import backend.team.ahachul_backend.common.annotation.Authentication
import backend.team.ahachul_backend.common.dto.PageInfoDto
import backend.team.ahachul_backend.common.response.CommonResponse
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RestController
class CommunityPostController(
Expand Down Expand Up @@ -42,14 +44,21 @@ class CommunityPostController(

@Authentication
@PostMapping("/v1/community-posts")
fun createCommunityPost(request: CreateCommunityPostDto.Request): CommonResponse<CreateCommunityPostDto.Response> {
return CommonResponse.success(communityPostUseCase.createCommunityPost(request.toCommand()))
fun createCommunityPost(
@RequestPart(value = "content") request: CreateCommunityPostDto.Request,
@RequestPart(value = "files", required = false) imageFiles: List<MultipartFile>?
): CommonResponse<CreateCommunityPostDto.Response> {
return CommonResponse.success(communityPostUseCase.createCommunityPost(request.toCommand(imageFiles)))
}

@Authentication
@PostMapping("/v1/community-posts/{postId}")
fun updateCommunityPost(@PathVariable postId: Long, request: UpdateCommunityPostDto.Request): CommonResponse<UpdateCommunityPostDto.Response> {
return CommonResponse.success(communityPostUseCase.updateCommunityPost(request.toCommand(postId)))
fun updateCommunityPost(
@PathVariable postId: Long,
@RequestPart(value = "content") request: UpdateCommunityPostDto.Request,
@RequestPart(value = "files", required = false) imageFiles: List<MultipartFile>?
): CommonResponse<UpdateCommunityPostDto.Response> {
return CommonResponse.success(communityPostUseCase.updateCommunityPost(request.toCommand(postId, imageFiles)))
}

@Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class CreateCommunityPostDto {
val categoryType: CommunityCategoryType,
val hashTags: List<String> = listOf(),
val subwayLineId: Long,
val imageFiles: List<MultipartFile> = listOf()
) {
fun toCommand(): CreateCommunityPostCommand {
fun toCommand(imageFiles: List<MultipartFile>?): CreateCommunityPostCommand {
return CreateCommunityPostCommand(
title = title,
content = content,
Expand All @@ -36,10 +35,10 @@ class CreateCommunityPostDto {
val categoryType: CommunityCategoryType,
val region: RegionType,
val subwayLineId: Long,
val images: List<ImageDto> = arrayListOf()
val images: List<ImageDto>? = arrayListOf()
) {
companion object {
fun of(entity: CommunityPostEntity, images: List<ImageDto>): Response {
fun of(entity: CommunityPostEntity, images: List<ImageDto>?): Response {
return Response(
id = entity.id,
title = entity.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class UpdateCommunityPostDto {
val content: String,
val categoryType: CommunityCategoryType,
val hashTags: List<String>,
val uploadFiles: List<MultipartFile> = listOf(),
val removeFileIds: List<Long> = listOf()
) {
fun toCommand(postId: Long): UpdateCommunityPostCommand {
fun toCommand(postId: Long, uploadFiles: List<MultipartFile>?): UpdateCommunityPostCommand {
return UpdateCommunityPostCommand(
id = postId,
title = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ class CommunityPostService(
val subwayLine = subwayLineReader.getById(command.subwayLineId)
val communityPost = communityPostWriter.save(CommunityPostEntity.of(command, member, subwayLine))
communityPostHashTagService.createCommunityPostHashTag(communityPost, command.hashTags)
val images = communityPostFileService.createCommunityPostFiles(communityPost, command.imageFiles)

val images = command.imageFiles?.let {
communityPostFileService.createCommunityPostFiles(communityPost, command.imageFiles!!)
}

return CreateCommunityPostDto.Response.of(
communityPost,
Expand All @@ -126,7 +129,9 @@ class CommunityPostService(
communityPost.checkMe(memberId)
communityPost.update(command)
communityPostHashTagService.createCommunityPostHashTag(communityPost, command.hashTags)
communityPostFileService.createCommunityPostFiles(communityPost, command.uploadFiles)
command.uploadFiles?.let {
communityPostFileService.createCommunityPostFiles(communityPost, command.uploadFiles!!)
}
communityPostFileService.deleteCommunityPostFiles(command.removeFileIds)
val communityPostFiles = communityPostFileReader.findAllByPostId(communityPost.id)
return UpdateCommunityPostDto.Response.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class CreateCommunityPostCommand(
val categoryType: CommunityCategoryType,
val hashTags: List<String> = arrayListOf(),
val subwayLineId: Long,
val imageFiles: List<MultipartFile> = arrayListOf(),
val imageFiles: List<MultipartFile>? = arrayListOf(),
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UpdateCommunityPostCommand(
val content: String,
val categoryType: CommunityCategoryType,
val hashTags: List<String> = arrayListOf(),
val uploadFiles: List<MultipartFile> = arrayListOf(),
val uploadFiles: List<MultipartFile>? = arrayListOf(),
val removeFileIds: List<Long> = arrayListOf()
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package backend.team.ahachul_backend.api.community.domain.model

enum class CommunityCategoryType {
FREE, INSIGHT, ISSUE, HUMOR
FREE, INSIGHT, ISSUE
}

0 comments on commit ea3a234

Please sign in to comment.