This commit is contained in:
Zoe Roux 2024-04-17 23:57:05 +02:00
parent 8a816b587f
commit dc5fd8f5a3
No known key found for this signature in database
3 changed files with 46 additions and 15 deletions

View File

@ -170,6 +170,33 @@ public class CrudApi<T> : BaseApi
return await Repository.Edit(resource);
}
/// <summary>
/// Edit
/// </summary>
/// <remarks>
/// Edit an item. If the ID is specified it will be used to identify the resource.
/// If not, the slug will be used to identify it.
/// </remarks>
/// <param name="identifier">The id or slug of the resource.</param>
/// <param name="resource">The resource to edit.</param>
/// <returns>The edited resource.</returns>
/// <response code="400">The resource in the request body is invalid.</response>
/// <response code="404">No item found with the specified ID (or slug).</response>
[HttpPut("{identifier:id}")]
[PartialPermission(Kind.Write)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<T>> Edit(Identifier identifier, [FromBody] T resource)
{
Guid id = await identifier.Match(
id => Task.FromResult(id),
async slug => (await Repository.Get(slug)).Id
);
resource.Id = id;
return await Repository.Edit(resource);
}
/// <summary>
/// Patch
/// </summary>

View File

@ -43,20 +43,24 @@ class Subscriber:
async def listen(self, scanner: Matcher):
async def on_message(message: AbstractIncomingMessage):
msg = decoder.decode(message.body)
ack = False
match msg:
case Scan(path):
ack = await scanner.identify(path)
case Delete(path):
ack = await scanner.delete(path)
case Refresh(kind, id):
ack = await scanner.refresh(kind, id)
case _:
logger.error(f"Invalid action: {msg.action}")
if ack:
await message.ack()
else:
try:
msg = decoder.decode(message.body)
ack = False
match msg:
case Scan(path):
ack = await scanner.identify(path)
case Delete(path):
ack = await scanner.delete(path)
case Refresh(kind, id):
ack = await scanner.refresh(kind, id)
case _:
logger.error(f"Invalid action: {msg.action}")
if ack:
await message.ack()
else:
await message.reject()
except Exception as e:
logger.exception("Unhandled error", exc_info=e)
await message.reject()
# Allow up to 20 scan requests to run in parallel on the same listener.

View File

@ -177,7 +177,7 @@ class KyooClient:
jdkwargs={"indent": 4},
),
)
async with self.client.post(
async with self.client.put(
f"{self._url}/{path}",
json=data,
headers={"X-API-Key": self._api_key},