-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from KEEPER31337/Election_관련_Entity_Repositor…
…y_생성 Feature/Election 관련 entity repository 생성
- Loading branch information
Showing
14 changed files
with
524 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/keeper/homepage/domain/election/dao/ElectionCandidateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.keeper.homepage.domain.election.dao; | ||
|
||
import com.keeper.homepage.domain.election.entity.ElectionCandidate; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ElectionCandidateRepository extends JpaRepository<ElectionCandidate, Long> { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/keeper/homepage/domain/election/dao/ElectionChartLogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.keeper.homepage.domain.election.dao; | ||
|
||
import com.keeper.homepage.domain.election.entity.ElectionChartLog; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ElectionChartLogRepository extends JpaRepository<ElectionChartLog, Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/keeper/homepage/domain/election/dao/ElectionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.keeper.homepage.domain.election.dao; | ||
|
||
import com.keeper.homepage.domain.election.entity.Election; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ElectionRepository extends JpaRepository<Election, Long> { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/keeper/homepage/domain/election/dao/ElectionVoterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.keeper.homepage.domain.election.dao; | ||
|
||
import com.keeper.homepage.domain.election.entity.Election; | ||
import com.keeper.homepage.domain.election.entity.ElectionVoter; | ||
import com.keeper.homepage.domain.election.entity.ElectionVoterPK; | ||
import com.keeper.homepage.domain.member.entity.Member; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ElectionVoterRepository extends JpaRepository<ElectionVoter, ElectionVoterPK> { | ||
|
||
Optional <ElectionVoter> findByMemberAndElectionAndIsVoted(Member member, Election election, Boolean isVoted); | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/keeper/homepage/domain/election/entity/Election.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.keeper.homepage.domain.election.entity; | ||
|
||
import static jakarta.persistence.CascadeType.REMOVE; | ||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.keeper.homepage.domain.member.entity.Member; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
@DynamicInsert | ||
@DynamicUpdate | ||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "election") | ||
public class Election { | ||
|
||
private static final int MAX_NAME_LENGTH = 45; | ||
private static final int MAX_DESCRIPTION_LENGTH = 200; | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "id", nullable = false, updatable = false) | ||
private Long id; | ||
|
||
@Column(name = "name", nullable = false, length = MAX_NAME_LENGTH) | ||
private String name; | ||
|
||
@Column(name = "description", length = MAX_DESCRIPTION_LENGTH) | ||
private String description; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "creator", nullable = false) | ||
private Member member; | ||
|
||
@Column(name = "register_time", nullable = false) | ||
private LocalDateTime registerTime; | ||
|
||
@Column(name = "is_available", nullable = false) | ||
private Boolean isAvailable; | ||
|
||
@OneToMany(mappedBy = "election", cascade = REMOVE) | ||
private final List<ElectionCandidate> electionCandidates = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "election") | ||
private final List<ElectionVoter> electionVoters = new ArrayList<>(); | ||
|
||
@Builder | ||
private Election(String name, String description, Member member, | ||
Boolean isAvailable) { | ||
this.name = name; | ||
this.description = description; | ||
this.member = member; | ||
this.registerTime = LocalDateTime.now(); | ||
this.isAvailable = isAvailable; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/keeper/homepage/domain/election/entity/ElectionCandidate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.keeper.homepage.domain.election.entity; | ||
|
||
import static jakarta.persistence.CascadeType.REMOVE; | ||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.keeper.homepage.domain.member.entity.Member; | ||
import com.keeper.homepage.domain.member.entity.job.MemberJob; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
@DynamicInsert | ||
@DynamicUpdate | ||
@Entity | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "election_candidate") | ||
public class ElectionCandidate { | ||
|
||
private static final int MAX_DESCRIPTION_LENGTH = 200; | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "id", nullable = false, updatable = false) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "election_id", nullable = false) | ||
private Election election; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "candidate_id", nullable = false) | ||
private Member member; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "member_job_id", nullable = false) | ||
private MemberJob memberJob; | ||
|
||
@Column(name = "description", length = MAX_DESCRIPTION_LENGTH) | ||
private String description; | ||
|
||
@Column(name = "register_time", nullable = false) | ||
private LocalDateTime registerTime; | ||
|
||
@Column(name = "vote_count", nullable = false) | ||
private Long voteCount; | ||
|
||
@OneToMany(mappedBy = "electionCandidate", cascade = REMOVE) | ||
private final List<ElectionChartLog> electionChartLogs = new ArrayList<>(); | ||
|
||
@Builder | ||
private ElectionCandidate(Election election, Member member, MemberJob memberJob, | ||
String description, Long voteCount) { | ||
this.election = election; | ||
this.member = member; | ||
this.memberJob = memberJob; | ||
this.registerTime = LocalDateTime.now(); | ||
this.description = description; | ||
this.voteCount = voteCount; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/keeper/homepage/domain/election/entity/ElectionChartLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.keeper.homepage.domain.election.entity; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
@DynamicInsert | ||
@DynamicUpdate | ||
@Entity | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "election_chart_log") | ||
public class ElectionChartLog { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "id", nullable = false, updatable = false) | ||
private Long id; | ||
|
||
@Column(name = "vote_time", nullable = false) | ||
private LocalDateTime voteTime; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "election_candidate_id", nullable = false) | ||
private ElectionCandidate electionCandidate; | ||
|
||
@Builder | ||
private ElectionChartLog(LocalDateTime voteTime, ElectionCandidate electionCandidate) { | ||
this.voteTime = voteTime; | ||
this.electionCandidate = electionCandidate; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/keeper/homepage/domain/election/entity/ElectionVoter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.keeper.homepage.domain.election.entity; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.keeper.homepage.domain.member.entity.Member; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
@DynamicInsert | ||
@DynamicUpdate | ||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "election_voter") | ||
@IdClass(ElectionVoterPK.class) | ||
public class ElectionVoter { | ||
|
||
@Id | ||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "voter_id", nullable = false) | ||
private Member member; | ||
|
||
@Id | ||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "election_id", nullable = false) | ||
private Election election; | ||
|
||
@Column(name = "is_voted", nullable = false) | ||
private Boolean isVoted; | ||
|
||
@Builder | ||
private ElectionVoter(Member member, Election election, Boolean isVoted) { | ||
this.member = member; | ||
this.election = election; | ||
this.isVoted = isVoted; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/keeper/homepage/domain/election/entity/ElectionVoterPK.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.keeper.homepage.domain.election.entity; | ||
|
||
import java.io.Serializable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ElectionVoterPK implements Serializable { | ||
|
||
private Long member; | ||
private Long election; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.