Skip to content

Commit

Permalink
Merge pull request #73 from ho0010/dev
Browse files Browse the repository at this point in the history
Feat: debate keyword 반영
  • Loading branch information
ho0010 authored Aug 11, 2024
2 parents eda424f + c1c57ad commit 8824d73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
COMMENT_PARENT_NOT_FOUND(6003,HttpStatus.BAD_REQUEST.value(), "부모 댓글이 존재하지 않습니다."),
INVALID_COMMENT_HEART_VALUE(6004,HttpStatus.BAD_REQUEST.value(), "댓글 좋아요 생성 요청에서 잘못된 값이 존재합니다."),
COMMENT_NOT_FOUND(6005,HttpStatus.BAD_REQUEST.value(), "해당 댓글이 존재하지 않습니다."),
KEYWORD_NOT_FOUND(6006,HttpStatus.BAD_REQUEST.value(), "해당 키워드가 존재하지 않습니다."),


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store.itpick.backend.dto.debate;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -14,6 +15,9 @@
@Builder
public class PostDebateRequest {

@NotNull(message = "keyword ID는 필수입니다.")
private Long keywordId;

@NotBlank(message = "title은 필수입니다.")
private String title;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/store/itpick/backend/model/Debate.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public class Debate {

@OneToMany(mappedBy = "debate")
private List<Comment> comment;

@ManyToOne
@JoinColumn(name = "keyword_id", nullable = false)
private Keyword keyword;
}
3 changes: 3 additions & 0 deletions src/main/java/store/itpick/backend/model/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Keyword {
)
private List<CommunityPeriod> communityPeriods = new ArrayList<>();

@OneToMany(mappedBy = "keyword")
private List<Debate> debates;

@PrePersist
protected void onCreate() {
Timestamp now = Timestamp.from(Instant.now());
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/store/itpick/backend/service/DebateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@
import store.itpick.backend.dto.debate.*;
import store.itpick.backend.dto.vote.PostVoteRequest;
import store.itpick.backend.jwt.JwtProvider;
import store.itpick.backend.model.Comment;
import store.itpick.backend.model.CommentHeart;
import store.itpick.backend.model.Debate;
import store.itpick.backend.model.User;
import store.itpick.backend.repository.CommentHeartRepository;
import store.itpick.backend.repository.CommentRepository;
import store.itpick.backend.repository.DebateRepository;
import store.itpick.backend.repository.UserRepository;
import store.itpick.backend.model.*;
import store.itpick.backend.repository.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
Expand All @@ -30,6 +24,7 @@
@RequiredArgsConstructor
public class DebateService {

private final KeywordRepository keywordRepository;
private final DebateRepository debateRepository;
private final CommentRepository commentRepository;
private final CommentHeartRepository commentHeartRepository;
Expand All @@ -38,7 +33,11 @@ public class DebateService {

@Transactional
public PostDebateResponse createDebate(PostDebateRequest postDebateRequest) {
Debate debate = Debate.builder().title(postDebateRequest.getTitle()).content(postDebateRequest.getContent()).hits(0L).onTrend(false).status("active").createAt(Timestamp.valueOf(LocalDateTime.now())).updateAt(Timestamp.valueOf(LocalDateTime.now())).build();

Keyword keyword = keywordRepository.findById(postDebateRequest.getKeywordId())
.orElseThrow(() -> new DebateException(KEYWORD_NOT_FOUND));

Debate debate = Debate.builder().title(postDebateRequest.getTitle()).content(postDebateRequest.getContent()).hits(0L).onTrend(false).status("active").createAt(Timestamp.valueOf(LocalDateTime.now())).updateAt(Timestamp.valueOf(LocalDateTime.now())).keyword(keyword).build();

debate = debateRepository.save(debate);

Expand Down

0 comments on commit 8824d73

Please sign in to comment.