Skip to content

Commit

Permalink
fix: Modify network controller (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanna29 committed Dec 6, 2023
1 parent 81b2224 commit 5b8d403
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Long> {
List<Project> findByMember(Member member);
Optional<Project> findByTitle(String title);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.gdscswu_server.server.domain.networking.controller;

import com.gdscswu_server.server.domain.networking.dto.MemberListResponseDto;
import com.gdscswu_server.server.domain.networking.dto.MemberResponseDto;
import com.gdscswu_server.server.domain.networking.service.NetworkService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
Expand All @@ -18,7 +16,7 @@ public class NetworkController {

// 멤버 리스트 응답
@GetMapping("")
public List<MemberListResponseDto> getAllMembers() {
public List<MemberResponseDto> getAllMembers() {
return networkService.findAllMembers();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.gdscswu_server.server.domain.networking.dto;

import com.gdscswu_server.server.domain.member.domain.Generation;
import com.gdscswu_server.server.domain.member.domain.Member;
import com.gdscswu_server.server.domain.member.domain.Project;
import lombok.Builder;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

@Getter
public class MemberDetailResponseDto {
public class GenerationResponseDto {
private Integer number; // 기수 (1기, 2기...)
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private List<String> part; // 솔챌 파트 (피엠, 디자인...)
@Builder
public MemberDetailResponseDto(Generation generation, List<Project> projects){
public GenerationResponseDto(Generation generation){
this.number=generation.getNumber();
this.department=generation.getDepartment();
this.level=generation.getLevel();
this.part=projects.stream()
.map(Project::getPart)
.collect(Collectors.toList());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gdscswu_server.server.domain.networking.dto;

import com.gdscswu_server.server.domain.member.domain.Member;
import com.gdscswu_server.server.domain.networking.domain.Bookmark;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -10,23 +9,24 @@

@Getter
@Setter
public class MemberListResponseDto {
public class MemberResponseDto {
private String name; // 이름
private String major; // 학과
private Integer admissionYear; // 학번
private String profileImagePath; // 프로필 사진
private boolean bookmark; // 북마크 저장 여부
private List<MemberDetailResponseDto> memberDetails;
private List<GenerationResponseDto> generationResponseDtoList;
private List<ProjectResponseDto> projectResponseDtoList;

@Builder
public MemberListResponseDto(Member member, boolean bookmark, List<MemberDetailResponseDto> memberDetailResponseDtoList){

public MemberResponseDto(Member member, boolean bookmark, List<GenerationResponseDto> generationResponseDtoList, List<ProjectResponseDto> projectResponseDtoList){
this.name=member.getName();
this.profileImagePath=member.getProfileImagePath();
this.major=member.getMajor();
this.admissionYear=member.getAdmissionYear();
this.bookmark=bookmark;
this.memberDetails=memberDetailResponseDtoList;
this.generationResponseDtoList= generationResponseDtoList;
this.projectResponseDtoList = projectResponseDtoList;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.gdscswu_server.server.domain.networking.dto;

import com.gdscswu_server.server.domain.member.domain.Project;
import lombok.Builder;
import lombok.Getter;

@Getter
public class ProjectResponseDto {
private String part; // 솔챌 파트 (피엠, 디자인...)
@Builder
public ProjectResponseDto(Project projects) {
this.part=projects.getPart();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import com.gdscswu_server.server.domain.member.domain.*;
import com.gdscswu_server.server.domain.networking.domain.BookmarkRepository;
import com.gdscswu_server.server.domain.networking.dto.MemberDetailResponseDto;
import com.gdscswu_server.server.domain.networking.dto.MemberListResponseDto;
import com.gdscswu_server.server.domain.networking.dto.MemberListUpdateRequestDto;
import com.gdscswu_server.server.domain.networking.dto.GenerationResponseDto;
import com.gdscswu_server.server.domain.networking.dto.MemberResponseDto;
import com.gdscswu_server.server.domain.networking.dto.ProjectResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -22,29 +19,39 @@ public class NetworkService {
public final ProjectRepository projectRepository;
public final BookmarkRepository bookmarkRepository;

public List<MemberListResponseDto> findAllMembers() {
List<Member> members = memberRepository.findAll();
return mapToMemberListResponseDtoList(members, false);

private List<GenerationResponseDto> createGenerationResponseDtoList(Member member) {
List<Generation> generations = generationRepository.findByMember(member);
return generations.stream()
.map(GenerationResponseDto::new)
.collect(Collectors.toList());
}

private List<ProjectResponseDto> createProjectResponseDtoList(Member member) {
List<Project> projects = projectRepository.findByMember(member);
return projects.stream()
.map(ProjectResponseDto::new)
.collect(Collectors.toList());
}

private List<MemberListResponseDto> mapToMemberListResponseDtoList(List<Member> members, boolean bookmark) {
public List<MemberResponseDto> findAllMembers() {
List<Member> members = memberRepository.findAll();
return members.stream()
.map(member -> {
List<MemberDetailResponseDto> memberDetailResponseDtoList = getMemberDetails(member);
return new MemberListResponseDto(member, bookmark, memberDetailResponseDtoList);
List<GenerationResponseDto> generationResponseDtoList = createGenerationResponseDtoList(member);
List<ProjectResponseDto> projectResponseDtoList = createProjectResponseDtoList(member);

return MemberResponseDto.builder()
.member(member)
.bookmark(false)
.generationResponseDtoList(generationResponseDtoList)
.projectResponseDtoList(projectResponseDtoList)
.build();
})
.collect(Collectors.toList());
}

private List<MemberDetailResponseDto> getMemberDetails(Member member) {
List<Generation> generations = generationRepository.findByMember(member);
List<Project> projects = projectRepository.findByMember(member);

return generations.stream()
.map(generation -> new MemberDetailResponseDto(generation, projects))
.collect(Collectors.toList());
}

/*@Transactional(readOnly = true)
public List<MemberListResponseDto> findFilteredMembers(String department, String part, String level) {
Expand All @@ -66,4 +73,4 @@ public ResponseEntity<Object> removeBookmark(){
}*/


}
}
Loading

0 comments on commit 5b8d403

Please sign in to comment.