Skip to content

Commit

Permalink
[Feat] 전체회원 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed Nov 18, 2024
1 parent acdbc80 commit 6ea958a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
<p></p>
<a href="https://github.com/squidjiny">
<img src="https://avatars.githubusercontent.com/u/92552047?v=4" width="60">
</a>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/members")
Expand Down Expand Up @@ -43,6 +45,11 @@ public ResponseEntity<MemberRes> getMember(@PathVariable Long memberId) {
return ResponseEntity.ok(memberService.getMember(memberId));
}

@GetMapping("")
public ResponseEntity<List<MemberRes>> getMembers() {
return ResponseEntity.ok(memberService.getMembers());
}

@DeleteMapping("/{memberId}")
@Operation(description = "회원 탈퇴")
@ApiResponse(responseCode = "200", description = "탈퇴 성공")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/basic/study/dto/MemberRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public class MemberRes {
private Long memberId;
@Schema(description = "회원의 email", example = "asdf")
private String email;
@Builder.Default
@Schema(description = "회원의 password (전체회원 조회시 사용)", example = "asdf")
private String password="private";
}
11 changes: 11 additions & 0 deletions src/main/java/com/basic/study/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.NoSuchElementException;

@Service
Expand Down Expand Up @@ -51,6 +52,16 @@ public MemberRes getMember(Long memberId) {
.build();
}

public List<MemberRes> getMembers() {
return memberRepository.findAll().stream().map(
member -> MemberRes.builder()
.memberId(member.getId())
.email(member.getEmail())
.password(member.getPassword())
.build()
).toList();
}

public boolean deleteMember(Long memberId) {
if (!memberRepository.existsById(memberId)) throw new NullPointerException();
memberRepository.deleteById(memberId);
Expand Down

0 comments on commit 6ea958a

Please sign in to comment.