Merge branch 'module/poll' into dev
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m23s
Build Docker Image / Clean-Registry (push) Successful in -6s

This commit is contained in:
2026-03-10 11:35:01 +01:00
13 changed files with 153 additions and 27 deletions

View File

@@ -10,7 +10,7 @@ import java.util.Map;
public interface PollDb {
Collection<Poll> listPolls(UmbrellaUser user);
Poll.Evaluation loadEvaluation(String id);
Poll.Evaluation loadEvaluation(Poll poll);
Poll loadPoll(String id);

View File

@@ -113,7 +113,7 @@ public class PollModule extends BaseHandler implements PollService {
}
}
var result = new HashMap<>(poll.toMap());
var evaluation = pollDb.loadEvaluation(poll.id());
var evaluation = pollDb.loadEvaluation(poll);
result.put(Field.EVALUATION,evaluation.toMap());
return sendContent(ex,result);
}

View File

@@ -132,25 +132,27 @@ public class SqliteDb extends BaseDb implements PollDb {
ps.setLong(1,user.id());
ps.setLong(2, user.id());
var rs = ps.executeQuery();
var list = new ArrayList<Poll>();
var map = new HashMap<String,Poll>();
while (rs.next()) {
var pollId = rs.getString(ID);
if (map.containsKey(pollId)) continue;
var poll = Poll.of(rs);
var perm = rs.getInt(PERMISSION);
if (perm != 0) poll.permissions().put(user,Permission.of(perm));
list.add(poll);
map.put(pollId,poll);
}
rs.close();
return list;
return map.values().stream().sorted(Comparator.comparing(Poll::name)).toList();
} catch (SQLException sqle){
throw failedToLoadObject(TABLE_POLLS);
}
}
@Override
public Poll.Evaluation loadEvaluation(String pollId) {
public Poll.Evaluation loadEvaluation(Poll poll) {
try {
var result = new Poll.Evaluation();
var rs = select(ALL).from(TABLE_SELECTIONS).where(POLL_ID,equal(pollId)).exec(db);
var result = new Poll.Evaluation(poll);
var rs = select(ALL).from(TABLE_SELECTIONS).where(POLL_ID,equal(poll.id())).exec(db);
while (rs.next()) result.count(rs);
rs.close();
return result;