-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4 주차 PR #6
Open
nette74
wants to merge
17
commits into
master
Choose a base branch
from
WEEK_4.00
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
4 주차 PR #6
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5553639
FEAT : REST CONTROLLER 와 그 응답을 위한 JSON DTO 생성
nette74 c6cc94a
FEAT : LocalDateTime 을 알맞게 변환하기 위한 유틸리티 추가
nette74 9a7aa52
FEAT : ProductDto 작성
nette74 73ed419
FEAT : MyBookDto 작성
nette74 a6d277a
FEAT : PostDto 추가
nette74 a6eb94c
FEAT : MyBookDetailDto 추가
nette74 10bf8a8
FEAT : PostKeyWord 대소문자 오류? 해결
nette74 3c359d8
FEAT : @NotNull 추가
nette74 1d5e9f5
FEAT : 패키지 이름 변경
nette74 5030c18
FEAT : MemberDto 작성
nette74 9827fd3
FEAT : JWT 토큰 로그인 기반
nette74 d911012
FEAT : 내 책 목록조회 컨트롤러
nette74 300efaa
FIX : return 중복 오타 수정
nette74 a8829f2
FEAT : BookDetail 메소드
nette74 916fa11
FIX : 메소드명 첫 대문자 제거
nette74 c5c281e
FEAT : 상세 페이지 구현중 보류
nette74 fc539b7
FEAT : 개발중 이슈
nette74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
4Week_Mission/src/main/java/com/ll/exam/final__2022_10_08/app/member/dto/MemberDto.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,40 @@ | ||
package com.ll.exam.final__2022_10_08.app.member.dto; | ||
|
||
import com.ll.exam.final__2022_10_08.app.member.entity.Member; | ||
import com.ll.exam.final__2022_10_08.util.DateTimeParser; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
@RequiredArgsConstructor | ||
public class MemberDto { | ||
Long id; | ||
List<Integer> createDate; | ||
List<Integer> modifyDate; | ||
String username; | ||
String email; | ||
boolean emailVerified = false; | ||
String nickname = ""; | ||
|
||
public static MemberDto fromEntity(Member member){ | ||
List<Integer> createDateList = DateTimeParser.dateTimeToIntegerList(member.getCreateDate()); | ||
List<Integer> modifyDateList = DateTimeParser.dateTimeToIntegerList(member.getModifyDate()); | ||
|
||
return MemberDto.builder() | ||
.id(member.getId()) | ||
.createDate(createDateList) | ||
.modifyDate(modifyDateList) | ||
.username(member.getUsername()) | ||
.email(member.getEmail()) | ||
.emailVerified(member.isEmailVerified()) | ||
.nickname(member.getNickname() == null ? "" : member.getNickname()) | ||
.build(); | ||
} | ||
|
||
} |
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
95 changes: 95 additions & 0 deletions
95
...in/java/com/ll/exam/final__2022_10_08/app/member/restcontroller/MemberRestController.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,95 @@ | ||
package com.ll.exam.final__2022_10_08.app.member.restcontroller; | ||
|
||
import com.ll.exam.final__2022_10_08.app.base.dto.RsData; | ||
import com.ll.exam.final__2022_10_08.app.base.rq.Rq; | ||
import com.ll.exam.final__2022_10_08.app.member.dto.MemberDto; | ||
import com.ll.exam.final__2022_10_08.app.member.entity.Member; | ||
import com.ll.exam.final__2022_10_08.app.member.service.MemberService; | ||
import com.ll.exam.final__2022_10_08.app.security.dto.MemberContext; | ||
import com.ll.exam.final__2022_10_08.util.Ut; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class MemberRestController { | ||
private final MemberService memberService; | ||
private final PasswordEncoder passwordEncoder; | ||
private final Rq rq; | ||
|
||
//리퀘스트에 토큰 담는 법? | ||
//세션 방식에서 완전한 변경 필요함 | ||
//@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/api/v1/member/me") | ||
public ResponseEntity<RsData> showProfile(){ | ||
|
||
Long id = rq.getMember() != null ? rq.getMember().getId() : 1; | ||
Member member = memberService.findById(id).orElseThrow(()->{throw new RuntimeException("해당 ID의 유저가 없습니다.");}); | ||
MemberDto memberDto = MemberDto.fromEntity(member); | ||
|
||
return Ut.spring.responseEntityOf( | ||
RsData.of( | ||
"S-1", | ||
"회원 조회 성공", | ||
Ut.mapOf( | ||
"member", memberDto | ||
) | ||
) | ||
); | ||
} | ||
|
||
|
||
// https://www.youtube.com/watch?v=EMsXhobcUDc | ||
@PreAuthorize("isAnonymous()") | ||
@PostMapping("/api/v1/member/login") | ||
public ResponseEntity<RsData> login(@RequestBody LoginDto loginDto) { | ||
if (loginDto.isNotValid()) { | ||
return Ut.spring.responseEntityOf(RsData.of("F-1", "로그인 정보가 올바르지 않습니다.")); | ||
} | ||
|
||
Member member = memberService.findByUsername(loginDto.getUsername()).orElse(null); | ||
|
||
if (member == null) { | ||
return Ut.spring.responseEntityOf(RsData.of("F-2", "일치하는 회원이 존재하지 않습니다.")); | ||
} | ||
|
||
if (passwordEncoder.matches(loginDto.getPassword(), member.getPassword()) == false) { | ||
return Ut.spring.responseEntityOf(RsData.of("F-3", "비밀번호가 일치하지 않습니다.")); | ||
} | ||
|
||
String accessToken = "JWT_Access_Token"; | ||
|
||
return Ut.spring.responseEntityOf( | ||
RsData.of( | ||
"S-1", | ||
"로그인 성공, Access Token 을 발급합니다.", | ||
Ut.mapOf( | ||
"accessToken", accessToken | ||
) | ||
), | ||
Ut.spring.httpHeadersOf("Authentication", accessToken) | ||
); | ||
} | ||
@Data | ||
public static class LoginDto { | ||
private String username; | ||
private String password; | ||
|
||
public boolean isNotValid() { | ||
return username == null || password == null || username.trim().length() == 0 || password.trim().length() == 0; | ||
} | ||
} | ||
|
||
|
||
} |
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
62 changes: 62 additions & 0 deletions
62
...k_Mission/src/main/java/com/ll/exam/final__2022_10_08/app/myBook/dto/MyBookDetailDto.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,62 @@ | ||
package com.ll.exam.final__2022_10_08.app.myBook.dto; | ||
|
||
import com.ll.exam.final__2022_10_08.app.member.entity.Member; | ||
import com.ll.exam.final__2022_10_08.app.myBook.entity.MyBook; | ||
import com.ll.exam.final__2022_10_08.app.post.dto.PostDto; | ||
import com.ll.exam.final__2022_10_08.app.product.dto.ProductDto; | ||
import com.ll.exam.final__2022_10_08.app.product.entity.Product; | ||
import com.ll.exam.final__2022_10_08.util.DateTimeParser; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
@RequiredArgsConstructor | ||
public class MyBookDetailDto{ //상속해도 될 듯..? | ||
Long id; | ||
List<Integer> createDate; | ||
List<Integer> modifyDate; | ||
Long ownerId; | ||
ProductDto product; | ||
Long authorId; | ||
String authorName; | ||
String subject; | ||
List<PostDto> bookChapters; //밖에서 만들어서 넣어줘야 함. | ||
|
||
public static MyBookDetailDto fromEntity(@NotNull MyBook myBook){ | ||
|
||
Product productEntity = myBook.getProduct(); | ||
Member author = productEntity.getAuthor(); | ||
Member owner = myBook.getOwner(); | ||
List<Integer> createDateList = DateTimeParser.dateTimeToIntegerList(myBook.getCreateDate()); | ||
List<Integer> modifyDateList = DateTimeParser.dateTimeToIntegerList(myBook.getModifyDate()); | ||
|
||
return MyBookDetailDto.builder() | ||
.id(myBook.getId()) | ||
.createDate(createDateList) | ||
.modifyDate(modifyDateList) | ||
.ownerId(owner.getId()) | ||
.product(ProductDto.fromEntity(productEntity)) | ||
.authorId(author.getId()) | ||
.authorName(author.getNickname()) | ||
.subject(productEntity.getSubject()) | ||
.build(); | ||
} | ||
public MyBookDetailDto(@NotNull MyBookDto myBookDto) | ||
{ | ||
id = myBookDto.getId(); | ||
createDate = myBookDto.getCreateDate(); | ||
modifyDate = myBookDto.getModifyDate(); | ||
ownerId = myBookDto.getOwnerId(); | ||
product = myBookDto.getProduct(); | ||
authorId = myBookDto.getAuthorId(); | ||
authorName = myBookDto.getAuthorName(); | ||
subject = myBookDto.getSubject(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
4Week_Mission/src/main/java/com/ll/exam/final__2022_10_08/app/myBook/dto/MyBookDto.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,50 @@ | ||
package com.ll.exam.final__2022_10_08.app.myBook.dto; | ||
|
||
import com.ll.exam.final__2022_10_08.app.member.entity.Member; | ||
import com.ll.exam.final__2022_10_08.app.myBook.entity.MyBook; | ||
import com.ll.exam.final__2022_10_08.app.product.dto.ProductDto; | ||
import com.ll.exam.final__2022_10_08.app.product.entity.Product; | ||
import com.ll.exam.final__2022_10_08.util.DateTimeParser; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
|
||
@RequiredArgsConstructor | ||
public class MyBookDto { | ||
Long id; | ||
List<Integer> createDate; | ||
List<Integer> modifyDate; | ||
Long ownerId; | ||
ProductDto product; | ||
Long authorId; | ||
String authorName; | ||
String subject; | ||
|
||
public static MyBookDto fromEntity(@NotNull MyBook myBook){ | ||
|
||
Product productEntity = myBook.getProduct(); | ||
Member author = productEntity.getAuthor(); | ||
Member owner = myBook.getOwner(); | ||
List<Integer> createDateList = DateTimeParser.dateTimeToIntegerList(myBook.getCreateDate()); | ||
List<Integer> modifyDateList = DateTimeParser.dateTimeToIntegerList(myBook.getModifyDate()); | ||
|
||
return MyBookDto.builder() | ||
.id(myBook.getId()) | ||
.createDate(createDateList) | ||
.modifyDate(modifyDateList) | ||
.ownerId(owner.getId()) | ||
.product(ProductDto.fromEntity(productEntity)) | ||
.authorId(author.getId()) | ||
.authorName(author.getNickname()) | ||
.subject(productEntity.getSubject()) | ||
.build(); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...in/java/com/ll/exam/final__2022_10_08/app/myBook/restcontroller/MyBookRestController.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,86 @@ | ||
package com.ll.exam.final__2022_10_08.app.myBook.restcontroller; | ||
|
||
import com.ll.exam.final__2022_10_08.app.base.dto.RsData; | ||
import com.ll.exam.final__2022_10_08.app.base.rq.Rq; | ||
import com.ll.exam.final__2022_10_08.app.member.entity.Member; | ||
import com.ll.exam.final__2022_10_08.app.member.service.MemberService; | ||
import com.ll.exam.final__2022_10_08.app.myBook.dto.MyBookDetailDto; | ||
import com.ll.exam.final__2022_10_08.app.myBook.dto.MyBookDto; | ||
import com.ll.exam.final__2022_10_08.app.myBook.entity.MyBook; | ||
import com.ll.exam.final__2022_10_08.app.myBook.service.MyBookService; | ||
import com.ll.exam.final__2022_10_08.app.post.entity.Post; | ||
import com.ll.exam.final__2022_10_08.app.postTag.entity.PostTag; | ||
import com.ll.exam.final__2022_10_08.app.postTag.service.PostTagService; | ||
import com.ll.exam.final__2022_10_08.app.postkeyword.entity.PostKeyword; | ||
import com.ll.exam.final__2022_10_08.app.product.dto.ProductDto; | ||
import com.ll.exam.final__2022_10_08.app.product.entity.Product; | ||
import com.ll.exam.final__2022_10_08.app.product.service.ProductService; | ||
import com.ll.exam.final__2022_10_08.app.productTag.entity.ProductTag; | ||
import com.ll.exam.final__2022_10_08.util.Ut; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
//@RequestMapping("/api/v1/myBooks") | ||
public class MyBookRestController { | ||
|
||
private final MemberService memberService; | ||
private final Rq rq; | ||
private final MyBookService myBookService; | ||
private final ProductService productService; | ||
private final PostTagService postTagService; | ||
|
||
//@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/api/v1/myBooks") | ||
public ResponseEntity<RsData> booksList(){ | ||
|
||
Long id = rq.getMember() != null ? rq.getMember().getId() : 1; //임시, 로그인 정보 못 가져올시 1로 | ||
List<MyBookDto> myBooks = myBookService.findAllByOwnerId(id); | ||
|
||
return Ut.spring.responseEntityOf( | ||
RsData.of( | ||
"S-1", | ||
"내 책 리스트 조회 성공", | ||
Ut.mapOf( | ||
"myBooks", myBooks | ||
) | ||
) | ||
); | ||
} | ||
|
||
//@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/api/v1/myBooks/{id}") | ||
public ResponseEntity<RsData> bookDetail(long id){ | ||
|
||
|
||
MyBook myBook = myBookService.findById(id); | ||
MyBookDetailDto myBookDetailDto = MyBookDetailDto.fromEntity(myBook); | ||
|
||
|
||
Product product = myBook.getProduct(); | ||
//Long postKeywordId = product.getPostKeyword().getId(); | ||
//PostTag postTag = postTagService. | ||
|
||
|
||
//PostTag postTag = postTagService. | ||
//List<Post> posts = myBook.getProduct().getPostKeyword().getContent() | ||
//List<PostDto> bookChapters = | ||
//myBookDetailDto.setBookChapters(bookChapters); | ||
|
||
return Ut.spring.responseEntityOf( | ||
RsData.of( | ||
"S-1", | ||
"내 책 조회 성공", | ||
Ut.mapOf( | ||
"myBook", myBookDetailDto | ||
) | ||
) | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dto를 활용해서 요구사항에 맞추는게 더 좋겠네요!!