Skip to content

Commit

Permalink
[#24] update file-items controller to support Get including directory…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
philipphoeninger committed Oct 29, 2024
1 parent 2c1a221 commit ff94487
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions API/API.FileSharing/API.FileSharing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion API/API.FileSharing/Controllers/FileItemsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace API.FileSharing.Controllers;
namespace API.FileSharing.Controllers;

[ApiController]
[Route("api/[controller]")]
Expand All @@ -8,5 +8,56 @@ public FileItemsController(IAppLogging<FileItemsController> logger, IFileItemRep
{
}

/// <summary>
/// Gets a single record & it's corresponding path
/// </summary>
/// <param name="id">Primary key of the record</param>
/// <returns>Single record</returns>
[HttpGet("withPath/{id}")]
[ApiVersion("0.1")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[SwaggerResponse(200, "The execution was successful")]
[SwaggerResponse(204, "No content")]
[SwaggerResponse(400, "The request was invalid")]
[SwaggerResponse(401, "Unauthorized access attempted")]
public ActionResult<GetFileItemResponse> GetOneWithPath(int id)
{
var entity = MainRepo.Find(id);
if (entity == null) return NoContent();

List<PathModel> path = [];
path.Add(new PathModel()
{
FileItemId = entity.Id,
PathName = entity.Name,
SortId = 0
});
var parent = entity.ParentNavigation;
int sortId = 1;
while (parent != null)
{
PathModel parentPath = new PathModel()
{
FileItemId = parent.Id,
PathName = parent.Name,
SortId = sortId
};
path.Add(parentPath);
sortId += 1;
parent = parent.ParentNavigation;
}
GetFileItemResponse response = new GetFileItemResponse()
{
FileItem = entity,
DirectoryPath = path
};

return Ok(response);
}

// TODO: put more individual Requests here
}

0 comments on commit ff94487

Please sign in to comment.