-
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
[Seminar3] 필수 과제 구현 #10
Open
jjuny-won
wants to merge
16
commits into
main
Choose a base branch
from
seminar3_assignment
base: main
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a3d753c
feat(entity) Entity 추가 및 수정
eea0f27
feat(user): 로그인,회원가입 구현
077e702
feat(diary):다이어리 생성 수정 완료
28dde74
feat(diary) : 다이어리 개별 조회 수정
fa17dda
feat(diaty) : 다이어리 수정 구현
9c3e900
feat(diaries) : 다이어리 목록 조회 구현
d31db13
fix:파일이름변경
ab2f986
gitignore 에 yml추가
be88a49
fix:Transactional 추가
5a934b9
feat(diary) : 일기 상세 조회 수정
4899d64
yml파일 gitignore에 추가
88166c2
feat(diaries) : diary 목록 조회 수정
55a7631
fix(error): 예외 처리 수정
c8507cd
lombok 제거
8ac8e14
fix(service) : @Transactional 수정
3d351f8
fix(enum) : enum 수정
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
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 |
---|---|---|
|
@@ -15,7 +15,6 @@ build/ | |
.idea/workspace.xml | ||
.idea/libraries/ | ||
.idea/** | ||
.idea/vcs.xml | ||
.idea | ||
.idea/ | ||
*.iws | ||
|
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 was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
src/main/java/org/sopt/Diary/controller/DiariesController.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,41 @@ | ||
package org.sopt.Diary.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import org.sopt.Diary.dto.res.DiaryListRes; | ||
import org.sopt.Diary.entity.Category; | ||
import org.sopt.Diary.entity.SortType; | ||
import org.sopt.Diary.service.DiariesService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RequestMapping("/diaries") | ||
@RestController | ||
public class DiariesController { | ||
|
||
private final DiariesService diariesService; | ||
|
||
public DiariesController(DiariesService diariesService) { | ||
this.diariesService = diariesService; | ||
} | ||
|
||
@GetMapping() | ||
public ResponseEntity<DiaryListRes> getDiaries( | ||
@RequestHeader(name="userId" , required = false) Long userId, | ||
@RequestParam(name = "category" , required = false, defaultValue = "ALL") final Category category, | ||
@RequestParam(name = "sort",required = false, defaultValue = "LATEST") final SortType sortType) { | ||
|
||
DiaryListRes diaryListRes = diariesService.getDiariesResponse( category,sortType, false, userId); | ||
return ResponseEntity.ok(diaryListRes); | ||
} | ||
|
||
@GetMapping("/my") | ||
public ResponseEntity<DiaryListRes> getMyDiaries( | ||
@Valid @RequestHeader("userId") long userId, | ||
@Valid @RequestParam(name = "category",required = false, defaultValue = "ALL") final Category category, | ||
@RequestParam(name = "sort",required = false, defaultValue = "LATEST")final SortType sortType) { | ||
|
||
DiaryListRes diaryListRes = diariesService.getDiariesResponse(category, sortType,true,userId); | ||
return ResponseEntity.ok(diaryListRes); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/org/sopt/Diary/controller/DiaryController.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,88 @@ | ||
package org.sopt.Diary.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import org.sopt.Diary.dto.req.DiaryUpdateReq; | ||
import org.sopt.Diary.dto.req.DiaryReq; | ||
import org.sopt.Diary.dto.res.DiaryRes; | ||
import org.sopt.Diary.service.DiaryService; | ||
import org.sopt.Diary.service.UserService; | ||
import org.sopt.Diary.validator.DiaryValidator; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequestMapping("/diary") | ||
@RestController | ||
public class DiaryController { | ||
|
||
private final DiaryService diaryService; | ||
private final UserService userService; | ||
|
||
public DiaryController(DiaryService diaryService,UserService userService) { | ||
this.diaryService = diaryService; | ||
this.userService=userService; | ||
} | ||
|
||
/** | ||
* 일기 작성하기 | ||
* @param userId 유저 Id(Header) | ||
* @param diaryRequest title,content,category,isPrivate | ||
* @return 200 | ||
*/ | ||
@PostMapping() | ||
ResponseEntity<String> postDiary(@RequestHeader("userId") long userId, @Valid @RequestBody final DiaryReq diaryRequest) { | ||
|
||
//UserId, 내용 글자수 검증 | ||
userService.findByUserId(userId); | ||
DiaryValidator.checkContent(diaryRequest.content()); | ||
DiaryValidator.checkTitle(diaryRequest.title()); | ||
|
||
diaryService.createDiary(userId, diaryRequest); | ||
return ResponseEntity.ok("일기가 생성되었습니다."); | ||
} | ||
|
||
/** | ||
* 일기 상세 조회 | ||
* @param diaryId 다이어리 아이디 | ||
* @return 200 | ||
*/ | ||
@GetMapping("/{diaryId}") | ||
ResponseEntity<DiaryRes> getDiary(@RequestHeader(name="userId",required = false) Long userId, @PathVariable("diaryId") final long diaryId) { | ||
DiaryRes diaryRes = diaryService.getDiary(userId, diaryId); | ||
|
||
return ResponseEntity.ok(diaryRes); | ||
} | ||
|
||
/** | ||
* 일기 수정 | ||
* @param userId 유저 아이디 | ||
* @param diaryId 다이어리 아이디 | ||
* @param diaryRequest content,category | ||
* @return 200 | ||
*/ | ||
@PatchMapping("/{diaryId}") | ||
ResponseEntity<String> updateDiary( @RequestHeader("userId") long userId, | ||
@PathVariable("diaryId") final long diaryId, | ||
@Valid @RequestBody DiaryUpdateReq diaryRequest){ | ||
|
||
//UserId, 내용 글자수 검증 | ||
userService.findByUserId(userId); | ||
DiaryValidator.checkContent(diaryRequest.content()); | ||
|
||
diaryService.patchDiary(userId, diaryId,diaryRequest.content(),diaryRequest.category()); | ||
return ResponseEntity.ok("일기가 수정되었습니다."); | ||
} | ||
|
||
/** | ||
* 일기 삭제하기 | ||
* @param userId 유저 아이디 | ||
* @param diaryId 다이어리 아이디 | ||
* @return 200 | ||
*/ | ||
@DeleteMapping("/{diaryId}") | ||
ResponseEntity<String> deleteDiary(@RequestHeader("userId") long userId, | ||
@PathVariable("diaryId") final long diaryId){ | ||
userService.findByUserId(userId); | ||
diaryService.deleteDiary(userId,diaryId); | ||
return ResponseEntity.ok("일기가 삭제되었습니다."); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/sopt/Diary/controller/UserController.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,45 @@ | ||
package org.sopt.Diary.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import org.sopt.Diary.dto.req.SignInReq; | ||
import org.sopt.Diary.dto.req.SignUpReq; | ||
import org.sopt.Diary.dto.res.UserRes; | ||
import org.sopt.Diary.service.UserService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
public UserController(final UserService userService){this.userService=userService;} | ||
|
||
/** | ||
* 회원가입 | ||
* @param signUpRequest Id, Pwd, Nickname | ||
*/ | ||
@PostMapping("/signup") | ||
private void signUp(@Valid @RequestBody SignUpReq signUpRequest){ | ||
// 제약사항 따로 없음 | ||
//@Valid 를 통해 RequestBody @NotNull 체크해줌 | ||
userService.join(signUpRequest); | ||
} | ||
|
||
/** | ||
* 로그인 | ||
* @param signInReq Id, Pwd | ||
* @return 200 | ||
*/ | ||
@PostMapping("/signin") | ||
private UserRes signIn(@Valid @RequestBody SignInReq signInReq){ | ||
Long userId= userService.login(signInReq); | ||
return new UserRes(userId); | ||
|
||
} | ||
|
||
|
||
} |
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,12 @@ | ||
package org.sopt.Diary.dto.req; | ||
|
||
|
||
import jakarta.validation.constraints.NotNull; | ||
import org.sopt.Diary.entity.Category; | ||
|
||
|
||
public record DiaryReq(@NotNull String title, | ||
@NotNull String content, | ||
@NotNull Category category, | ||
boolean isPrivate){ | ||
} |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
package org.sopt.Diary.dto.req; | ||
|
||
|
||
import jakarta.validation.constraints.NotNull; | ||
import org.sopt.Diary.entity.Category; | ||
|
||
public record DiaryUpdateReq(@NotNull String content , @NotNull Category category) { | ||
} |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
package org.sopt.Diary.dto.req; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record SignInReq (@NotNull String loginId, @NotNull String password){ | ||
} |
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,9 @@ | ||
package org.sopt.Diary.dto.req; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
//입력값의 Null 검증을 위한 @Valid, @NotNull | ||
public record SignUpReq ( @NotNull String loginId, @NotNull String password, @NotNull String nickname ) | ||
{ | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...g/sopt/Diary/dto/res/DiariesResponse.java → ...va/org/sopt/Diary/dto/res/DiariesRes.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
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,20 @@ | ||
package org.sopt.Diary.dto.res; | ||
|
||
|
||
import java.util.List; | ||
|
||
public class DiaryListRes { | ||
private List<DiariesRes> diaries; | ||
|
||
public DiaryListRes(List<DiariesRes> diaries) { | ||
this.diaries = diaries; | ||
} | ||
|
||
public List<DiariesRes> getDiaries() { | ||
return diaries; | ||
} | ||
|
||
public void setDiaries(List<DiariesRes> diaries) { | ||
this.diaries = diaries; | ||
} | ||
} |
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.
혹시 존재하지 않는 유저 아이디가 들어왔을 때는 어떻게 처리하나용?