Skip to content

Commit

Permalink
Merge pull request #13 from gutanbug/fix/post_search
Browse files Browse the repository at this point in the history
fix : 모든 게시물 검색 시 리턴 타입 ResponsePage로 변경 및 Dto 슬라이스 추가
  • Loading branch information
gutanbug authored May 2, 2024
2 parents 4a6114a + 4f4f7b2 commit 2b70d01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@
import com.dku.council.domain.post.model.entity.Post;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class ResponseSingleSearchPost {

private final Long id;

private final String title;

private final String body;

private final LocalDateTime createdAt;

public ResponseSingleSearchPost(Post post) {
this.id = post.getId();
this.title = post.getTitle();
this.title = sliceTitle(post.getTitle());
this.body = sliceBody(post.getBody());
this.createdAt = post.getCreatedAt();
}

private String sliceTitle(String title) {
if (title.length() > 50) {
return title.substring(0, 50);
}
return title;
}

private String sliceBody(String body) {
if (body.length() > 100) {
return body.substring(0, 100);
}
return body;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dku.council.domain.post.service.post;

import com.dku.council.domain.post.model.dto.response.ResponsePage;
import com.dku.council.domain.post.model.dto.response.ResponseSingleSearchPost;
import com.dku.council.domain.post.model.entity.posttype.*;
import com.dku.council.domain.post.repository.post.*;
Expand Down Expand Up @@ -35,11 +36,11 @@ public SummarizedPostSearchDto searchPost(String keyword, Pageable pageable) {
Page<Conference> conferences = getConferencesLists(keyword, pageable);
Page<Rule> rules = getRulesLists(keyword, pageable);
return new SummarizedPostSearchDto(
notices.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()),
coalitions.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()),
petitions.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()),
conferences.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()),
rules.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList())
new ResponsePage<>(notices.map(ResponseSingleSearchPost::new)),
new ResponsePage<>(coalitions.map(ResponseSingleSearchPost::new)),
new ResponsePage<>(petitions.map(ResponseSingleSearchPost::new)),
new ResponsePage<>(conferences.map(ResponseSingleSearchPost::new)),
new ResponsePage<>(rules.map(ResponseSingleSearchPost::new))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dku.council.domain.post.service.post;

import com.dku.council.domain.post.model.dto.response.ResponsePage;
import com.dku.council.domain.post.model.dto.response.ResponseSingleSearchPost;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -10,14 +11,14 @@
@RequiredArgsConstructor
public class SummarizedPostSearchDto {

private final List<ResponseSingleSearchPost> notices;
private final ResponsePage<ResponseSingleSearchPost> notices;

private final List<ResponseSingleSearchPost> coalitions;
private final ResponsePage<ResponseSingleSearchPost> coalitions;

private final List<ResponseSingleSearchPost> petitions;
private final ResponsePage<ResponseSingleSearchPost> petitions;

private final List<ResponseSingleSearchPost> conferences;
private final ResponsePage<ResponseSingleSearchPost> conferences;

private final List<ResponseSingleSearchPost> rules;
private final ResponsePage<ResponseSingleSearchPost> rules;

}

0 comments on commit 2b70d01

Please sign in to comment.