From 8ad8dfb0605d0bb93d969f71efd8ffb6d5168ff6 Mon Sep 17 00:00:00 2001 From: Andrew Schlackman <72105194+sei-aschlackman@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:08:52 -0400 Subject: [PATCH] changed GetResource to use address as unique identifier --- .../Features/Resources/Queries/Get.cs | 17 +++++------------ .../Features/Resources/ResourcesController.cs | 6 +++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Caster.Api/Features/Resources/Queries/Get.cs b/src/Caster.Api/Features/Resources/Queries/Get.cs index be54a17..c335cdb 100644 --- a/src/Caster.Api/Features/Resources/Queries/Get.cs +++ b/src/Caster.Api/Features/Resources/Queries/Get.cs @@ -33,17 +33,10 @@ public class Query : IRequest public Guid WorkspaceId { get; set; } /// - /// Id of the Resource. + /// Address of the Resource /// [JsonIgnore] - public string Id { get; set; } - - /// - /// Type of the Resource. - /// - [DataMember] - [Required] - public string Type { get; set; } + public string Address { get; set; } } public class Handler : IRequestHandler @@ -70,7 +63,7 @@ public async Task Handle(Query request, CancellationToken cancellation if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) throw new ForbiddenException(); - var workspace = await _db.Workspaces.FindAsync(request.WorkspaceId); + var workspace = await _db.Workspaces.FindAsync(request.WorkspaceId, cancellationToken); if (workspace == null) throw new EntityNotFoundException(); @@ -78,9 +71,9 @@ public async Task Handle(Query request, CancellationToken cancellation var state = workspace.GetState(); var resources = state.GetResources(); - var id = HttpUtility.UrlDecode(request.Id); + var address = HttpUtility.UrlDecode(request.Address); - var resource = resources.Where(r => r.Type == request.Type && r.Id == id).FirstOrDefault(); + var resource = resources.Where(r => r.Address == address).FirstOrDefault(); return _mapper.Map(resource, opts => opts.ExcludeMembers()); } } diff --git a/src/Caster.Api/Features/Resources/ResourcesController.cs b/src/Caster.Api/Features/Resources/ResourcesController.cs index 833558f..e6ce439 100644 --- a/src/Caster.Api/Features/Resources/ResourcesController.cs +++ b/src/Caster.Api/Features/Resources/ResourcesController.cs @@ -27,13 +27,13 @@ public ResourcesController(IMediator mediator) /// /// Get a single resource in a Workspace. /// - [HttpGet("workspaces/{workspaceId}/resources/{id}")] + [HttpGet("workspaces/{workspaceId}/resources/{address}")] [ProducesResponseType(typeof(Resource), (int)HttpStatusCode.OK)] [SwaggerOperation(OperationId = "GetResource")] - public async Task Get([FromRoute] Guid workspaceId, [FromRoute] string id, [FromQuery] Get.Query query) + public async Task Get([FromRoute] Guid workspaceId, [FromRoute] string address, [FromQuery] Get.Query query) { query.WorkspaceId = workspaceId; - query.Id = id; + query.Address = address; var result = await _mediator.Send(query); return Ok(result); }