Spaces:
Runtime error
Runtime error
Download TaskTrackingSystem.WebApi/Features/Issue/IssueController.cs from Yuruyuruu/task-tracking-system: direct link, hf CLI and curl.
- Browser
- Download file 4.52 kB
-
https://huggingface.co/spaces/Yuruyuruu/task-tracking-system/resolve/main/TaskTrackingSystem.WebApi/Features/Issue/IssueController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/task-tracking-system/TaskTrackingSystem.WebApi/Features/Issue/IssueController.cs
-
curl -L -o IssueController.cs https://huggingface.co/spaces/Yuruyuruu/task-tracking-system/resolve/main/TaskTrackingSystem.WebApi/Features/Issue/IssueController.cs
4.52 kB
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Http; | |
| using Microsoft.AspNetCore.Mvc; | |
| using System.Collections.Generic; | |
| using System.Threading.Tasks; | |
| using TaskTrackingSystem.Shared; | |
| using TaskTrackingSystem.Shared.Enums; | |
| using TaskTrackingSystem.Shared.Models.Issue; | |
| using TaskTrackingSystem.WebApi.Infrastructure; | |
| namespace TaskTrackingSystem.WebApi.Features.Issue | |
| { | |
| [] | |
| [] | |
| [] | |
| public class IssueController : ControllerBase | |
| { | |
| private readonly IssueService _issueService; | |
| private readonly PermissionAuthorizationService _permissionAuthorizationService; | |
| public IssueController(IssueService issueService, PermissionAuthorizationService permissionAuthorizationService) | |
| { | |
| _issueService = issueService; | |
| _permissionAuthorizationService = permissionAuthorizationService; | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult> GetIssues( | |
| [FromQuery] string? search, | |
| [FromQuery] long? taskId, | |
| [FromQuery] long? projectId, | |
| [FromQuery] AppTaskStatus? statusId, | |
| [FromQuery] TaskPriority? priorityId, | |
| [FromQuery] bool assignedOnly = false, | |
| [FromQuery] PaginationQuery? paging = null) | |
| { | |
| if (paging == null || (!paging.Page.HasValue && !paging.Limit.HasValue)) | |
| { | |
| var issues = await _issueService.GetAllIssuesAsync(User.GetRoleId(), User.GetUserId()); | |
| return Ok(issues); | |
| } | |
| var page = PaginationExtensions.NormalizePage(paging.Page); | |
| var limit = PaginationExtensions.NormalizePageSize(paging.Limit ?? 0); | |
| var paged = await _issueService.GetPagedIssuesAsync( | |
| User.GetRoleId(), | |
| User.GetUserId(), | |
| search, | |
| taskId, | |
| projectId, | |
| statusId, | |
| priorityId, | |
| assignedOnly, | |
| page, | |
| limit); | |
| return Ok(paged); | |
| } | |
| [] | |
| public async Task<ActionResult<IssueDto>> GetIssue(long id) | |
| { | |
| var issue = await _issueService.GetIssueByIdAsync(id, User.GetRoleId(), User.GetUserId()); | |
| if (issue == null) | |
| { | |
| return NotFound(new { message = $"Issue with ID {id} not found." }); | |
| } | |
| return Ok(issue); | |
| } | |
| [] | |
| public async Task<ActionResult<IEnumerable<IssueDto>>> GetIssuesByTask(long taskId) | |
| { | |
| var issues = await _issueService.GetIssuesByTaskIdAsync(taskId, User.GetRoleId(), User.GetUserId()); | |
| return Ok(issues); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<IssueDto>>> CreateIssue([FromBody] CreateIssueDto dto) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Issue", "Create")) | |
| { | |
| return StatusCode(403, Result<IssueDto>.Failure("You do not have permission to create issues.", 403)); | |
| } | |
| var result = await _issueService.CreateIssueAsync(dto, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<ActionResult<Result>> UpdateIssue(long id, [FromBody] UpdateIssueDto dto) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Issue", "Update")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to update issues.", 403)); | |
| } | |
| var result = await _issueService.UpdateIssueAsync(id, dto, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| [] | |
| public async Task<ActionResult<Result>> DeleteIssue(long id) | |
| { | |
| if (!await _permissionAuthorizationService.CanAccessAsync(User, "api/Issue", "Delete")) | |
| { | |
| return StatusCode(403, Result.Failure("You do not have permission to delete issues.", 403)); | |
| } | |
| var result = await _issueService.SoftDeleteIssueAsync(id, User.GetRoleId(), User.GetUserId()); | |
| return StatusCode(result.StatusCode, result); | |
| } | |
| } | |
| } | |