💄 Update path param
This commit is contained in:
@@ -544,14 +544,15 @@ public class AccountCurrentController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("devices/{id}/label")]
|
[HttpPatch("devices/{deviceId}/label")]
|
||||||
public async Task<ActionResult<AuthSession>> UpdateDeviceLabel(string id, [FromBody] string label)
|
[Authorize]
|
||||||
|
public async Task<ActionResult<AuthSession>> UpdateDeviceLabel(string deviceId, [FromBody] string label)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await accounts.UpdateDeviceName(currentUser, id, label);
|
await accounts.UpdateDeviceName(currentUser, deviceId, label);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -561,6 +562,7 @@ public class AccountCurrentController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("devices/current/label")]
|
[HttpPatch("devices/current/label")]
|
||||||
|
[Authorize]
|
||||||
public async Task<ActionResult<AuthSession>> UpdateCurrentDeviceLabel([FromBody] string label)
|
public async Task<ActionResult<AuthSession>> UpdateCurrentDeviceLabel([FromBody] string label)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser ||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser ||
|
||||||
|
@@ -464,7 +464,9 @@ public class AccountService(
|
|||||||
|
|
||||||
public async Task<AuthClient> UpdateDeviceName(Account account, string deviceId, string label)
|
public async Task<AuthClient> UpdateDeviceName(Account account, string deviceId, string label)
|
||||||
{
|
{
|
||||||
var device = await db.AuthClients.FirstOrDefaultAsync(d => d.DeviceId == deviceId && d.AccountId == account.Id);
|
var device = await db.AuthClients.FirstOrDefaultAsync(
|
||||||
|
c => c.DeviceId == deviceId && c.AccountId == account.Id
|
||||||
|
);
|
||||||
if (device is null) throw new InvalidOperationException("Device was not found.");
|
if (device is null) throw new InvalidOperationException("Device was not found.");
|
||||||
|
|
||||||
device.DeviceLabel = label;
|
device.DeviceLabel = label;
|
||||||
@@ -508,7 +510,9 @@ public class AccountService(
|
|||||||
|
|
||||||
public async Task DeleteDevice(Account account, string deviceId)
|
public async Task DeleteDevice(Account account, string deviceId)
|
||||||
{
|
{
|
||||||
var device = await db.AuthClients.FirstOrDefaultAsync(c => c.DeviceId == deviceId && c.AccountId == account.Id);
|
var device = await db.AuthClients.FirstOrDefaultAsync(
|
||||||
|
c => c.DeviceId == deviceId && c.AccountId == account.Id
|
||||||
|
);
|
||||||
if (device is null)
|
if (device is null)
|
||||||
throw new InvalidOperationException("Device not found.");
|
throw new InvalidOperationException("Device not found.");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user