Skip to content

Commit 52ffbec

Browse files
Merge pull request #159 from prgrms-web-devcourse-final-project/feature/EA3-163-study-post-implement
[EA3-163] Feature: 스터디 게시글 CRUD 추가
2 parents 4bbb9a8 + 313d58a commit 52ffbec

36 files changed

+1417
-247
lines changed

src/main/java/grep/neogul_coder/domain/comment/Comment.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/grep/neogul_coder/domain/quiz/controller/AiQuizController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,30 @@
88
import grep.neogul_coder.domain.quiz.service.AiQuizServiceImpl;
99
import grep.neogul_coder.domain.studypost.Category;
1010
import grep.neogul_coder.domain.studypost.StudyPost;
11-
import grep.neogul_coder.domain.studypost.service.StudyPostService;
11+
import grep.neogul_coder.domain.studypost.repository.StudyPostRepository;
1212
import grep.neogul_coder.global.response.ApiResponse;
13-
import java.util.Optional;
1413
import lombok.RequiredArgsConstructor;
1514
import org.springframework.web.bind.annotation.GetMapping;
1615
import org.springframework.web.bind.annotation.PathVariable;
1716
import org.springframework.web.bind.annotation.RequestMapping;
1817
import org.springframework.web.bind.annotation.RestController;
1918

19+
import java.util.Optional;
20+
2021

2122
@RestController
2223
@RequiredArgsConstructor
2324
@RequestMapping("/api/post/ai")
2425
public class AiQuizController implements AiQuizSpecification {
2526

26-
private final StudyPostService studyPostService;
27+
private final StudyPostRepository studyPostRepository;
2728
private final AiQuizServiceImpl aiQuizServiceImpl;
2829
private final AiQuizRepository aiQuizRepository;
2930

3031
@GetMapping("/{postId}")
3132
public ApiResponse<QuizResponse> get(@PathVariable("postId") Long postId) {
3233

33-
StudyPost post = studyPostService.findById(postId);
34+
StudyPost post = studyPostRepository.findById(postId).orElseThrow();
3435

3536
if (!Category.FREE.equals((post.getCategory()))) {
3637
throw new PostNotFreeException(QuizErrorCode.POST_NOT_FREE_ERROR);

src/main/java/grep/neogul_coder/domain/study/StudyMember.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class StudyMember extends BaseEntity {
2525

2626
private boolean participated;
2727

28-
protected StudyMember() {}
28+
protected StudyMember() {
29+
}
2930

3031
@Builder
3132
public StudyMember(Study study, Long userId, StudyMemberRole role) {
@@ -43,7 +44,7 @@ public boolean isLeader() {
4344
return this.role == StudyMemberRole.LEADER;
4445
}
4546

46-
public boolean hasNotRoleLeader(){
47+
public boolean hasNotRoleLeader() {
4748
return this.role != StudyMemberRole.LEADER;
4849
}
4950

src/main/java/grep/neogul_coder/domain/study/controller/dto/response/StudyMyContentResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package grep.neogul_coder.domain.study.controller.dto.response;
22

3-
import grep.neogul_coder.domain.studypost.dto.StudyPostListResponse;
3+
import grep.neogul_coder.domain.studypost.controller.dto.StudyPostListResponse;
44
import io.swagger.v3.oas.annotations.media.Schema;
55
import lombok.Getter;
66

src/main/java/grep/neogul_coder/domain/study/controller/dto/response/StudyResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import grep.neogul_coder.domain.attendance.controller.dto.response.AttendanceResponse;
44
import grep.neogul_coder.domain.calender.controller.dto.response.TeamCalendarResponse;
5-
import grep.neogul_coder.domain.studypost.dto.StudyPostListResponse;
5+
import grep.neogul_coder.domain.studypost.controller.dto.StudyPostListResponse;
66
import io.swagger.v3.oas.annotations.media.Schema;
77
import lombok.Getter;
88

src/main/java/grep/neogul_coder/domain/studypost/Category.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public enum Category {
1616
public String toJson() {
1717
return korean;
1818
}
19+
20+
public String getKorean() {
21+
return korean;
22+
}
1923
}

src/main/java/grep/neogul_coder/domain/studypost/StudyPost.java

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,57 @@
22

33
import grep.neogul_coder.domain.study.Study;
44
import grep.neogul_coder.global.entity.BaseEntity;
5-
import jakarta.persistence.Column;
6-
import jakarta.persistence.Entity;
7-
import jakarta.persistence.EnumType;
8-
import jakarta.persistence.Enumerated;
9-
import jakarta.persistence.FetchType;
10-
import jakarta.persistence.GeneratedValue;
11-
import jakarta.persistence.GenerationType;
12-
import jakarta.persistence.Id;
13-
import jakarta.persistence.JoinColumn;
14-
import jakarta.persistence.ManyToOne;
15-
import jakarta.validation.constraints.NotBlank;
5+
import jakarta.persistence.*;
6+
import lombok.Builder;
167
import lombok.Getter;
178

189
@Getter
1910
@Entity
2011
public class StudyPost extends BaseEntity {
2112

22-
@Id
23-
@GeneratedValue(strategy = GenerationType.IDENTITY)
24-
private Long id;
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
private Long id;
2516

26-
@ManyToOne(fetch = FetchType.LAZY, optional = false)
27-
@JoinColumn(name = "study_id", nullable = false)
28-
private Study study;
17+
@ManyToOne(fetch = FetchType.LAZY)
18+
@JoinColumn(name = "study_id", nullable = false)
19+
private Study study;
2920

30-
@Column(nullable = false)
31-
private Long userId;
21+
@Column(nullable = false)
22+
private Long userId;
3223

33-
@NotBlank(message = "제목은 필수입니다.")
34-
@Column(nullable = false)
35-
private String title;
24+
@Column(nullable = false)
25+
private String title;
3626

37-
@Enumerated(EnumType.STRING)
38-
@Column(nullable = false)
39-
private Category category;
27+
@Enumerated(EnumType.STRING)
28+
@Column(nullable = false)
29+
private Category category;
4030

41-
@NotBlank(message = "내용은 필수입니다.")
42-
@Column(nullable = false)
43-
private String content;
31+
@Column(nullable = false)
32+
private String content;
4433

34+
protected StudyPost() {
35+
}
36+
37+
@Builder
38+
private StudyPost(Long userId, String title, Category category, String content) {
39+
this.userId = userId;
40+
this.title = title;
41+
this.category = category;
42+
this.content = content;
43+
}
44+
45+
public void connectStudy(Study study) {
46+
this.study = study;
47+
}
48+
49+
public void update(Category category, String title, String content) {
50+
this.category = category;
51+
this.title = title;
52+
this.content = content;
53+
}
54+
55+
public void delete() {
56+
this.activated = false;
57+
}
4558
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package grep.neogul_coder.domain.studypost;
2+
3+
import grep.neogul_coder.global.response.code.ErrorCode;
4+
import lombok.Getter;
5+
import org.springframework.http.HttpStatus;
6+
7+
@Getter
8+
public enum StudyPostErrorCode implements ErrorCode {
9+
NOT_VALID_CONDITION(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.name(), "잘못된 쿼리 조건 입니다."),
10+
NOT_JOINED_STUDY_USER(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.name(), "해당 스터디에 참여 하고 있지 않은 회원 입니다."),
11+
NOT_FOUND_POST(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.name(), "해당 스터디 게시글을 찾지 못했습니다.");
12+
13+
private static final String BASIC_ERROR_NAME = "STUDY_POST";
14+
private final HttpStatus status;
15+
private final String code;
16+
private final String message;
17+
18+
StudyPostErrorCode(HttpStatus status, String code, String message) {
19+
this.status = status;
20+
this.code = BASIC_ERROR_NAME + ": " + code;
21+
this.message = message;
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package grep.neogul_coder.domain.studypost.comment;
2+
3+
import grep.neogul_coder.global.entity.BaseEntity;
4+
import jakarta.persistence.*;
5+
import jakarta.validation.constraints.NotBlank;
6+
import lombok.Builder;
7+
import lombok.Getter;
8+
9+
@Getter
10+
@Entity
11+
public class StudyPostComment extends BaseEntity {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
private Long id;
16+
17+
@Column(nullable = false)
18+
private Long postId;
19+
20+
@Column(nullable = false)
21+
private Long userId;
22+
23+
@Column(nullable = false, length = 100)
24+
@NotBlank(message = "내용은 필수입니다.")
25+
private String content;
26+
27+
protected StudyPostComment() {
28+
}
29+
30+
@Builder
31+
private StudyPostComment(Long postId, Long userId, String content) {
32+
this.postId = postId;
33+
this.userId = userId;
34+
this.content = content;
35+
}
36+
}

src/main/java/grep/neogul_coder/domain/comment/controller/CommentController.java renamed to src/main/java/grep/neogul_coder/domain/studypost/comment/controller/CommentController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package grep.neogul_coder.domain.comment.controller;
1+
package grep.neogul_coder.domain.studypost.comment.controller;
22

3-
import grep.neogul_coder.domain.comment.dto.CommentRequest;
4-
import grep.neogul_coder.domain.comment.dto.CommentResponse;
3+
import grep.neogul_coder.domain.studypost.comment.dto.CommentRequest;
4+
import grep.neogul_coder.domain.studypost.comment.dto.CommentResponse;
55
import grep.neogul_coder.global.response.ApiResponse;
66
import jakarta.validation.Valid;
77
import java.util.List;

0 commit comments

Comments
 (0)