Skip to content

Commit

Permalink
♻️ 게시글 조회 시 즐겨찾는 역 배열로 받도록 수정 (#349) (#351)
Browse files Browse the repository at this point in the history
* ♻️ 유실물 검색 subwayLine 필드 수정

* ♻️ 커뮤니티 검색 subwayLine 필드 및 버그 수정

* ♻️ 민원 subwayLine 필드 수정

* 🐛 오타 수정
  • Loading branch information
semi-cloud authored Mar 1, 2025
1 parent 127fbe8 commit 9169632
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import org.springframework.data.domain.Sort
class SearchCommunityHotPostDto {

data class Request(
val subwayLineId: Long?,
val subwayLineIds: String?,
val content: String?,
val hashTag: String?,
val writer: String?,
val sort: String
) {
fun toCommand(pageToken: String?, pageSize: Int): SearchCommunityHotPostCommand {
return SearchCommunityHotPostCommand(
subwayLineId = subwayLineId,
subwayLineIds = subwayLineIds?.let {
it.split(",").map { x -> x.toLong() }
},
content = content,
hashTag = hashTag,
writer = writer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SearchCommunityPostDto {

data class Request(
val categoryType: CommunityCategoryType?,
val subwayLineId: Long?,
val subwayLineIds: String?,
val content: String?,
val hashTag: String?,
val writer: String?,
Expand All @@ -19,7 +19,9 @@ class SearchCommunityPostDto {
fun toCommand(pageToken: String?, pageSize: Int): SearchCommunityPostCommand {
return SearchCommunityPostCommand(
categoryType = categoryType,
subwayLineId = subwayLineId,
subwayLineIds = subwayLineIds?.let {
it.split(",").map { x -> x.toLong() }
},
content = content,
hashTag = hashTag,
writer = writer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class CommunityPostService(

override fun searchCommunityPosts(command: SearchCommunityPostCommand): PageInfoDto<SearchCommunityPostDto.Response> {
val userId: String? = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)
val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) }
val subwayLines = command.subwayLineIds?.stream()
?.map { subwayLineReader.getById(it) }
?.toList()

val searchCommunityPosts = communityPostReader.searchCommunityPosts(
GetSliceCommunityPostCommand.from(
command = command,
subwayLine = subwayLine
subwayLines = subwayLines
)
)

Expand All @@ -67,12 +69,14 @@ class CommunityPostService(

override fun searchCommunityHotPosts(command: SearchCommunityHotPostCommand): PageInfoDto<SearchCommunityPostDto.Response> {
val userId: String? = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)
val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) }
val subwayLines = command.subwayLineIds?.stream()
?.map { subwayLineReader.getById(it) }
?.toList()

val searchCommunityHotPosts = communityPostReader.searchCommunityHotPosts(
GetSliceCommunityHotPostCommand.from(
command = command,
subwayLine = subwayLine
subwayLines = subwayLines
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import backend.team.ahachul_backend.common.dto.ImageDto
class SearchComplaintPostDto {

data class Request(
val subwayLineId: Long?,
val subwayLineIds: String?,
val keyword: String?,
) {
fun toCommand(pageToken: String?, pageSize: Int): SearchComplaintPostCommand {
return SearchComplaintPostCommand(
subwayLineId = subwayLineId,
subwayLineIds = subwayLineIds?.let {
it.split(",").map { x -> x.toLong() }
},
keyword = keyword,
pageToken = pageToken,
pageSize = pageSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class ComplaintPostService(
): ComplaintPostUseCase {

override fun searchComplaintPosts(command: SearchComplaintPostCommand): PageInfoDto<SearchComplaintPostDto.Response> {
val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) }
val subwayLines = command.subwayLineIds?.stream()
?.map { subwayLineReader.getById(it) }
?.toList()

val complaintPosts = complaintPostReader.getComplaintPosts(
GetSliceComplaintPostsCommand.of(
command = command,
subwayLine = subwayLine
subwayLines = subwayLines
)
).map {
val file = complaintPostFileReader.findByPostId(it.id)?.file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ class SearchLostPostsDto {

data class Request(
val lostType: LostType,
val subwayLineId: Long?,
val subwayLineIds: String?,
val category: String?,
val keyword: String?,
) {
fun toCommand(pageToken: String?, pageSize: Int): SearchLostPostCommand {
return SearchLostPostCommand(
lostType = lostType,
subwayLineId = subwayLineId,
subwayLineIds = subwayLineIds?.let {
it.split(",").map { x -> x.toLong() }
},
keyword = keyword,
category = category,
pageToken = pageToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ class LostPostService(
}

override fun searchLostPosts(command: SearchLostPostCommand): PageInfoDto<SearchLostPostsDto.Response> {
val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) }
val subwayLines = command.subwayLineIds?.stream()
?.map { subwayLineReader.getById(it) }
?.toList()

val category = command.category?.let { categoryReader.getCategoryByName(it) }

val lostPostList = lostPostReader.getLostPosts(
GetSliceLostPostsCommand.from(
command=command, subwayLine=subwayLine, category=category
command=command, subwayLines=subwayLines, category=category
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CommunityPostControllerDocsTest : CommonDocsTestConfig() {
val result = mockMvc.perform(
get("/v1/community-posts")
.queryParam("categoryType", "ISSUE")
.queryParam("subwayLineId", "1")
.queryParam("subwayLineIds", "1,2")
.queryParam("content", "내용")
.queryParam("hashTag", "여행")
.queryParam("writer", "작성자")
Expand All @@ -87,7 +87,7 @@ class CommunityPostControllerDocsTest : CommonDocsTestConfig() {
getDocsResponse(),
queryParameters(
parameterWithName("categoryType").description("카테고리 타입").attributes(getFormatAttribute("FREE, INSIGHT, ISSUE, HUMOR")).optional(),
parameterWithName("subwayLineId").description("노선 ID").optional(),
parameterWithName("subwayLineIds").description("노선 ID 리스트").optional(),
parameterWithName("content").description("검색하고자 하는 내용").optional(),
parameterWithName("hashTag").description("검색하고자 하는 해시 태그").optional(),
parameterWithName("hotPostYn").description("검색하고자 하는 핫 게시글 여부").optional(),
Expand Down Expand Up @@ -153,7 +153,7 @@ class CommunityPostControllerDocsTest : CommonDocsTestConfig() {
// when
val result = mockMvc.perform(
get("/v1/community-hot-posts")
.queryParam("subwayLineId", "1")
.queryParam("subwayLineIds", "1,2")
.queryParam("content", "내용")
.queryParam("hashTag", "여행")
.queryParam("writer", "작성자")
Expand All @@ -172,7 +172,7 @@ class CommunityPostControllerDocsTest : CommonDocsTestConfig() {
getDocsRequest(),
getDocsResponse(),
queryParameters(
parameterWithName("subwayLineId").description("노선 ID").optional(),
parameterWithName("subwayLineIds").description("노선 ID 리스트").optional(),
parameterWithName("content").description("검색하고자 하는 내용").optional(),
parameterWithName("hashTag").description("검색하고자 하는 해시 태그").optional(),
parameterWithName("writer").description("검색하고자 하는 작성자 닉네임").optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class CommunityPostServiceTest(

val verifyNameCommand = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = "",
hashTag = null,
writer = null,
Expand All @@ -286,7 +286,7 @@ class CommunityPostServiceTest(
)
val verifyNameCommand2 = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = "지하철",
hashTag = null,
writer = null,
Expand All @@ -296,7 +296,7 @@ class CommunityPostServiceTest(
)
val verifyNameCommand3 = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = "지하철",
hashTag = null,
writer = null,
Expand All @@ -306,7 +306,7 @@ class CommunityPostServiceTest(
)
val verifyOrderCommand = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = null,
writer = null,
Expand Down Expand Up @@ -359,7 +359,7 @@ class CommunityPostServiceTest(

val verifyCategoryCommand = SearchCommunityPostCommand(
categoryType = CommunityCategoryType.FREE,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = null,
writer = null,
Expand All @@ -369,7 +369,7 @@ class CommunityPostServiceTest(
)
val verifyCategoryCommand2 = SearchCommunityPostCommand(
categoryType = CommunityCategoryType.ISSUE,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = null,
writer = null,
Expand Down Expand Up @@ -411,7 +411,7 @@ class CommunityPostServiceTest(

val verifyHashTagCommand = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = "여행",
writer = null,
Expand All @@ -421,7 +421,7 @@ class CommunityPostServiceTest(
)
val verifyHashTagCommand2 = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = "취미",
writer = null,
Expand Down Expand Up @@ -461,7 +461,7 @@ class CommunityPostServiceTest(

val verifyWriterCommand = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = null,
content = null,
hashTag = null,
writer = "nickname",
Expand Down Expand Up @@ -493,7 +493,7 @@ class CommunityPostServiceTest(
// when
val searchCommand1 = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = listOf(subwayLine.id),
content = null,
hashTag = null,
writer = null,
Expand All @@ -506,7 +506,7 @@ class CommunityPostServiceTest(

val searchCommand2 = SearchCommunityPostCommand(
categoryType = null,
subwayLineId = null,
subwayLineIds = listOf(subwayLine.id),
content = null,
hashTag = null,
writer = null,
Expand Down Expand Up @@ -556,7 +556,7 @@ class CommunityPostServiceTest(

val result = communityPostUseCase.searchCommunityHotPosts(
SearchCommunityHotPostCommand(
subwayLineId = null,
subwayLineIds = listOf(subwayLine.id),
content = null,
hashTag = null,
writer = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ComplaintPostControllerDocsTest : CommonDocsTestConfig() {
// when
val result = mockMvc.perform(
get("/v1/complaint-posts")
.queryParam("subwayLineId", "1")
.queryParam("subwayLineIds", "1,2")
.queryParam("keyword", "검색 키워드 이름")
.queryParam("pageToken", "MTIzMTI5MTU6MTI=")
.queryParam("pageSize", "10")
Expand All @@ -80,7 +80,7 @@ class ComplaintPostControllerDocsTest : CommonDocsTestConfig() {
getDocsRequest(),
getDocsResponse(),
queryParameters(
parameterWithName("subwayLineId").description("민원 호선").optional(),
parameterWithName("subwayLineIds").description("민원 호선 리스트").optional(),
parameterWithName("keyword").description("검색 키워드 명칭").optional(),
parameterWithName("pageToken").description("base64로 인코딩 된 페이지 토큰 문자열").optional(),
parameterWithName("pageSize").description("페이지 노출 데이터 수. index 0부터 시작"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ComplaintPostServiceTest(

lateinit var member: MemberEntity
lateinit var subwayLine: SubwayLineEntity
lateinit var subwayLine2: SubwayLineEntity

@BeforeEach
fun setUp() {
Expand All @@ -55,6 +56,12 @@ class ComplaintPostServiceTest(
regionType = RegionType.METROPOLITAN
)
)
subwayLine2 = subwayLineRepository.save(
SubwayLineEntity(
name = "2호선",
regionType = RegionType.METROPOLITAN
)
)
}

@Test
Expand All @@ -76,7 +83,7 @@ class ComplaintPostServiceTest(

// when
val searchComplaintPostCommand = SearchComplaintPostCommand(
subwayLineId = subwayLine.id,
subwayLineIds = listOf(subwayLine.id),
keyword = null,
pageToken = null,
pageSize = 10
Expand Down Expand Up @@ -121,7 +128,7 @@ class ComplaintPostServiceTest(

// when
val searchComplaintPostCommand = SearchComplaintPostCommand(
subwayLineId = null,
subwayLineIds = listOf(subwayLine.id),
keyword = "",
pageToken = null,
pageSize = 10
Expand All @@ -134,6 +141,53 @@ class ComplaintPostServiceTest(
assertThat(searchComplaintPosts.data[0].content).isEqualTo(complaintPost1.content)
}

@Test
fun 민원_조회_즐겨찾는_역() {
// given
val createComplaintPostCommand1 = CreateComplaintPostCommand(
complaintType = ComplaintType.ENVIRONMENTAL_COMPLAINT,
shortContentType = ShortContentType.SELF,
content = "내용",
phoneNumber = null,
trainNo = null,
location = null,
subwayLineId = subwayLine.id,
imageFiles = listOf(),
)

val createComplaintPostCommand2 = CreateComplaintPostCommand(
complaintType = ComplaintType.ENVIRONMENTAL_COMPLAINT,
shortContentType = ShortContentType.SELF,
content = "123",
phoneNumber = null,
trainNo = null,
location = null,
subwayLineId = subwayLine2.id,
imageFiles = listOf(),
)

val complaintPost1 = ComplaintPostEntity.of(createComplaintPostCommand1, member, subwayLine)
val complaintPost2 = ComplaintPostEntity.of(createComplaintPostCommand2, member, subwayLine2)
complaintPostRepository.save(complaintPost1)
complaintPostRepository.save(complaintPost2)

// when
val searchComplaintPostCommand = SearchComplaintPostCommand(
subwayLineIds = listOf(subwayLine.id, subwayLine2.id),
keyword = null,
pageToken = null,
pageSize = 10
)
val searchComplaintPosts = complaintPostUseCase.searchComplaintPosts(searchComplaintPostCommand)

// then
assertThat(searchComplaintPosts.data).hasSize(2)
assertThat(searchComplaintPosts.data[0].id).isEqualTo(complaintPost2.id)
assertThat(searchComplaintPosts.data[0].content).isEqualTo(complaintPost2.content)
assertThat(searchComplaintPosts.data[1].id).isEqualTo(complaintPost1.id)
assertThat(searchComplaintPosts.data[1].content).isEqualTo(complaintPost1.content)
}

@Test
fun 민원_상세_조회() {
// given
Expand Down
Loading

0 comments on commit 9169632

Please sign in to comment.