Skip to content

Commit

Permalink
refactor: dto 클래스를 레코드로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hyena0608 committed Sep 20, 2023
1 parent 462fccd commit 2aff82d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ default ApplicantCountMappingDto findApplicantCountMappingByRunnerPostIds(final
final Map<Long, Long> applicantCountMapping = countApplicantsByRunnerPostIds(runnerPostIds)
.stream()
.collect(Collectors.toMap(
applicantCountDto -> applicantCountDto.getRunnerPostId(),
applicantCountDto -> applicantCountDto.getApplicantCount()
ApplicantCountDto::runnerPostId,
ApplicantCountDto::applicantCount
));

return new ApplicantCountMappingDto(applicantCountMapping);
Expand All @@ -34,7 +34,6 @@ default ApplicantCountMappingDto findApplicantCountMappingByRunnerPostIds(final
left outer join fetch SupporterRunnerPost srp on srp.runnerPost.id = rp.id
where rp.id in :runnerPostIds
group by rp.id
order by rp.id
""")
List<ApplicantCountDto> countApplicantsByRunnerPostIds(@Param("runnerPostIds") final List<Long> runnerPostIds);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
package touch.baton.domain.runnerpost.repository.dto;

import java.util.Objects;

public class ApplicantCountDto {

private Long runnerPostId;

private Long applicantCount;

public ApplicantCountDto() {
}

public ApplicantCountDto(final Long runnerPostId, final Long applicantCount) {
this.runnerPostId = runnerPostId;
this.applicantCount = (long) applicantCount;
}

public Long getRunnerPostId() {
return runnerPostId;
}

public Long getApplicantCount() {
return applicantCount;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final ApplicantCountDto that = (ApplicantCountDto) o;
return applicantCount == that.applicantCount && Objects.equals(runnerPostId, that.runnerPostId);
}

@Override
public int hashCode() {
return Objects.hash(runnerPostId, applicantCount);
}
public record ApplicantCountDto(Long runnerPostId, Long applicantCount) {
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
package touch.baton.domain.runnerpost.repository.dto;

import java.util.Map;
import java.util.Objects;

public class ApplicantCountMappingDto {

private final Map<Long, Long> applicantCounts;

public ApplicantCountMappingDto(final Map<Long, Long> applicantCounts) {
this.applicantCounts = applicantCounts;
}
public record ApplicantCountMappingDto(Map<Long, Long> applicantCounts) {

public Long getApplicantCountByRunnerPostId(final Long runnerPostId) {
return applicantCounts.get(runnerPostId);
}

public Map<Long, Long> getApplicantCounts() {
return applicantCounts;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final ApplicantCountMappingDto that = (ApplicantCountMappingDto) o;
return Objects.equals(applicantCounts, that.applicantCounts);
}

@Override
public int hashCode() {
return Objects.hash(applicantCounts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ default Long countApplicantByRunnerPostId(final Long runnerPostId) {
throw new IllegalArgumentException("테스트에서 러너 게시글 식별자값으로 서포터 지원자 수 조회에 실패하였습니다.");
}

return foundApplicants.get(0).getApplicantCount();
return foundApplicants.get(0).applicantCount();
}
}

0 comments on commit 2aff82d

Please sign in to comment.