Skip to content

Commit

Permalink
Merge pull request #5 from goormthon-Univ/feat/pocket
Browse files Browse the repository at this point in the history
Feat: ๋ช…ํ•จ ๋ฆฌ์ŠคํŠธ api ์ƒ์„ฑ
  • Loading branch information
eun0901 authored Mar 16, 2024
2 parents aa682ba + f8f2da1 commit 4155317
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public ResponseEntity<?> getMyCard(Principal principal){
public ResponseEntity<?> saveCard(@PathVariable(name="userId") Long userId, Principal principal) {
return cardService.saveCard(userId, principal);
}

@PreAuthorize("isAuthenticated()")
@GetMapping("/card/list")
public ResponseEntity<?> getAllCards(Principal principal) {
return cardService.getAllCard(principal);
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/goormuniv/ponnect/service/CardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,30 @@ public ResponseEntity<?> saveCard(Long userId, Principal principal) {
.build());
}
}

public ResponseEntity<?> getAllCard (Principal principal) {
try {
Member member = memberRepository.findByEmail(principal.getName()).orElseThrow();

List<Follow> follows = followRepository.findAllByFollowing(member);

List<CardListDto> cardListDtos = follows.stream()
.map(follow -> {
Member followed = follow.getFollowed();

return CardListDto.builder()
.userId(followed.getId())
.name(followed.getName())
.phone(followed.getPhone())
.email(followed.getEmail())
.build();
})
.toList();
return ResponseEntity.ok(cardListDtos);
}catch(Exception e){
log.info("ํšŒ์›์ด ์—†์Œ");
return new ResponseEntity<>( ErrMsgDto.builder()
.message("ํšŒ์›์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.").statusCode(HttpStatus.BAD_REQUEST.value()).build(),HttpStatus.BAD_REQUEST);
}
}
}

0 comments on commit 4155317

Please sign in to comment.