Skip to content

Commit

Permalink
Feat: debate에 user 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ho0010 committed Aug 15, 2024
1 parent d5da17b commit a4d9934
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
@Builder
public class PostDebateRequest {

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

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

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 @@ -50,4 +50,8 @@ public class Debate {
@ManyToOne
@JoinColumn(name = "keyword_id", nullable = false)
private Keyword keyword;

@ManyToOne
@JoinColumn(name = "user_id",nullable = false)
private User user;
}
3 changes: 3 additions & 0 deletions src/main/java/store/itpick/backend/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ public class User {

@OneToMany(mappedBy = "user")
private List<UserVoteChoice> userVoteChoices;

@OneToMany(mappedBy = "user")
private List<Debate> debates;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Service;
import store.itpick.backend.common.exception.DebateException;
import store.itpick.backend.common.exception.AuthException;
import store.itpick.backend.common.exception.UserException;
import store.itpick.backend.dto.debate.*;
import store.itpick.backend.dto.vote.PostVoteRequest;
import store.itpick.backend.jwt.JwtProvider;
Expand Down Expand Up @@ -34,10 +35,13 @@ public class DebateService {
@Transactional
public PostDebateResponse createDebate(PostDebateRequest postDebateRequest) {

User user = userRepository.findById(postDebateRequest.getUserId())
.orElseThrow(() -> new UserException(USER_NOT_FOUND));

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 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).user(user).build();

debate = debateRepository.save(debate);

Expand Down

0 comments on commit a4d9934

Please sign in to comment.