Skip to content

Commit

Permalink
feat: Add Read Project API (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
suucong committed Dec 3, 2023
1 parent db1bf52 commit dc3e45c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 Down Expand Up @@ -38,4 +39,9 @@ public MemberResponseDto findById(@PathVariable Long id) {
public List<GenerationResponseDto> findByMemberId(@PathVariable Long id) {
return memberService.findByMemberId(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 @@ -3,6 +3,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Long> {
List<Project> findAllByMemberOrderById(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.gdscswu_server.server.domain.member.domain.GenerationRepository;
import com.gdscswu_server.server.domain.member.domain.Member;
import com.gdscswu_server.server.domain.member.domain.MemberRepository;
import com.gdscswu_server.server.domain.member.domain.ProjectRepository;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,6 +20,7 @@
public class MemberService {
private final MemberRepository memberRepository;
private final GenerationRepository generationRepository;
private final ProjectRepository projectRepository;

// Get Member Information
@Transactional(readOnly = true)
Expand All @@ -41,4 +44,16 @@ public List<GenerationResponseDto> findByMemberId(Long id) {
.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()
.map(ProjectResponseDto::new)
.collect(Collectors.toList());
}
}

0 comments on commit dc3e45c

Please sign in to comment.