Skip to content

Commit

Permalink
feat: Network- show memberList code (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanna29 committed Dec 3, 2023
1 parent 89597a2 commit 883e0d7
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gdscswu_server.server.domain.member.domain;

import com.gdscswu_server.server.domain.model.Role;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;

import java.util.Objects;
Expand Down Expand Up @@ -37,6 +39,14 @@ public boolean equals(Object obj) {
Objects.equals(this.number, generation.getNumber());
}

@Builder
public Generation(Member member, Integer number, String department,String level) {
this.member = member;
this.number = number;
this.department = department;
this.level = level;
}

@Override
public int hashCode() {
return Objects.hash(id, member, number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

@Repository
public interface GenerationRepository extends JpaRepository<Generation, Long> {

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

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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/network")
public class NetworkController {
private final NetworkService networkService;

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


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

@Getter
@NoArgsConstructor
public class MemberListResponseDto {
private Long id;
private String name; // 이름
private String profileImagePath; // 프로필 이미지
private String major; // 전공
private Integer admissionYear; // 학번
private Integer number; // 기수 (1기, 2기...)
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private String part; // 파트 (피엠, 디자인...)


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.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//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;
//
//
//public class UserProfileResponseDto {
// private Long id;
// private String name; // 이름
// private String profileImagePath; // 프로필 이미지
// private Integer number; // 기수 (1기, 2기...)
// private String department; // 부서
// private String level; // 레벨 (코어, 리드...)
// private String part; // 파트 (피엠, 디자인...)
//
// // 생성자
// public UserProfileResponseDto(Generation generation){
// this.id=generation.getId();
// this.name=generation.getMember().getName();
// this.profileImagePath=generation.getMember().getProfileImagePath();
// this.number=generation.getNumber();
// this.department=generation.getDepartment();
// this.level=generation.getLevel();
// //this.part=project.getPart(); // 파트 처리 고민중...
// }
//}
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
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.networking.dto.MemberListResponseDto;
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;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Service
public class NetworkService {
public final MemberRepository memberRepository;
public final GenerationRepository generationRepository;

// 멤버 보여주기
@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 (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 883e0d7

Please sign in to comment.