forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Be feature/#32 member
- Loading branch information
Showing
27 changed files
with
439 additions
and
41 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
backend/src/main/java/com/project/capstone/auth/controller/dto/SignupRequest.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,11 @@ | ||
package com.project.capstone.auth.controller.dto; | ||
|
||
import com.project.capstone.member.domain.Gender; | ||
|
||
public record SignupRequest( | ||
String email, | ||
String name, | ||
int age, | ||
String gender | ||
Gender gender | ||
) { | ||
} |
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
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
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
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
37 changes: 31 additions & 6 deletions
37
backend/src/main/java/com/project/capstone/member/controller/MemberController.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,17 +1,42 @@ | ||
package com.project.capstone.member.controller; | ||
|
||
import com.project.capstone.auth.domain.PrincipalDetails; | ||
import com.project.capstone.member.controller.dto.AddMyBookRequest; | ||
import com.project.capstone.member.controller.dto.MemberResponse; | ||
import com.project.capstone.member.controller.dto.MyBookResponse; | ||
import com.project.capstone.member.service.MemberService; | ||
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; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/member") | ||
public class MemberController { | ||
@GetMapping("/test") | ||
public ResponseEntity<?> test() { | ||
return ResponseEntity.ok("ok"); | ||
|
||
private final MemberService memberService; | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<MemberResponse> getMember(@PathVariable UUID id) { | ||
MemberResponse memberResponse = memberService.getMember(id); | ||
return ResponseEntity.ok().body(memberResponse); | ||
} | ||
|
||
// 나만의 서재 조회 | ||
@GetMapping("/my-book") | ||
public ResponseEntity<List<MyBookResponse>> getMyBook(@AuthenticationPrincipal PrincipalDetails details) { | ||
List<MyBookResponse> myBooks = memberService.getMyBooks(details.getUserId()); | ||
return ResponseEntity.ok().body(myBooks); | ||
} | ||
|
||
// 나만의 서재 추가 | ||
@PostMapping("/my-book/add") | ||
public ResponseEntity<?> addMyBook(@AuthenticationPrincipal PrincipalDetails details, @RequestBody AddMyBookRequest request) { | ||
memberService.addMyBook(details.getUserId(), request); | ||
return ResponseEntity.ok().body("추가 완료"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/project/capstone/member/controller/dto/AddMyBookRequest.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,15 @@ | ||
package com.project.capstone.member.controller.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record AddMyBookRequest ( | ||
String isbn, | ||
String title, | ||
String category1d, | ||
String category2d, | ||
String category3d, | ||
String author, | ||
String publisher, | ||
String publishDate | ||
) { | ||
} |
81 changes: 81 additions & 0 deletions
81
backend/src/main/java/com/project/capstone/member/controller/dto/MemberResponse.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,81 @@ | ||
package com.project.capstone.member.controller.dto; | ||
|
||
import com.project.capstone.club.domain.Club; | ||
import com.project.capstone.comment.controller.dto.CommentResponse; | ||
import com.project.capstone.comment.domain.Comment; | ||
import com.project.capstone.content.controller.dto.ContentResponse; | ||
import com.project.capstone.content.domain.Content; | ||
import com.project.capstone.member.domain.Gender; | ||
import com.project.capstone.member.domain.Member; | ||
import com.project.capstone.memberclub.domain.MemberClub; | ||
import com.project.capstone.mybook.domain.MyBook; | ||
import com.project.capstone.post.controller.dto.PostResponse; | ||
import com.project.capstone.post.controller.dto.SimplePostResponse; | ||
import com.project.capstone.post.domain.Post; | ||
import com.project.capstone.quiz.controller.dto.QuizResponse; | ||
import com.project.capstone.quiz.domain.Quiz; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record MemberResponse ( | ||
UUID id, | ||
String email, | ||
String name, | ||
int age, | ||
Gender gender, | ||
LocalDateTime createdAt, | ||
List<MemberClub> clubsList, | ||
List<SimplePostResponse> postList, | ||
List<CommentResponse> commentList, | ||
List<ContentResponse> contentList, | ||
List<QuizResponse> quizList, | ||
List<MyBookResponse> myBookList | ||
) { | ||
public MemberResponse(Member member) { | ||
this(member.getId(), member.getEmail(), member.getName(), member.getAge(), member.getGender(), member.getCreatedAt(), | ||
member.getClubs(), createSimplePostResponseList(member.getPosts()), createCommentResponseList(member.getComments()), | ||
createContentResponseList(member.getContents()), createQuizResponseList(member.getQuizzes()), createMyBookResponseList(member.getMyBooks())); | ||
} | ||
|
||
private static List<SimplePostResponse> createSimplePostResponseList(List<Post> postList) { | ||
List<SimplePostResponse> simplePostResponses = new ArrayList<>(); | ||
for (Post post: postList) { | ||
simplePostResponses.add(new SimplePostResponse(post)); | ||
} | ||
return simplePostResponses; | ||
} | ||
|
||
private static List<CommentResponse> createCommentResponseList(List<Comment> commentList) { | ||
List<CommentResponse> commentResponseList = new ArrayList<>(); | ||
for (Comment comment: commentList) { | ||
commentResponseList.add(new CommentResponse(comment)); | ||
} | ||
return commentResponseList; | ||
} | ||
|
||
private static List<ContentResponse> createContentResponseList(List<Content> contentList) { | ||
List<ContentResponse> contentResponseList = new ArrayList<>(); | ||
for (Content content : contentList) { | ||
contentResponseList.add(new ContentResponse(content)); | ||
} | ||
return contentResponseList; | ||
} | ||
private static List<QuizResponse> createQuizResponseList(List<Quiz> quizList) { | ||
List<QuizResponse> quizResponseList = new ArrayList<>(); | ||
for (Quiz quiz : quizList) { | ||
quizResponseList.add(new QuizResponse(quiz)); | ||
} | ||
return quizResponseList; | ||
} | ||
|
||
private static List<MyBookResponse> createMyBookResponseList(List<MyBook> myBookList) { | ||
List<MyBookResponse> myBookResponseList = new ArrayList<>(); | ||
for (MyBook myBook : myBookList) { | ||
myBookResponseList.add(new MyBookResponse(myBook)); | ||
} | ||
return myBookResponseList; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/project/capstone/member/controller/dto/MyBookResponse.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,15 @@ | ||
package com.project.capstone.member.controller.dto; | ||
|
||
import com.project.capstone.mybook.domain.MyBook; | ||
|
||
public record MyBookResponse( | ||
Long id, | ||
String isbn, | ||
String title, | ||
String author, | ||
String publisher | ||
) { | ||
public MyBookResponse(MyBook myBook) { | ||
this(myBook.getId(), myBook.getBook().getIsbn(), myBook.getBook().getTitle(), myBook.getBook().getAuthor(), myBook.getBook().getPublisher()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/project/capstone/member/domain/Gender.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,25 @@ | ||
package com.project.capstone.member.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.project.capstone.quiz.domain.QuizType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum Gender { | ||
MALE("남자"), | ||
FEMALE("여자") | ||
; | ||
private final String type; | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING) | ||
public static Gender from(String type) { | ||
for (Gender gender: Gender.values()) { | ||
if (gender.getType().equals(type)) { | ||
return gender; | ||
} | ||
} | ||
throw new RuntimeException("잘못된 성별 입니다."); | ||
} | ||
} |
Oops, something went wrong.