Skip to content

Commit

Permalink
[♻️refactor/#129]: 검색 responseDto 필드 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JungYoonShin committed Sep 10, 2024
1 parent ff5400b commit 1c06d46
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,52 @@

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

public record SearchResultResponseDto(
int totalPages,
long totalCount,
Boolean hasNext,
List<SearchAnnouncementResponse> announcements
) {
@Builder
@Builder(access = PRIVATE)
public record SearchAnnouncementResponse(
Long internshipAnnouncementId,
Long scrapId,
String dDay,
String deadline,
long internshipAnnouncementId,
String companyImage,
String dDay,
String title,
String workingPeriod,
String startYearMonth,
String color
boolean isScrapped,
String color,
String deadline,
String startYearMonth

) {
public static SearchAnnouncementResponse from(final InternshipAnnouncement announcement, final Long scrapId, final String color) {
String startYearMonth = announcement.getStartYear() + "년 " + announcement.getStartMonth() + "월";
String deadline = DateUtil.convertDeadline(announcement.getDeadline());

public static SearchAnnouncementResponse from(
final InternshipAnnouncement announcement,
final Long scrapId,
final String color
) {
return SearchAnnouncementResponse.builder()
.internshipAnnouncementId(announcement.getId())
.scrapId(scrapId)
.dDay(DateUtil.convert(announcement.getDeadline()))
.deadline(deadline)
.companyImage(announcement.getCompany().getCompanyImage())
.dDay(DateUtil.convert(announcement.getDeadline()))
.title(announcement.getTitle())
.workingPeriod(announcement.getWorkingPeriod())
.startYearMonth(startYearMonth)
.isScrapped(scrapId!=null)
.color(color)
// .isScrapped(isScrapped)
.deadline(DateUtil.convertDeadline(announcement.getDeadline()))
.startYearMonth(announcement.getStartYear() + "년 " + announcement.getStartMonth() + "월")
.build();
}
}
public static SearchResultResponseDto of(int totalPages, Boolean hasNext, List<SearchAnnouncementResponse> announcements) {
return new SearchResultResponseDto(totalPages, hasNext, announcements);
public static SearchResultResponseDto of(
final int totalPages,
final long totalCount,
final Boolean hasNext,
final List<SearchAnnouncementResponse> announcements
) {
return new SearchResultResponseDto(totalPages, totalCount, hasNext, announcements);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface InternshipDetailService {

InternshipDetailResponseDto getInternshipDetail(Long internshipAnnouncementId, Long userId);
InternshipDetailResponseDto getInternshipDetail(long internshipAnnouncementId, long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class InternshipDetailServiceImpl implements InternshipDetailService {

@Override
@Transactional
public InternshipDetailResponseDto getInternshipDetail(Long internshipAnnouncementId, Long userId) {
public InternshipDetailResponseDto getInternshipDetail(long internshipAnnouncementId, long userId) {
InternshipAnnouncement announcement = internshipRepository.findById(internshipAnnouncementId)
.orElseThrow(() -> new CustomException(ErrorMessage.NOT_FOUND_INTERN_EXCEPTION));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SearchResultResponseDto searchInternshipAnnouncement(String keyword, Stri

List<InternshipAnnouncement> announcements = pageAnnouncements.getContent();

List<SearchResultResponseDto.SearchAnnouncementResponse> searchAnnouncementResponses = new ArrayList<>();
List<SearchResultResponseDto.SearchAnnouncementResponse> searchAnnouncementResponses;

List<Scrap> scraps = scrapRepository.findAllByInternshipAndUserId(announcements, userId);

Expand All @@ -57,12 +57,16 @@ public SearchResultResponseDto searchInternshipAnnouncement(String keyword, Stri
searchAnnouncementResponses = announcements.stream()
.map(a -> {
Scrap scrap = scrapMap.get(a.getId());
return SearchResultResponseDto.SearchAnnouncementResponse.from(a, scrap != null ? scrap.getId() : null, scrap != null ? scrap.getColor().getColorValue() : null);
return SearchResultResponseDto.SearchAnnouncementResponse.from(
a, scrap != null ? scrap.getId() : null,
scrap != null ? scrap.getColor().getColorValue() : null
);
})
.toList();

return new SearchResultResponseDto(
pageAnnouncements.getTotalPages(),
pageAnnouncements.getTotalElements(),
pageAnnouncements.hasNext(),
searchAnnouncementResponses
);
Expand Down

0 comments on commit 1c06d46

Please sign in to comment.