implemented creating new poll and managing poll options
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -9,13 +9,11 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.is0;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
public record Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights, Map<UmbrellaUser,Long> shares) implements Mappable {
|
||||
public class Poll implements Mappable {
|
||||
public static class Option implements Mappable{
|
||||
private int id;
|
||||
Integer status;
|
||||
@@ -106,6 +104,47 @@ public record Poll(String id, Owner owner, String name, String description, bool
|
||||
}
|
||||
}
|
||||
|
||||
private Owner owner;
|
||||
private String id, name, description;
|
||||
private boolean isPrivate;
|
||||
private List<Option> options;
|
||||
private Map<Integer,String> weights;
|
||||
private Map<UmbrellaUser,Long> shares;
|
||||
private Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights, Map<UmbrellaUser,Long> shares){
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isPrivate = isPrivate;
|
||||
this.options = new ArrayList<>();
|
||||
this.weights = new HashMap<>();
|
||||
this.shares = new HashMap<>();
|
||||
}
|
||||
|
||||
public String description(){
|
||||
return description;
|
||||
}
|
||||
|
||||
public Poll description(String newVal){
|
||||
description = newVal;
|
||||
dirtyFields.add(DESCRIPTION);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String id(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isDirty(){
|
||||
return !dirtyFields.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isPrivate(){
|
||||
return isPrivate;
|
||||
}
|
||||
|
||||
private Map<Long, Map<String, Object>> mapShares() {
|
||||
var result = new HashMap<Long,Map<String,Object>>();
|
||||
for (var entry : shares.entrySet()){
|
||||
@@ -117,6 +156,16 @@ public record Poll(String id, Owner owner, String name, String description, bool
|
||||
return result;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public Poll name(String newVal){
|
||||
name = newVal;
|
||||
dirtyFields.add(NAME);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Poll of(ResultSet rs) throws SQLException {
|
||||
var id = rs.getString(ID);
|
||||
var userId = rs.getLong(Field.USER_ID);
|
||||
@@ -128,6 +177,16 @@ public record Poll(String id, Owner owner, String name, String description, bool
|
||||
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>(),new HashMap<>());
|
||||
}
|
||||
|
||||
public List<Option> options(){
|
||||
return options;
|
||||
}
|
||||
public Owner owner(){
|
||||
return owner;
|
||||
}
|
||||
|
||||
public Map<UmbrellaUser, Long> shares(){
|
||||
return shares;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
@@ -145,4 +204,8 @@ public record Poll(String id, Owner owner, String name, String description, bool
|
||||
Field.WEIGHTS, weights
|
||||
);
|
||||
}
|
||||
|
||||
public Map<Integer, String> weights(){
|
||||
return weights;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user