fix(api): return updated switch in PATCH /switches/:id
This commit is contained in:
parent
6ed066de29
commit
92ef6d4ec3
@ -183,7 +183,7 @@ public class SwitchControllerV2: PKControllerBase
|
|||||||
if (await _repo.GetSwitches(system.Id).Select(x => x.Timestamp).ContainsAsync(value))
|
if (await _repo.GetSwitches(system.Id).Select(x => x.Timestamp).ContainsAsync(value))
|
||||||
throw Errors.SameSwitchTimestampError;
|
throw Errors.SameSwitchTimestampError;
|
||||||
|
|
||||||
await _repo.MoveSwitch(sw.Id, value);
|
sw = await _repo.MoveSwitch(sw.Id, value);
|
||||||
|
|
||||||
var members = await _db.Execute(conn => _repo.GetSwitchMembers(conn, sw.Id)).ToListAsync();
|
var members = await _db.Execute(conn => _repo.GetSwitchMembers(conn, sw.Id)).ToListAsync();
|
||||||
return Ok(new FrontersReturnNew
|
return Ok(new FrontersReturnNew
|
||||||
|
@ -92,11 +92,11 @@ public partial class ModelRepository
|
|||||||
_logger.Information("Updated {SwitchId} members: {Members}", switchId, members);
|
_logger.Information("Updated {SwitchId} members: {Members}", switchId, members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MoveSwitch(SwitchId id, Instant time)
|
public async Task<PKSwitch> MoveSwitch(SwitchId id, Instant time)
|
||||||
{
|
{
|
||||||
_logger.Information("Updated {SwitchId} timestamp: {SwitchTimestamp}", id, time);
|
_logger.Information("Updated {SwitchId} timestamp: {SwitchTimestamp}", id, time);
|
||||||
var query = new Query("switches").AsUpdate(new { timestamp = time }).Where("id", id);
|
var query = new Query("switches").AsUpdate(new { timestamp = time }).Where("id", id);
|
||||||
await _db.ExecuteQuery(query);
|
var ret = await _db.QueryFirst<PKSwitch>(query, extraSql: "returning *");
|
||||||
_ = _dispatch.Dispatch(id, new UpdateDispatchData
|
_ = _dispatch.Dispatch(id, new UpdateDispatchData
|
||||||
{
|
{
|
||||||
Event = DispatchEvent.UPDATE_SWITCH,
|
Event = DispatchEvent.UPDATE_SWITCH,
|
||||||
@ -105,6 +105,7 @@ public partial class ModelRepository
|
|||||||
timestamp = time.FormatExport(),
|
timestamp = time.FormatExport(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteSwitch(SwitchId id)
|
public async Task DeleteSwitch(SwitchId id)
|
||||||
|
Loading…
Reference in New Issue
Block a user