working on management of poll weights
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user