Merge branch 'module/poll' into dev
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user