Skip to content

Commit

Permalink
Added todo complete api endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
mak-thevar committed Oct 7, 2023
1 parent 86043b2 commit 9dba1cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion CoreWebApiBoilerPlate/Controllers/TodosController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TodosController(IMapper mapper, IRepositoryWrapper repository)
[ProducesResponseType(200, Type = typeof(ApiResponseModel<List<TodoResponseModel>>))]
public async Task<IActionResult> Get()
{
var result = await this.repository.TodoRepository.GetAllAsync("Comments", "CreatedBy");
var result = await this.repository.TodoRepository.GetAllAsync("Comments", "CreatedBy","TodoStatus");
var response = mapper.Map<IReadOnlyList<TodoResponseModel>>(result);
return CreateSuccessResponse(response);
}
Expand Down Expand Up @@ -97,5 +97,16 @@ public async Task<IActionResult> AddComment(int id,CommentRequestModel requestMo
}

}

[HttpPost("completed/{id}")]
public async Task<IActionResult> Completed(int id)
{
var result = await this.repository.TodoRepository.GetByIdAsync(id);
if (result is null)
return CreateErrorResponse(System.Net.HttpStatusCode.NotFound, new List<string> { "Not found"});
result.TodoStatusId = 3;
await this.repository.SaveAsync();
return CreateSuccessResponse(result);
}
}
}
4 changes: 3 additions & 1 deletion CoreWebApiBoilerPlate/Infrastructure/AutoMapperProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public AutoMapperProfile()
.ForMember(x => x.CreatedById, opt => opt.MapFrom(src => Constants.CurrentUserId))
.ForMember(x => x.IsActive, opt => opt.MapFrom(src => true));

CreateMap<Todo, TodoResponseModel>();
CreateMap<Todo, TodoResponseModel>()
.ForMember(x => x.TodoStatus, opt => opt.MapFrom(src => src.TodoStatus != null ? src.TodoStatus.Description : ""));

CreateMap<Comment, CommentResponseModel>();

CreateMap<CommentRequestModel, Comment>()
Expand Down

0 comments on commit 9dba1cf

Please sign in to comment.