Skip to content

Commit

Permalink
Merge pull request #46 from NOzigak/feature/recruitt
Browse files Browse the repository at this point in the history
feat:studymember조회
  • Loading branch information
1224kang authored Jul 13, 2024
2 parents b412dc8 + 036c4fa commit eaba24b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ public ResponseEntity<ResultDto<String>> approveMember(@PathVariable Long study_


}


}
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package hamsung.hamsung_project.controller;

import hamsung.hamsung_project.dto.ApplyingSummaryDto;
import hamsung.hamsung_project.dto.MemberSummaryDto;
import hamsung.hamsung_project.service.StudyMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
@RequiredArgsConstructor
public class StudyMemberController {
private final StudyMemberService studyMemberService;

//스터디 멤버 조회
@GetMapping("studymember/{study_id}")
public ResponseEntity<List<MemberSummaryDto>> findAllMembers(@PathVariable Long study_id) {
try {
List<MemberSummaryDto> memberList = studyMemberService.findAllMembers(study_id);
return ResponseEntity.status(HttpStatus.OK).body(memberList);
} catch (IllegalArgumentException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
// List<ApplySummaryDto> appliedList=studyMemberService.findAllAppliers(study_id);
// return ResponseEntity.status(HttpStatus.OK).body(appliedList);
}


}
30 changes: 30 additions & 0 deletions src/main/java/hamsung/hamsung_project/dto/MemberSummaryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hamsung.hamsung_project.dto;

import hamsung.hamsung_project.entity.StudyMember;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
public class MemberSummaryDto {
private Long id;
private String username;

public static MemberSummaryDto createSummaryDto (StudyMember studyMember){
if (studyMember == null || studyMember.getUsers() == null) {
throw new IllegalArgumentException("스터디 멤버나 스터디는 null이 될 수 없음");
}

return new MemberSummaryDto(
studyMember.getUsers().getId(),
studyMember.getUsers().getUsername()
);

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hamsung.hamsung_project.dto.ApplyingSummaryDto;
import hamsung.hamsung_project.dto.ApplyingDto;
import hamsung.hamsung_project.dto.MemberSummaryDto;
import hamsung.hamsung_project.dto.StudyMemberDto;
import hamsung.hamsung_project.entity.Study;
import hamsung.hamsung_project.entity.StudyMember;
Expand All @@ -15,6 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -94,4 +96,18 @@ public boolean approveMember(Long study_id,Long users_id) {
}
}

//스터디 멤버 조회
public List<MemberSummaryDto> findAllMembers(Long study_id){
Study study = studyRepository.findById(study_id)
.orElseThrow(() -> new IllegalArgumentException("해당 스터디를 찾을 수 없어요."));
List<StudyMember> StudyMemberList = studyMemberRepository.findByStudy_id(study_id);
List<MemberSummaryDto> summaryMemberList=new ArrayList<>();
for (StudyMember studyMember : StudyMemberList) {
if (studyMember.getApproval() ==true) {
summaryMemberList.add(MemberSummaryDto.createSummaryDto(studyMember));
}
}
return summaryMemberList;
}

}

0 comments on commit eaba24b

Please sign in to comment.