diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-30 16:40:03 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-30 16:40:03 +0100 |
| commit | 0725e4f7cf4c6f723264b6d461b91c660d144cb7 (patch) | |
| tree | aae5876b5760c80679161d918c34d753ec0e2582 /code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs | |
| parent | d76c180c9631df015d37138045c79a46cca350e8 (diff) | |
| download | greatoffice-0725e4f7cf4c6f723264b6d461b91c660d144cb7.tar.xz greatoffice-0725e4f7cf4c6f723264b6d461b91c660d144cb7.zip | |
feat: Apiwork
Diffstat (limited to 'code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs')
| -rw-r--r-- | code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs b/code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs new file mode 100644 index 0000000..d60f974 --- /dev/null +++ b/code/api/src/Endpoints/V1/Projects/GetProjectsRoute.cs @@ -0,0 +1,43 @@ +using MR.AspNetCore.Pagination; + +namespace IOL.GreatOffice.Api.Endpoints.V1.Projects; + +public class GetProjectsRoute : RouteBaseAsync.WithRequest<GetProjectsQueryParameters>.WithActionResult<KeysetPaginationResult<GetProjectsResponseDto>> +{ + private readonly MainAppDatabase _database; + private readonly PaginationService _pagination; + + public GetProjectsRoute(MainAppDatabase database, PaginationService pagination) { + _database = database; + _pagination = pagination; + } + + [HttpGet("~/v{version:apiVersion}/projects")] + public override async Task<ActionResult<KeysetPaginationResult<GetProjectsResponseDto>>> HandleAsync(GetProjectsQueryParameters request, CancellationToken cancellationToken = default) { + var result = await _pagination.KeysetPaginateAsync( + _database.Projects.ForTenant(LoggedInUser), + b => b.Descending(x => x.CreatedAt), + async id => await _database.Projects.FindAsync(id), + query => query.Select(p => new GetProjectsResponseDto() { + Id = p.Id, + Name = p.Name + }) + ); + return Ok(result); + } +} + +public class GetProjectsResponseDto +{ + public Guid Id { get; set; } + public string Name { get; set; } +} + +public class GetProjectsQueryParameters +{ + [FromQuery] + public int Page { get; set; } + + [FromQuery] + public int Size { get; set; } +}
\ No newline at end of file |
