Skip to content

Commit

Permalink
♻️ 유실물 생성, 업데이트, 삭제 리팩토링 (#260)
Browse files Browse the repository at this point in the history
* 🐛 유실물 생성, 업데이트 REST DOCS 에러 수정

* 🐛 유실물 추가, 삭제 요청 변수명 변경
: subwayLine -> subwayLineId

* 🐛 삭제/업데이트 API에서 categoryName 선택 필드로 변경
  • Loading branch information
hwgyun authored Nov 13, 2024
1 parent a8a3aa3 commit b557ddd
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
12 changes: 8 additions & 4 deletions application/src/docs/asciidoc/lost/posts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ include::{snippets}/get-lost-post/response-fields.adoc[]
include::{snippets}/create-lost-post/http-request.adoc[]
.Request Headers
include::{snippets}/create-lost-post/request-headers.adoc[]
.Request Fields
include::{snippets}/create-lost-post/request-fields.adoc[]
.Request Parts
include::{snippets}/create-lost-post/request-parts.adoc[]
.Request Parts - content
include::{snippets}/create-lost-post/request-part-content-fields.adoc[]
.Response
include::{snippets}/create-lost-post/http-response.adoc[]
.Response Fields
Expand All @@ -41,8 +43,10 @@ include::{snippets}/create-lost-post/response-fields.adoc[]
include::{snippets}/update-lost-post/http-request.adoc[]
.Request Headers
include::{snippets}/update-lost-post/request-headers.adoc[]
.Request Fields
include::{snippets}/update-lost-post/request-fields.adoc[]
.Request Parts
include::{snippets}/create-lost-post/request-parts.adoc[]
.Request Parts - content
include::{snippets}/create-lost-post/request-part-content-fields.adoc[]
.Response
include::{snippets}/update-lost-post/http-response.adoc[]
.Response Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CreateLostPostDto{
@NotNull val content: String,
@NotNull val subwayLine: Long,
@NotNull val lostType: LostType,
@NotNull val categoryName: String
val categoryName: String?
) {
fun toCommand(imageFiles: List<MultipartFile>?): CreateLostPostCommand {
return CreateLostPostCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UpdateLostPostDto {
val id: Long,
val title: String?,
val content: String?,
val subwayLine: Long?,
val subwayLineId: Long?,
val status: LostStatus?,
val removeFileIds: List<Long>? = arrayListOf(),
val categoryName: String?
Expand All @@ -21,7 +21,7 @@ class UpdateLostPostDto {
id = id,
title = title,
content = content,
subwayLine = subwayLine,
subwayLineId = subwayLineId,
status = status,
imageFiles = imageFiles,
removeFileIds = removeFileIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class LostPostService(
val memberId = RequestUtils.getAttribute("memberId")!!
val member = memberReader.getMember(memberId.toLong())
val subwayLine = subwayLineReader.getById(command.subwayLine)
val category = categoryReader.getCategoryByName(command.categoryName)
val category = command.categoryName?.let { categoryReader.getCategoryByName(it) }

val entity = lostPostWriter.save(
LostPostEntity.of(
Expand All @@ -166,7 +166,7 @@ class LostPostService(
val entity = lostPostReader.getLostPost(command.id)
entity.checkMe(memberId)

val subwayLine = command.subwayLine?.let {
val subwayLine = command.subwayLineId?.let {
subwayLineReader.getById(it)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ class LostPostControllerDocsTest: CommonDocsTestConfig() {
"content",
fieldWithPath("title").type(JsonFieldType.STRING).description("유실물 제목"),
fieldWithPath("content").type(JsonFieldType.STRING).description("유실물 내용"),
fieldWithPath("subwayLine").type(JsonFieldType.NUMBER).description("유실 호선 ID"),
fieldWithPath("subwayLineId").type(JsonFieldType.NUMBER).description("유실 호선 ID"),
fieldWithPath("lostType").type(JsonFieldType.STRING).description("유실물 타입").attributes(getFormatAttribute("LOST(유실) / ACQUIRE(습득)")),
fieldWithPath("categoryName").type(JsonFieldType.STRING).description("카테고리 이름").optional(),
// fieldWithPath("categoryName").type(JsonFieldType.STRING).description("카테고리 이름").optional(), // deprecated
),
responseFields(
*commonResponseFields(),
Expand Down Expand Up @@ -261,7 +261,7 @@ class LostPostControllerDocsTest: CommonDocsTestConfig() {
id = 1,
title = "title",
content = "content",
subwayLine = 1,
subwayLineId = 1,
status = LostStatus.COMPLETE,
removeFileIds = arrayListOf(1, 2, 3),
categoryName = "휴대폰"
Expand Down Expand Up @@ -311,11 +311,11 @@ class LostPostControllerDocsTest: CommonDocsTestConfig() {
fieldWithPath("title").type(JsonFieldType.STRING).description("유실물 제목").optional(),
fieldWithPath("content").type(JsonFieldType.STRING).description("유실물 내용").optional(),
fieldWithPath("imgUrls").type(JsonFieldType.ARRAY).description("유실물 이미지 리스트").optional(),
fieldWithPath("subwayLine").type(JsonFieldType.NUMBER).description("유실 호선 ID").optional(),
fieldWithPath("subwayLineId").type(JsonFieldType.NUMBER).description("유실 호선 ID").optional(),
fieldWithPath("status").type(JsonFieldType.STRING).description("유실물 찾기 완료 상태")
.attributes(getFormatAttribute( "PROGRESS / COMPLETE")).optional(),
fieldWithPath("removeFileIds").type(JsonFieldType.ARRAY).description("삭제할 유실물 이미지 번호 리스트"),
fieldWithPath("categoryName").type(JsonFieldType.STRING).description("카테고리 이름").optional()
// fieldWithPath("categoryName").type(JsonFieldType.STRING).description("카테고리 이름").optional() // deprecated
),
responseFields(
*commonResponseFields(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class LostPostServiceTest(
id = entity.id,
title = null,
content = "수정한 내용",
subwayLine = subwayLine.id,
subwayLineId = subwayLine.id,
status = LostStatus.COMPLETE,
categoryName = "지갑"
)
Expand All @@ -196,7 +196,7 @@ class LostPostServiceTest(
id = entity.id,
title = null,
content = "수정한 내용",
subwayLine = null,
subwayLineId = null,
status = LostStatus.COMPLETE,
categoryName = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class CreateLostPostCommand(
val content: String,
val subwayLine: Long,
val lostType: LostType,
val categoryName: String,
val categoryName: String?,
var imageFiles: List<MultipartFile>? = listOf()
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UpdateLostPostCommand (
val id: Long,
val title: String?,
val content: String?,
val subwayLine: Long?,
val subwayLineId: Long?,
val status: LostStatus?,
val imageFiles: List<MultipartFile>? = arrayListOf(),
val removeFileIds: List<Long>? = arrayListOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LostPostEntity(
const val MIN_BLOCK_REPORT_COUNT = 5

fun of(command: CreateLostPostCommand, member: MemberEntity,
subwayLine: SubwayLineEntity?, category: CategoryEntity
subwayLine: SubwayLineEntity?, category: CategoryEntity?
): LostPostEntity {
return LostPostEntity(
title = command.title,
Expand Down

0 comments on commit b557ddd

Please sign in to comment.