Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/debatetimer/domain/poll/PollStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.debatetimer.domain.poll;

public enum PollStatus {

PROGRESS,
DONE,
;
}
8 changes: 8 additions & 0 deletions src/main/java/com/debatetimer/domain/poll/VoteTeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.debatetimer.domain.poll;

public enum VoteTeam {

PROS,
CONS,
;
}
39 changes: 39 additions & 0 deletions src/main/java/com/debatetimer/entity/poll/PollEntity.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도메인 없이 일단 엔티티만 사용하는 건가요? 아니면 도메인은 다음 작업에서 구현하시는 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[의견 🔈 ]

투표 API는 기존 도메인과 분리된 부분이기 때문에 영향 줄 부분이 크게 없다고 생각되어 API 뽑으면서 도메인까지 붙이겠습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.debatetimer.entity.poll;

import com.debatetimer.domain.poll.PollStatus;
import com.debatetimer.entity.customize.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "poll")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PollEntity extends BaseTimeEntity {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이럴꺼면 CustomizeTimeBox에도 Entity 붙여주세요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unifolio0 이건 다음에 작업하는 사람이 하는 걸로 합시다. 일단은 "투표 API 관련 엔티티"만 보는 건 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CustomizeTimeBox에도 도메인 -엔티티 분리 작업 리팩터링하면서 Entity suffix 붙을 것 같아요.


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private long tableId;

@NotNull
@Enumerated(EnumType.STRING)
private PollStatus status;

@NotBlank
private String prosTeamName;

@NotBlank
private String consTeamName;
Comment on lines +32 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CustomizeTable에서 검증했기 때문에 여기선 검증하지 않는 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네, 그렇게 판단한 이유는 다음과 같아요.

일단, 최대한 도메인 검증에 대한 책임은 Entity 단에서 수행하지 않는 것을 지향합니다.

선거 엔티티가 각 팀 이름을 검증하는 것이 어색하게 느껴졌습니다.

만약 팀이름에 대한 검증로직이 해당 엔티티에 추가되면 중복 검증이 되어 관리포인트가 2가지로 생깁니다.

따라서 생성 루트 일원화를 통해 관리하는 것이 바람직하다고 판단했습니다.


private String agenda;
}
42 changes: 42 additions & 0 deletions src/main/java/com/debatetimer/entity/poll/VoteEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.debatetimer.entity.poll;

import com.debatetimer.domain.poll.VoteTeam;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "vote")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class VoteEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "poll_id")
private PollEntity poll;

@NotNull
@Enumerated(EnumType.STRING)
private VoteTeam team;

@NotBlank
private String name;

@NotBlank
private String participantCode;
}
25 changes: 25 additions & 0 deletions src/main/resources/db/migration/V9__create_poll_and_vote_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE poll
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
table_id BIGINT NOT NULL,
status ENUM ('PROGRESS','DONE') NOT NULL,
pros_team_name VARCHAR(255) NOT NULL,
cons_team_name VARCHAR(255) NOT NULL,
agenda VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE vote
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
poll_id BIGINT NOT NULL,
team ENUM ('CONS','PROS') NOT NULL,
name VARCHAR(255) NOT NULL,
participant_code VARCHAR(255) NOT NULL
);

alter table vote
add constraint vote_to_poll
foreign key (poll_id)
references poll (id);