-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/#26 게시판기능구현 #49
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
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "feature/#26-\uAC8C\uC2DC\uD310\uAE30\uB2A5\uAD6C\uD604"
Changes from all commits
e91803c
458542e
95cf417
bb014ab
ae5fc0d
22806c6
41160b4
e65aa8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.battles.battles.exception.exception; | ||
|
|
||
| public class CPostNotFoundException extends RuntimeException { | ||
|
|
||
| public CPostNotFoundException(String msg, Throwable t) { | ||
| super(msg, t); | ||
| } | ||
|
|
||
| public CPostNotFoundException(String msg) { | ||
| super(msg); | ||
| } | ||
|
|
||
| public CPostNotFoundException() { | ||
| super(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.battles.battles.exception.exception; | ||
|
|
||
| public class CSchoolNotFoundException extends RuntimeException{ | ||
|
|
||
| public CSchoolNotFoundException(String msg, Throwable t) { | ||
| super(msg, t); | ||
| } | ||
|
|
||
| public CSchoolNotFoundException(String msg) { | ||
| super(msg); | ||
| } | ||
|
|
||
| public CSchoolNotFoundException() { | ||
| super(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package org.battles.battles.post.Dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.battles.battles.battle.Battle; | ||
| import org.battles.battles.battle.category.Category; | ||
| import org.battles.battles.common.Status; | ||
| import org.battles.battles.post.Post; | ||
| import org.battles.battles.post.PostType; | ||
| import org.battles.battles.school.School; | ||
| import org.battles.battles.user.User; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Optional; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class PostsResponseDto { | ||
| private Long postId; | ||
|
|
||
| private Long userId; | ||
|
|
||
| private String nickName; | ||
|
|
||
| private Long schoolId; | ||
|
|
||
| private String schoolName; | ||
|
|
||
| private String title; | ||
|
|
||
| private String content; | ||
|
|
||
| private PostType postType; | ||
|
|
||
| private Status status; | ||
|
|
||
| private LocalDateTime createdAt; | ||
|
|
||
| private LocalDateTime modifiedAt; | ||
|
|
||
| public PostsResponseDto(Post post) { | ||
| this.postId = post.getPostId(); | ||
| this.userId = post.getUser().getUserId(); | ||
| this.nickName = post.getUser().getNickName(); | ||
| this.schoolId = post.getUser().getSchool().getSchoolId(); | ||
| this.schoolName = post.getUser().getSchool().getSchoolName(); | ||
| this.title = post.getTitle(); | ||
| this.content = post.getContent(); | ||
| this.postType = post.getPostType(); | ||
| this.status = post.getStatus(); | ||
| this.createdAt = post.getCreatedAt(); | ||
| this.modifiedAt = post.getModifiedAt(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.battles.battles.post.Dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.battles.battles.common.Status; | ||
| import org.battles.battles.post.Post; | ||
| import org.battles.battles.post.PostType; | ||
| import org.battles.battles.school.School; | ||
| import org.battles.battles.user.User; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class PostsSaveRequestDto { | ||
| private String title; | ||
| private String content; | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| import lombok.NoArgsConstructor; | ||
| import org.battles.battles.common.Status; | ||
| import org.battles.battles.common.TimeStamped; | ||
| import org.battles.battles.school.School; | ||
| import org.battles.battles.user.User; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
|
|
@@ -15,20 +17,21 @@ | |
| @AllArgsConstructor | ||
| @Entity | ||
| @Table(name = "Post_Table") | ||
|
|
||
| public class Post extends TimeStamped { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long postId; | ||
|
|
||
| // fix me = fk mapping 필요 | ||
| @Column(nullable = false) | ||
| private Long userId; | ||
| // fix me = fk mapping 필요 | ||
| @ManyToOne | ||
| @JoinColumn(name = "userId", nullable = true) | ||
| private User user; | ||
|
|
||
| // fix me = fk mapping 필요 | ||
| @Column(nullable = true) | ||
| private Long schoolId; | ||
| @ManyToOne | ||
| @JoinColumn(name = "schoolId", nullable = true) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매핑 잘 하셨는데 지금 언뜻 서치해보니까 fk null이면 에러가 난다는.... 설계를 다시 해봐야겠네요 ㅠㅠㅠ
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fk null 허용되지 않나요? JPA라서 그런가요??
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jpa라서 그런건 아니고.. 아 fk가 pk 동시일때 null허용은 안되는구나 원래 db상으로는... 음 고민이되네요 null이 좋은 방식은 아닌 것 같긴 해요 ㅠㅠ 고민고민
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 더 알아보겠습니다. @yejipractice
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
정도 고민이 있는 것 같습니다. 개발하고 있는데 schoolID가 NULL이 되면 코드가 많아지기도 했습니다..
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| private School school; | ||
|
|
||
| @Column(nullable = false) | ||
| private String title; | ||
|
|
@@ -45,9 +48,9 @@ public class Post extends TimeStamped { | |
| private Status status; | ||
|
|
||
| @Builder | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빌더는 빼주세요~! |
||
| public Post(Long userId, Long schoolId, String title, String content, PostType postType, Status status) { | ||
| this.userId = userId; | ||
| this.schoolId = schoolId; | ||
| public Post(User user, School school, String title, String content, PostType postType, Status status) { | ||
| this.user = user; | ||
| this.school = school; | ||
| this.title = title; | ||
| this.content = content; | ||
| this.postType = postType; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,79 @@ | ||
| package org.battles.battles.post; | ||
|
|
||
| public class PostController { | ||
| import io.swagger.annotations.Api; | ||
| import io.swagger.annotations.ApiImplicitParam; | ||
| import io.swagger.annotations.ApiImplicitParams; | ||
| import io.swagger.annotations.ApiOperation; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.battles.battles.post.Dto.PostsSaveRequestDto; | ||
| import org.battles.battles.response.CommonResult; | ||
| import org.battles.battles.response.ResponseService; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import org.springframework.security.core.Authentication; | ||
|
|
||
| @Api(tags = {"6. 게시판 컨트롤러"}) | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/post") | ||
| @Slf4j | ||
| public class PostController{ | ||
| private final ResponseService responseService; | ||
|
|
||
| private final PostService postService; | ||
| @ApiImplicitParams({ | ||
| @ApiImplicitParam(name = "AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header") | ||
| }) | ||
| @ApiOperation(value = "전체 게시글 작성", notes = "회원정보와 제목, 내용을 입력하여 전체 게시글을 작성한다.") | ||
| @PostMapping("/entire") | ||
| public CommonResult saveEntire(@RequestBody PostsSaveRequestDto requestDto) { | ||
| Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| String email = authentication.getName(); | ||
|
|
||
| return responseService.getSingleResult(postService.saveEntire(email, requestDto)); | ||
| } | ||
|
|
||
| @ApiImplicitParams({ | ||
| @ApiImplicitParam(name = "AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header") | ||
| }) | ||
| @ApiOperation(value = "학교 게시글 작성", notes = "회원정보와 제목, 내용을 입력하여 학교 게시글을 작성한다.") | ||
| @PostMapping("/{schoolId}") | ||
| public CommonResult saveSchool(@RequestBody PostsSaveRequestDto requestDto, @PathVariable Long schoolId) { | ||
| Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| String email = authentication.getName(); | ||
|
|
||
| return responseService.getSingleResult(postService.saveSchool(email, requestDto, schoolId)); | ||
| } | ||
| @ApiOperation(value = "게시글 단건 조회", notes = "게시글 단건을 조회한다.") | ||
| @GetMapping("/{postId}") | ||
| public CommonResult getPostById(@PathVariable Long postId) { | ||
|
|
||
| return responseService.getSingleResult(postService.getPostById(postId)); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @ApiOperation(value = "전체 게시글 조회", notes = "전체 게시글을 조회한다.") | ||
| @GetMapping("/entire") | ||
| public CommonResult getEntirePosts() { | ||
|
|
||
| return responseService.getListResult(postService.getPostAllEntire()); | ||
| } | ||
|
|
||
| @ApiOperation(value = "학교별 게시글 조회", notes = "학교 게시글을 조회한다.") | ||
| @GetMapping("/school/{schoolId}") | ||
| public CommonResult getSchoolPosts(@PathVariable Long schoolId) { | ||
|
|
||
| return responseService.getListResult(postService.getPostAllSchool(schoolId)); | ||
| } | ||
|
|
||
|
|
||
| @ApiOperation(value = "모든 게시글 조회", notes = "모든 게시글을 조회한다.") | ||
| @GetMapping("/all") | ||
| public CommonResult getAllPosts() { | ||
|
|
||
| return responseService.getListResult(postService.getPostAll()); | ||
| } | ||
|
|
||
| } |
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.
코드 좋습니다!! 다만 api문서를 그렇게 작성했던 것 같긴 한데 순간 response로 모두 보내줘야 할까 싶은데 .. 어떻게 생각하세요? 모두 보내줘야겠다 싶으시면 이부분은 수정안하셔도 됩니다!