Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: task details feature #20

Merged
merged 19 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using DotnetFoundation.Application.DTO.TaskDetailsDTO;
using DotnetFoundation.Application.Interfaces.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DotnetFoundation.Api.Controllers;

[ApiController]
[Route("api/tasks")]
public class TaskDetailsController : ControllerBase
kshitij-k-osmosys marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly ITaskDetailsService _TaskDetailsService;
public TaskDetailsController(ITaskDetailsService TaskDetailsService)
{
_TaskDetailsService = TaskDetailsService;
}

[HttpGet("all")]
[Authorize]
public async Task<IActionResult> GetAllTasksAsync()
{
List<TaskDetailsResponse> result = await _TaskDetailsService.GetAllTasksAsync().ConfigureAwait(false);
return Ok(result);
}

[HttpGet("{taskId}")]
[Authorize]
public async Task<IActionResult> GetTaskByIdAsync(int taskId)
{
TaskDetailsResponse? result = await _TaskDetailsService.GetTaskByIdAsync(taskId).ConfigureAwait(false);
return Ok(result);
}

[HttpPost("insert")]
[Authorize]
public async Task<IActionResult> InsertTaskAsync(TaskDetailsRequest detailRequest)
{
string result = await _TaskDetailsService.InsertTaskAsync(detailRequest).ConfigureAwait(false);
return Ok(result);
}

[HttpPut("update/{taskId}")]
[Authorize]
public async Task<IActionResult> UpdateTaskAsync(int taskId, TaskDetailsRequest modifiedDetails)
{
string result = await _TaskDetailsService.UpdateTaskAsync(taskId, modifiedDetails).ConfigureAwait(false);
return Ok(result);
}

[HttpDelete("delete/{taskId}")]
[Authorize]
public async Task<IActionResult> DeleteTaskAsync(int taskId)
{
string result = await _TaskDetailsService.DeleteTaskAsync(taskId).ConfigureAwait(false);
return Ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DotnetFoundation.Application.DTO.TaskDetailsDTO;

public record TaskDetailsRequest(
string Description,
int BudgetedHours,
int AssignedTo,
string? Category
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DotnetFoundation.Domain.Entities;
namespace DotnetFoundation.Application.DTO.TaskDetailsDTO;

public record TaskDetailsResponse(
// TaskDetails taskDetailsRecord
int Id,
string Description,
int BudgetedHours,
int AssignedTo,
string? Category,
StatusEnum Status,
DateTime CreatedOn,
int CreatedBy,
DateTime ModifiedOn,
int ModifiedBy
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace DotnetFoundation.Application;
using DotnetFoundation.Application.Services.Authentication;
using DotnetFoundation.Application.Services.EmailService;
using DotnetFoundation.Application.Services.UserService;
using DotnetFoundation.Application.Services.TaskDetailsService;
using Microsoft.Extensions.DependencyInjection;
public static class DependencyInjection
{
Expand All @@ -12,6 +13,7 @@ public static IServiceCollection AddApplication(this IServiceCollection services
services.AddScoped<IAuthenticationService, AuthenticationService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IEmailService, EmailService>();
services.AddScoped<ITaskDetailsService, TaskDetailsService>();
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DotnetFoundation.Application.DTO.TaskDetailsDTO;
using DotnetFoundation.Domain.Entities;

namespace DotnetFoundation.Application.Interfaces.Persistence;

/// <summary>
/// Represents the repository interface for handling task related operations.
/// </summary>
public interface ITaskDetailsRepository
{
public Task<List<TaskDetails>> GetAllTasksAsync();
public Task<TaskDetails?> GetTaskByIdAsync(int Id);
public Task<string> InsertTaskAsync(TaskDetailsRequest request);
public Task<string> UpdateTaskAsync(int id, TaskDetailsRequest modifiedDetails);
public Task<string> DeleteTaskAsync(int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using DotnetFoundation.Application.DTO.TaskDetailsDTO;
namespace DotnetFoundation.Application.Interfaces.Services;

/// <summary>
/// Provides functionality for task related operations.
/// </summary>
public interface ITaskDetailsService
{
public Task<List<TaskDetailsResponse>> GetAllTasksAsync();
public Task<TaskDetailsResponse?> GetTaskByIdAsync(int id);
public Task<string> InsertTaskAsync(TaskDetailsRequest request);
public Task<string> UpdateTaskAsync(int id, TaskDetailsRequest modifiedDetails);
public Task<string> DeleteTaskAsync(int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using DotnetFoundation.Application.DTO.TaskDetailsDTO;
using DotnetFoundation.Application.Interfaces.Persistence;
using DotnetFoundation.Application.Interfaces.Services;
using DotnetFoundation.Domain.Entities;
using System.Security.Claims;

namespace DotnetFoundation.Application.Services.TaskDetailsService;

public class TaskDetailsService : ITaskDetailsService
{
private readonly ITaskDetailsRepository _taskDetailsRepository;
public TaskDetailsService(ITaskDetailsRepository taskDetailsRepository)
{
_taskDetailsRepository = taskDetailsRepository;
}

private static TaskDetailsResponse TaskDTOMapper(TaskDetails details)
{
return new(
Id: details.Id,
Description: details.Description,
BudgetedHours: details.BudgetedHours,
AssignedTo: details.AssignedTo,
Category: details.Category,
Status: details.Status,
CreatedOn: details.CreatedOn,
CreatedBy: details.CreatedBy,
ModifiedOn: details.ModifiedOn,
ModifiedBy: details.ModifiedBy
);
}

public async Task<List<TaskDetailsResponse>> GetAllTasksAsync()
{
List<TaskDetailsResponse> response = (await _taskDetailsRepository.GetAllTasksAsync().ConfigureAwait(false)).Select(TaskDTOMapper).ToList();
return response;
}

public async Task<TaskDetailsResponse?> GetTaskByIdAsync(int id)
{
TaskDetails res = await _taskDetailsRepository.GetTaskByIdAsync(id).ConfigureAwait(false) ?? throw new Exception($"Task with Id={id} does not exist");
return TaskDTOMapper(res);
}

public async Task<string> InsertTaskAsync(TaskDetailsRequest detailsRequest)
{
try
{
string res = await _taskDetailsRepository.InsertTaskAsync(detailsRequest).ConfigureAwait(false);
return res;
}
catch (Exception ex)
{
return $"An error inserting TaskDetails: {ex.Message}";
}
}

public async Task<string> UpdateTaskAsync(int id, TaskDetailsRequest modifiedDetails)
{
try
{
string res = await _taskDetailsRepository.UpdateTaskAsync(id, modifiedDetails).ConfigureAwait(false);
return res;
}
catch (Exception ex)
{
return $"An error occurred while updating Task with id = \"{id}\": {ex.Message}";
}
}

public async Task<string> DeleteTaskAsync(int id)
{
try
{
string res = await _taskDetailsRepository.DeleteTaskAsync(id).ConfigureAwait(false);
return res;
}
catch (Exception ex)
{
return $"An error occurred while deleting Task with id = \"{id}\": {ex.Message}";
}
}
}
21 changes: 21 additions & 0 deletions DotnetFoundation/DotnetFoundation.Domain/Entities/TaskDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace DotnetFoundation.Domain.Entities;

public enum StatusEnum
{
Inactive = 0,
Active = 1
}

public class TaskDetails
{
public int Id;
public string Description { get; set; } = null!;
public int BudgetedHours { get; set; } = 0;
public int AssignedTo { get; set; }
public string? Category { get; set; }
public StatusEnum Status { get; set; } = StatusEnum.Active;
public DateTime CreatedOn { get; set; } = DateTime.UtcNow;
public int CreatedBy { get; set; }
public DateTime ModifiedOn { get; set; } = DateTime.UtcNow;
public int ModifiedBy { get; set; }
}
kshitij-k-osmosys marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using DotnetFoundation.Application.Interfaces.Persistence;
using DotnetFoundation.Application.Interfaces.Services;
using DotnetFoundation.Application.Services.TaskDetailsService;
using DotnetFoundation.Infrastructure.Identity;
using DotnetFoundation.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authentication.JwtBearer;
Expand Down Expand Up @@ -53,6 +55,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi

services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IEmailRepository, EmailRepository>();
services.AddScoped<ITaskDetailsRepository, TaskDetailsRepository>();
services.AddHttpClient();

return services;
Expand Down
Loading
Loading