Skip to content

Commit

Permalink
Minor refactoring of TorrentEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
aannenko committed Jul 28, 2024
1 parent e224fbe commit 299210d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/TransmissionManager.Api/Endpoints/TorrentEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public static IEndpointRouteBuilder MapTorrentEndpoints(this IEndpointRouteBuild
group.MapGet("/", FindMany);
group.MapGet("/{id}", FindOneById);
group.MapPost("/", TryAddOrUpdateOneAsync);
group.MapPut("/{id}", UpdateOne);
group.MapDelete("/{id}", RemoveOne);
group.MapPut("/{id}", UpdateOneById);
group.MapDelete("/{id}", RemoveOneById);

return builder;
}

private static Torrent[] FindMany(
[FromServices] TorrentService torrentService,
[FromServices] TorrentService service,
int take = 20,
long afterId = 0,
string? webPageUri = null,
string? nameStartsWith = null,
bool? cronExists = null)
{
return torrentService.FindPage(new()
return service.FindPage(new()
{
Take = take,
AfterId = afterId,
Expand All @@ -46,25 +46,23 @@ private static Torrent[] FindMany(
}

private static Task<bool> TryAddOrUpdateOneAsync(
[FromServices] CompositeService<SchedulableTorrentService> compositeService,
[FromServices] CompositeService<SchedulableTorrentService> service,
TorrentPostRequest dto,
CancellationToken cancellationToken = default)
{
return compositeService.TryAddOrUpdateTorrentAsync(dto, cancellationToken);
return service.TryAddOrUpdateTorrentAsync(dto, cancellationToken);
}

private static void UpdateOne(
[FromServices] SchedulableTorrentService torrentService,
private static void UpdateOneById(
[FromServices] SchedulableTorrentService service,
long id,
TorrentPutRequest dto)
{
torrentService.UpdateOneById(id, dto.ToTorrentUpdateDto());
service.UpdateOneById(id, dto.ToTorrentUpdateDto());
}

private static void RemoveOne(
[FromServices] SchedulableTorrentService torrentService,
long id)
private static void RemoveOneById([FromServices] SchedulableTorrentService service, long id)
{
torrentService.DeleteOneById(id);
service.DeleteOneById(id);
}
}

0 comments on commit 299210d

Please sign in to comment.