Spaces:
Runtime error
Runtime error
Download TaskTrackingSystem.WebApi/Features/Project/ProjectController.cs from Yuruyuruu/task-tracking-system: direct link, hf CLI and curl.
- Browser
- Download file 6.11 kB
-
https://huggingface.co/spaces/Yuruyuruu/task-tracking-system/resolve/main/TaskTrackingSystem.WebApi/Features/Project/ProjectController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/task-tracking-system/TaskTrackingSystem.WebApi/Features/Project/ProjectController.cs
-
curl -L -o ProjectController.cs https://huggingface.co/spaces/Yuruyuruu/task-tracking-system/resolve/main/TaskTrackingSystem.WebApi/Features/Project/ProjectController.cs
6.11 kB
| using Microsoft.AspNetCore.Mvc; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Http; | |
| using TaskTrackingSystem.Shared; | |
| using TaskTrackingSystem.Shared.Models.User; | |
| using TaskTrackingSystem.Shared.Models.Task; | |
| using TaskTrackingSystem.Shared.Models.Project; | |
| using TaskTrackingSystem.WebApi.Infrastructure; | |
| namespace TaskTrackingSystem.WebApi.Features.Project | |
| { | |
| [] | |
| [] | |
| [] | |
| public class ProjectController : ControllerBase | |
| { | |
| private readonly ProjectService _projectService; | |
| private readonly PermissionAuthorizationService _permissionAuthorizationService; | |
| public ProjectController(ProjectService projectService, PermissionAuthorizationService permissionAuthorizationService) | |
| { | |
| _projectService = projectService; | |
| _permissionAuthorizationService = permissionAuthorizationService; | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult> GetProjects( | |
| [FromQuery] string? search, | |
| [FromQuery] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var projects = await _projectService.GetAllProjectsAsync(User.GetRoleId(), User.GetUserId()); | |
| return Ok(projects); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging.Limit ?? 0); | |
| var paged = await _projectService.GetPagedProjectsAsync(User.GetRoleId(), User.GetUserId(), search, page, limit); | |
| return Ok(paged); | |
| } | |
| [] | |
| public async Task<ActionResult<ProjectDto>> GetProject(long id) | |
| { | |
| var project = await _projectService.GetProjectByIdAsync(id, User.GetRoleId(), User.GetUserId()); | |
| if (project == null) | |
| { | |
| return NotFound(new { message = $"Project with ID {id} not found." }); | |
| } | |
| return Ok(project); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<ProjectDto>>> CreateProject([FromBody] CreateProjectDto createProjectDto) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Project", "Create")) | |
| { | |
| return StatusCode(403, Result<ProjectDto>.Failure("You do not have permission to create projects.", 403)); | |
| } | |
| long? currentUserId = User.GetUserId(); | |
| var result = await _projectService.CreateProjectAsync(createProjectDto, currentUserId); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<ActionResult<Result>> UpdateProject(long id, [FromBody] UpdateProjectDto updateProjectDto) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Project", "Update")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to update projects.", 403)); | |
| } | |
| var currentUserId = User.GetUserId(); | |
| var result = await _projectService.UpdateProjectAsync(id, updateProjectDto, User.GetRoleId(), currentUserId); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<ActionResult<Result>> DeleteProject(long id) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Project", "Delete")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to delete projects.", 403)); | |
| } | |
| var result = await _projectService.SoftDeleteProjectAsync(id, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<IEnumerable<UserDto>>>> GetProjectMembers(long id) | |
| { | |
| var result = await _projectService.GetProjectMembersAsync(id, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<IActionResult> AssignProjectMembers(long id, [FromBody] AssignMembersDto dto) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Project", "Update")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to assign project members.", 403)); | |
| } | |
| var result = await _projectService.AssignMembersToProjectAsync(id, dto, User.GetRoleId(), User.GetUserId()); | |
| if (!result.IsSuccess) | |
| { | |
| return StatusCode(result.StatusCode, new { message = result.ErrorMessage }); | |
| } | |
| return Ok(); | |
| } | |
| [] | |
| public async Task<IActionResult> RemoveProjectMember(long id, long userId) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Project", "Update")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to update project members.", 403)); | |
| } | |
| var result = await _projectService.RemoveMemberFromProjectAsync(id, userId, User.GetRoleId(), User.GetUserId()); | |
| if (!result.IsSuccess) | |
| { | |
| return StatusCode(result.StatusCode, new { message = result.ErrorMessage }); | |
| } | |
| return NoContent(); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<IEnumerable<TaskDto>>>> GetProjectTasks(long id) | |
| { | |
| var result = await _projectService.GetProjectTasksAsync(id, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| } | |
| } | |