working on management of poll weights

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-25 15:34:01 +01:00
parent 4a2c49c42c
commit 5336384e0d
3 changed files with 20 additions and 8 deletions

View File

@@ -137,8 +137,15 @@ public class PollModule extends BaseHandler implements PollService {
}
private boolean patchWeights(HttpExchange ex, Poll poll) throws IOException {
// TODO
return notFound(ex);
var json = json(ex);
for (var key : json.keySet()) try {
var weight = Integer.parseInt(key);
if (!(json.get(key) instanceof String description)) throw invalidField(Field.DESCRIPTION,Text.STRING);
poll.setWeight(weight,description);
} catch (NumberFormatException nfe) {
throw invalidField(Text.WEIGHT,Text.NUMBER);
}
return sendContent(ex,pollDb.save(poll));
}
private boolean patchPollOptions(HttpExchange ex, Path path, Poll poll) throws IOException {

View File

@@ -112,7 +112,7 @@ public class SqliteDb extends BaseDb implements PollDb {
private void dropWeight(Poll poll, int weight){
try {
delete().from(TABLE_WEIGHTS).where(POLL_ID, equal(poll.id())).where(ID, equal(weight)).execute(db);
delete().from(TABLE_WEIGHTS).where(POLL_ID, equal(poll.id())).where(WEIGHT, equal(weight)).execute(db);
poll.weights().remove(weight);
} catch (SQLException e){
throw failedToDropObject(Text.WEIGHT);