-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Network- show memberList code (#6)
- Loading branch information
Showing
7 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
|
||
@Repository | ||
public interface GenerationRepository extends JpaRepository<Generation, Long> { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...c/main/java/com/gdscswu_server/server/domain/networking/controller/NetworkController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/com/gdscswu_server/server/domain/networking/dto/MemberListResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/gdscswu_server/server/domain/networking/dto/UserProfileResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); // 파트 처리 고민중... | ||
// } | ||
//} |
51 changes: 51 additions & 0 deletions
51
Server/src/main/java/com/gdscswu_server/server/domain/networking/service/NetworkService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
// } | ||
// } | ||
} |