working on editor for polls
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -102,6 +102,7 @@ public class Field {
|
||||
|
||||
public static final String OBJECT = "object";
|
||||
public static final String OFFSET = "offset";
|
||||
public static final String OPTIONS = "options";
|
||||
public static final String OPTIONAL = "optional";
|
||||
public static final String OPTION_ID = "option_id";
|
||||
public static final String OWNER = "owner";
|
||||
@@ -133,6 +134,7 @@ public class Field {
|
||||
public static final String SENDER = "sender";
|
||||
public static final String SENDER_USER_ID = "sender_user_id";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SHARES = "shares";
|
||||
public static final String SHOW_CLOSED = "show_closed";
|
||||
public static final String SILENT = "silent";
|
||||
public static final String SOURCE = "source";
|
||||
@@ -182,4 +184,5 @@ public class Field {
|
||||
public static final String VERSIONS = "versions";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
public static final String WEIGHTS = "weights";
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class Text {
|
||||
public static final String NUMBER = "number";
|
||||
|
||||
public static final String PATH = "path";
|
||||
public static final String POLL = "poll";
|
||||
public static final String POLLS = "polls";
|
||||
public static final String PROJECTS = "projects";
|
||||
public static final String PROJECT_WITH_ID = "project ({id})";
|
||||
|
||||
@@ -8,30 +8,75 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
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 record Option(Integer id, String name, String description, Integer status) implements Mappable{
|
||||
public static Option of(ResultSet rs) throws SQLException {
|
||||
var id = rs.getInt(ID);
|
||||
var name = rs.getString(NAME);
|
||||
var description = rs.getString(DESCRIPTION);
|
||||
var status = rs.getInt(STATUS);
|
||||
|
||||
return new Option(id,name,description,status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(
|
||||
ID,id,
|
||||
NAME,name,
|
||||
DESCRIPTION, Map.of(
|
||||
SOURCE,description,
|
||||
RENDERED,Util.markdown(description)
|
||||
),
|
||||
STATUS,status
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public record Poll(String id, Owner owner, String name, String description, boolean isPrivate) implements Mappable {
|
||||
public static Poll of(ResultSet rs) throws SQLException {
|
||||
var id = rs.getString(Field.ID);
|
||||
var userId = rs.getLong(Field.USER_ID);
|
||||
var name = rs.getString(Field.NAME);
|
||||
var id = rs.getString(ID);
|
||||
var userId = rs.getLong(Field.USER_ID);
|
||||
var name = rs.getString(NAME);
|
||||
var description = rs.getString(Field.DESCRIPTION);
|
||||
var isPrivate = rs.getBoolean(Field.PRIVATE);
|
||||
var owner = ModuleRegistry.userService().loadUser(userId);
|
||||
return new Poll(id,owner,name,description,isPrivate);
|
||||
var isPrivate = rs.getBoolean(Field.PRIVATE);
|
||||
var owner = ModuleRegistry.userService().loadUser(userId);
|
||||
|
||||
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>(),new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(
|
||||
Field.ID, id,
|
||||
ID, id,
|
||||
Field.OWNER, owner.toMap(),
|
||||
Field.NAME,name,
|
||||
NAME,name,
|
||||
Field.DESCRIPTION, Map.of(
|
||||
Field.SOURCE,description,
|
||||
Field.RENDERED,Util.markdown(description)
|
||||
),
|
||||
Field.PRIVATE, isPrivate
|
||||
Field.OPTIONS, options.stream().map(Option::toMap).toList(),
|
||||
Field.SHARES, mapShares(),
|
||||
Field.PRIVATE, isPrivate,
|
||||
Field.WEIGHTS, weights
|
||||
);
|
||||
}
|
||||
|
||||
private Map<Long, Map<String, Object>> mapShares() {
|
||||
var result = new HashMap<Long,Map<String,Object>>();
|
||||
for (var entry : shares.entrySet()){
|
||||
var user = entry.getKey();
|
||||
var data = user.toMap();
|
||||
data.put(Field.PERMISSION,entry.getValue());
|
||||
result.put(user.id(),data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user