feat: track poll votes

This commit is contained in:
Tim
2025-08-30 12:03:17 +08:00
parent 5adee4db0e
commit 23582934fa
5 changed files with 52 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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;