Skip to content

Commit

Permalink
feat: Modift Dto structure (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanna29 committed Dec 6, 2023
1 parent 6207e9b commit c22519a
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GenerationRepository extends JpaRepository<Generation, Long> {
List<Generation> findByMember(Member member);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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> findByMember(Member member);

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

import com.gdscswu_server.server.domain.networking.dto.MemberListResponseDto;
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;

@RestController
@RequiredArgsConstructor
Expand All @@ -15,9 +18,11 @@ public class NetworkController {

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

// 특정 조건 멤버 리스트 응답


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.Getter;

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

@Getter
public class MemberDetailResponseDto {
private Integer number; // 기수 (1기, 2기...)
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private List<String> part; // 솔챌 파트 (피엠, 디자인...)

public MemberDetailResponseDto(Generation generation, List<Project> project){
this.number=generation.getNumber();
this.department=generation.getDepartment();
this.level=generation.getLevel();
this.part=project.stream()
.map(Project::getPart)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
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.networking.domain.Bookmark;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@NoArgsConstructor
@Setter
public class MemberListResponseDto {
private Long id;
private String name; // 이름
private String profileImagePath; // 프로필 이미지
private String major; // 전공
private String major; // 학과
private Integer admissionYear; // 학번
private Integer number; // 기수 (1기, 2기...)
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private String part; // 파트 (피엠, 디자인...)
private String profileImagePath; // 프로필 사진
private boolean bookmark; // 북마크 저장 여부
private List<MemberDetailResponseDto> memberDetails;

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

public MemberListResponseDto(Generation generation){
this.id=generation.getMember().getId();
this.name=generation.getMember().getName();
this.profileImagePath=generation.getMember().getProfileImagePath();
this.major=generation.getMember().getMajor();
this.admissionYear=generation.getMember().getAdmissionYear();
this.number=generation.getNumber();
this.department=generation.getDepartment();
this.level=generation.getLevel();
//this.part=generation.
this.name=member.getName();
this.profileImagePath=member.getProfileImagePath();
this.major=member.getMajor();
this.admissionYear=member.getAdmissionYear();
this.bookmark=bookmark;
this.memberDetails=memberDetailResponseDtoList;
}


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

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class MemberListUpdateRequestDto {
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private String part; // 솔챌 파트 (피엠, 디자인...)

@Builder
public MemberListUpdateRequestDto(String department,String level,String part){
this.department=department;
this.level=level;
this.part=part;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.gdscswu_server.server.domain.networking.service;

import com.gdscswu_server.server.domain.member.domain.Generation;
import com.gdscswu_server.server.domain.member.domain.GenerationRepository;
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 lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.gdscswu_server.server.domain.member.domain.MemberRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
Expand All @@ -18,41 +19,51 @@
public class NetworkService {
public final MemberRepository memberRepository;
public final GenerationRepository generationRepository;
public final ProjectRepository projectRepository;
public final BookmarkRepository bookmarkRepository;

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

}

private List<MemberListResponseDto> mapToMemberListResponseDtoList(List<Member> members, boolean bookmark) {
return members.stream()
.map(member -> {
List<MemberDetailResponseDto> memberDetailResponseDtoList = getMemberDetails(member);
return new MemberListResponseDto(member, bookmark, memberDetailResponseDtoList);
})
.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) {
// 필요한 로직을 구현해 필터링된 멤버를 가져오세요.
List<Member> filteredMembers = // ...
return mapToMemberListResponseDtoList(filteredMembers, false); // 북마크 값은 여기서 고정으로 설정
}*/


/* @Transactional
public ResponseEntity<Object> addBookmark(){
// 멤버 보여주기
@Transactional (readOnly = true)
public ResponseEntity<Object> findAllMembers() {
try {
// member 찾아서 리스트로 수집하여 반환
List<MemberListResponseDto> memberList = generationRepository.findAll().stream()
.map(MemberListResponseDto::new)
.collect(Collectors.toList());

return ResponseEntity.ok(memberList);
} catch (Exception e) {
// 예외가 발생한 경우 클라이언트에게 적절한 응답을 보내줌
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("멤버 리스트 조회 실패" + e.getMessage());

}
}
@Transactional
public ResponseEntity<Object> removeBookmark(){
}*/


// 유저(나) 보여주기
// @Transactional (readOnly = true)
// public ResponseEntity<Object> findByUser (Long userId){
// try{
// // 로그인 한 유저 (나) 생성될 때 담았던 id 값으로 디비에서 "나" 찾아오기
// Generation user = generationRepository.findById(userId)
// .orElseThrow(() -> new IllegalArgumentException());
//
// UserProfileResponseDto userProfileResponseDto = new UserProfileResponseDto(user);
// return ResponseEntity.ok("유저 조회 성공 "+ userProfileResponseDto);
// } catch (IllegalArgumentException e) {
// return ResponseEntity.badRequest().body("유저 조회 실패: " + e.getMessage());
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
// .body("서버 오류: " + e.getMessage());
// }
// }
}

0 comments on commit c22519a

Please sign in to comment.