This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: task routes and models #26
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using AutoMapper; | ||
using DotnetFoundation.Application.Exceptions; | ||
using DotnetFoundation.Application.Interfaces.Persistence; | ||
using DotnetFoundation.Application.Interfaces.Services; | ||
using DotnetFoundation.Application.Models.DTOs.TaskDetailsDTO; | ||
|
@@ -35,15 +36,15 @@ public async Task<List<TaskDetailsResponse>> GetActiveTasksAsync() | |
|
||
public async Task<TaskDetailsResponse> GetTaskByIdAsync(int id) | ||
{ | ||
TaskDetails response = await _taskDetailsRepository.GetTaskByIdAsync(id).ConfigureAwait(false) | ||
?? throw new Exception($"Task with Id={id} does not exist"); | ||
TaskDetails response = await _taskDetailsRepository.GetTaskByIdAsync(id).ConfigureAwait(false) | ||
?? throw new NotFoundException($"Task with Id={id} does not exist"); | ||
return _mapper.Map<TaskDetailsResponse>(response); | ||
} | ||
|
||
public async Task<TaskDetailsResponse> InsertTaskAsync(TaskDetailsRequest detailsRequest) | ||
{ | ||
User? user = await _userRepository.GetUserByIdAsync(detailsRequest.AssignedTo).ConfigureAwait(false) | ||
?? throw new Exception($"AssignedTo with userId = \"{detailsRequest.AssignedTo}\" does not exist. Cannot add task."); | ||
?? throw new NotFoundException($"AssignedTo with userId = \"{detailsRequest.AssignedTo}\" does not exist. Cannot add task."); | ||
|
||
// Create new TaskDetails object and add relevant details | ||
TaskDetails taskDetails = new TaskDetails | ||
|
@@ -57,8 +58,8 @@ public async Task<TaskDetailsResponse> InsertTaskAsync(TaskDetailsRequest detail | |
ModifiedBy = detailsRequest.AssignedTo, | ||
ModifiedOn = DateTime.UtcNow, | ||
}; | ||
int? taskId = await _taskDetailsRepository.InsertTaskAsync(taskDetails).ConfigureAwait(false) | ||
|
||
int? taskId = await _taskDetailsRepository.InsertTaskAsync(taskDetails).ConfigureAwait(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of a generic Consider introducing a custom exception, such as |
||
?? throw new Exception($"Error inserting TaskDetails for \"{detailsRequest.Description}\""); | ||
|
||
taskDetails.Id = (int)taskId; | ||
|
@@ -69,10 +70,10 @@ public async Task<TaskDetailsResponse> InsertTaskAsync(TaskDetailsRequest detail | |
public async Task<TaskDetailsResponse> UpdateTaskAsync(int id, TaskDetailsRequest modifiedDetails) | ||
{ | ||
TaskDetails? existingDetails = await _taskDetailsRepository.GetTaskByIdAsync(id).ConfigureAwait(false) | ||
?? throw new Exception($"Task with Id={id} does not exist"); | ||
?? throw new NotFoundException($"Task with Id={id} does not exist"); | ||
|
||
User? user = await _userRepository.GetUserByIdAsync(modifiedDetails.AssignedTo).ConfigureAwait(false) | ||
?? throw new Exception($"AssignedTo with userId = \"{modifiedDetails.AssignedTo}\" does not exist. Cannot add task."); | ||
?? throw new NotFoundException($"AssignedTo with userId = \"{modifiedDetails.AssignedTo}\" does not exist. Cannot add task."); | ||
|
||
TaskDetails? modifiedTask = await _taskDetailsRepository.UpdateTaskAsync(modifiedDetails, existingDetails).ConfigureAwait(false) | ||
?? throw new Exception($"An error occurred while updating Task with id = \"{id}\""); | ||
|
@@ -85,7 +86,7 @@ public async Task<TaskDetailsResponse> InactiveTaskAsync(int id) | |
TaskDetails? existingDetails = await _taskDetailsRepository.GetTaskByIdAsync(id).ConfigureAwait(false); | ||
if (existingDetails == null) | ||
{ | ||
throw new Exception($"Task with Id = \"{id}\" does not exist"); | ||
throw new NotFoundException($"Task with Id = \"{id}\" does not exist"); | ||
} | ||
|
||
TaskDetails? response = await _taskDetailsRepository.InactiveTaskAsync(existingDetails).ConfigureAwait(false) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
task
endpoint for adding a new task is correctly implemented as a POST operation, which aligns with RESTful design principles for creating resources. However, it's worth noting that the singular formtask
is used here, whereas other endpoints use the plural formtasks
. While this is not incorrect, it's generally a good practice to maintain consistency in naming conventions across the API. Consider aligning this endpoint with others by using the plural formtasks
for consistency.Committable suggestion