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); 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> /// <summary>
/// Patch /// Patch
/// </summary> /// </summary>

View File

@ -43,20 +43,24 @@ class Subscriber:
async def listen(self, scanner: Matcher): async def listen(self, scanner: Matcher):
async def on_message(message: AbstractIncomingMessage): async def on_message(message: AbstractIncomingMessage):
msg = decoder.decode(message.body) try:
ack = False msg = decoder.decode(message.body)
match msg: ack = False
case Scan(path): match msg:
ack = await scanner.identify(path) case Scan(path):
case Delete(path): ack = await scanner.identify(path)
ack = await scanner.delete(path) case Delete(path):
case Refresh(kind, id): ack = await scanner.delete(path)
ack = await scanner.refresh(kind, id) case Refresh(kind, id):
case _: ack = await scanner.refresh(kind, id)
logger.error(f"Invalid action: {msg.action}") case _:
if ack: logger.error(f"Invalid action: {msg.action}")
await message.ack() if ack:
else: await message.ack()
else:
await message.reject()
except Exception as e:
logger.exception("Unhandled error", exc_info=e)
await message.reject() await message.reject()
# Allow up to 20 scan requests to run in parallel on the same listener. # 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}, jdkwargs={"indent": 4},
), ),
) )
async with self.client.post( async with self.client.put(
f"{self._url}/{path}", f"{self._url}/{path}",
json=data, json=data,
headers={"X-API-Key": self._api_key}, headers={"X-API-Key": self._api_key},