Skip to content

Commit

Permalink
feat: Add Read Member's info, Generation info, Project info API (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
suucong committed Dec 5, 2023
1 parent abaca9c commit e951521
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.gdscswu_server.server.domain.member.controller;

import com.gdscswu_server.server.domain.member.dto.GenerationResponseDto;
import com.gdscswu_server.server.domain.member.dto.MemberResponseDto;
import com.gdscswu_server.server.domain.member.dto.ProjectResponseDto;
import com.gdscswu_server.server.domain.member.service.MemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -11,8 +9,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
Expand All @@ -34,14 +30,4 @@ public ResponseEntity<ResponseDto> test(@AuthenticationPrincipal ContextUser con
public MemberResponseDto findById(@PathVariable Long id) {
return memberService.findById(id);
}

@GetMapping("/generation/{id}")
public List<GenerationResponseDto> findGenerationByMemberId(@PathVariable Long id) {
return memberService.findGenerationByMemberId(id);
}

@GetMapping("/project/{id}")
public List<ProjectResponseDto> findProjectByMemberId(@PathVariable Long id) {
return memberService.findProjectByMemberId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@Repository
public interface ProjectRepository extends JpaRepository<Project, Long> {
List<Project> findAllByMemberOrderById(Member member);
List<Project> findAllByMemberOrderByGenerationDesc(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.gdscswu_server.server.domain.member.domain.Member;
import lombok.Getter;

import java.util.List;

@Getter
public class MemberResponseDto {
private String name;
Expand All @@ -11,13 +13,17 @@ public class MemberResponseDto {
private String profileImagePath;
private String introduction;
private String email;
private List<GenerationResponseDto> generationResponseDtoList;
private List<ProjectResponseDto> projectResponseDtoList;

public MemberResponseDto(Member member) {
public MemberResponseDto(Member member, List<GenerationResponseDto> generationResponseDtoList, List<ProjectResponseDto> projectResponseDtoList) {
this.name = member.getName();
this.major = member.getMajor();
this.admissionYear = member.getAdmissionYear();
this.profileImagePath = member.getProfileImagePath();
this.introduction = member.getIntroduction();
this.email = member.getEmail();
this.generationResponseDtoList = generationResponseDtoList;
this.projectResponseDtoList = projectResponseDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,22 @@ public class MemberService {
private final GenerationRepository generationRepository;
private final ProjectRepository projectRepository;

// Get Member Information
// Read Member Information(Member Info, Generation, Project)
@Transactional(readOnly = true)
public MemberResponseDto findById(Long id) {
Optional<Member> optionalMember = memberRepository.findById(id);
if(optionalMember.isEmpty()) {
throw new IllegalArgumentException("해당 멤버가 없습니다. id = " + id);
}

return new MemberResponseDto(optionalMember.get());
}

@Transactional(readOnly = true)
public List<GenerationResponseDto> findGenerationByMemberId(Long id) {
Optional<Member> optionalMember = memberRepository.findById(id);
if(optionalMember.isEmpty()) {
throw new IllegalArgumentException("해당 멤버가 없습니다. id = " + id);
}

return generationRepository.findAllByMemberOrderByNumberDesc(optionalMember.get()).stream()
.map(GenerationResponseDto::new)
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public List<ProjectResponseDto> findProjectByMemberId(Long id) {
Optional<Member> optionalMember = memberRepository.findById(id);
if(optionalMember.isEmpty()) {
throw new IllegalArgumentException("해당 멤버가 없습니다. id = " + id);
}

return projectRepository.findAllByMemberOrderById(optionalMember.get()).stream()
List<GenerationResponseDto> generationResponseDtoList =
generationRepository.findAllByMemberOrderByNumberDesc(optionalMember.get()).stream()
.map(GenerationResponseDto::new)
.collect(Collectors.toList());
List<ProjectResponseDto> projectResponseDtoList = projectRepository.findAllByMemberOrderByGenerationDesc(optionalMember.get()).stream()
.map(ProjectResponseDto::new)
.collect(Collectors.toList());

return new MemberResponseDto(optionalMember.get(), generationResponseDtoList, projectResponseDtoList);
}
}

0 comments on commit e951521

Please sign in to comment.