fix(API): added GetAll method to Folder Repository and controller

This commit is contained in:
REDCODE
2024-11-19 02:44:27 +01:00
parent c27f0d4f4f
commit ec100eb364
3 changed files with 21 additions and 1 deletions

View File

@@ -34,6 +34,19 @@ public class FolderController(
return Ok();
}
[HttpGet]
[Authorize(Roles = "Admin")]
public ActionResult<List<FolderFullDto>> GetAll() {
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
return Ok(
folderRepository.GetAll()
.Select(folder => folder.ToFolderDto())
.ToList()
);
}
[HttpGet("{id}")]
[Authorize(Roles = "Admin")]
public ActionResult<FolderFullDto> Get([FromRoute] Guid id) {

View File

@@ -23,4 +23,6 @@ public class FolderRepository(LactoseDbContext context) : IFolderRepository {
}
public Folder? Get(Guid id) => context.Folders.Find(id);
public IEnumerable<Folder> GetAll() => context.Folders;
}

View File

@@ -31,4 +31,9 @@ public interface IFolderRepository {
/// <param name="id">The ID of the folder to retrieve.</param>
/// <returns>The folder with the specified ID.</returns>
Folder? Get(Guid id);
}
/// <summary>
/// Retrieves all folders.
/// </summary>
IEnumerable<Folder> GetAll();
}