Skip to content

Commit

Permalink
feat: MemberDetailResponse 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Nov 5, 2023
1 parent b448b19 commit 75cd542
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.emmsale.login.application.dto.MemberQueryResponse;
import com.emmsale.member.application.dto.MemberProfileResponse;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberActivityRepository;
import com.emmsale.member.domain.MemberRepository;
import com.emmsale.member.exception.MemberException;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,6 +19,7 @@
public class MemberQueryService {

private final MemberRepository memberRepository;
private final MemberActivityRepository memberActivityRepository;

public Member findById(final Long memberId) {
return memberRepository.findById(memberId)
Expand All @@ -34,9 +36,8 @@ public MemberQueryResponse findOrCreateMember(
return new MemberQueryResponse(member.getId(), member.isOnboarded());
}

public MemberProfileResponse findProfile(Long memberId) {
final Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberException(NOT_FOUND_MEMBER));
public MemberProfileResponse findProfile(final Long memberId) {
final Member member = memberRepository.getByIdOrElseThrow(memberId);

return MemberProfileResponse.from(member);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.emmsale.member.application.dto;

import static java.util.stream.Collectors.toUnmodifiableList;

import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberActivity;
import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public class MemberDetailResponse {

private static final String GITHUB_URL_PREFIX = "https://github.com/";

private final Long id;
private final String name;
private final String description;
private final String imageUrl;
private final String githubUrl;
private final List<MemberActivityResponse> activities;

public static MemberDetailResponse from(
final Member member,
final List<MemberActivity> activities
) {
final List<MemberActivityResponse> memberActivityResponses = activities.stream()
.map(MemberActivityResponse::from)
.collect(toUnmodifiableList());

return new MemberDetailResponse(
member.getId(),
member.getName(),
member.getDescription(),
member.getImageUrl(),
GITHUB_URL_PREFIX + member.getGithubUsername(),
memberActivityResponses
);
}
}

0 comments on commit 75cd542

Please sign in to comment.