fix(API): added GetAll method to Folder Repository and controller
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user