mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-24 15:10:48 +08:00
feat: track poll votes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.openisle.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents a single vote in a poll, capturing which user selected which option.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "poll_participants")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class PollParticipant {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "post_id", nullable = false)
|
||||
private PollPost post;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@Column(name = "option_index", nullable = false)
|
||||
private int optionIndex;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,8 @@ public class PollPost extends Post {
|
||||
@Column(name = "vote_count")
|
||||
private Map<Integer, Integer> votes = new HashMap<>();
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "poll_participants",
|
||||
joinColumns = @JoinColumn(name = "post_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<User> participants = new HashSet<>();
|
||||
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<PollParticipant> participants = new HashSet<>();
|
||||
|
||||
@Column
|
||||
private LocalDateTime endTime;
|
||||
|
||||
Reference in New Issue
Block a user