public async Task <ActionResult <HateoasResponse> > GetAllExercisesByCategory(Guid categoryId, int index, int size) { try { GetExercisesByCategoryQuery query = new(categoryId, index, size); var exercises = await _mediator.Send(query); return(Ok(_sender.SendResult(exercises, GenericLinks.GetExerciseLinks(), $"The exercises whose category id is {categoryId} have been reached!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > CreateExercise([FromForm] CreateExerciseRequest model) { try { CreateExerciseCommand command = new(model); var exercise = await _mediator.Send(command); return(Ok(_sender.SendResult(exercise, GenericLinks.GetExerciseLinks(), $"The exercise whose name is {exercise.ExerciseName} has been created!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > DeleteExercise(Guid id) { try { DeleteExerciseCommand command = new(id); var exerciseDeleted = new { DeletedExerciseId = await _mediator.Send(command) }; return(Ok(_sender.SendResult(exerciseDeleted, GenericLinks.GetExerciseLinks(), $"The exercise whose id is {exerciseDeleted.DeletedExerciseId} has been deleted!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > GetIndexesCount(Guid categoryId, int size) { try { GetIndexesCount query = new(categoryId, size); var count = new { Count = await _mediator.Send(query) }; return(Ok(_sender.SendResult(count, GenericLinks.GetExerciseLinks(), "The exercise count with that specific category has been reached!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > GetExercisesNameAndIdByCategory(Guid categoryId) { try { GetExercisesNameAndIdByCategoryQuery query = new(categoryId); var result = await _mediator.Send(query); return(Ok(_sender.SendResult(result, GenericLinks.GetExerciseLinks(), "The exercise count with that specific category has been reached!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetExerciseLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > SetDone(SetDoneRequest request) { try { SetDoneCommand command = new(request); bool result = await _mediator.Send(command); return(Ok(_sender.SendResult(new { SetDoneCreated = result }, GenericLinks.GetRoutineLinks(), "The set done has been registered!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > RemoveExerciseFromRoutine(Guid id) { try { RemoveExerciseFromRoutineCommand command = new(id); bool result = await _mediator.Send(command); return(Ok(_sender.SendResult(new { ExerciseRemoved = result }, GenericLinks.GetRoutineLinks(), "The exercise has been removed!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > AddExerciseToRoutine(AddExerciseToRoutineRequest request) { try { AddExerciseToRoutineCommand command = new(request); bool result = await _mediator.Send(command); return(Ok(_sender.SendResult(new { ExerciseCreated = result }, GenericLinks.GetRoutineLinks(), "The exercise has been added to your Routine!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > GetAllCategories() { try { GetAllCategoriesQuery query = new(); var categories = await _mediator.Send(query); return(Ok(_sender.SendResult(categories, GenericLinks.GetCategoryLinks(), "The categories have been achieved!"))); } catch (Exception ex) { var result = _sender.SendError(ex, GenericLinks.GetCategoryLinks()); Response.StatusCode = result.StatusCode; return(result); } }
public async Task <ActionResult <HateoasResponse> > CreateCategory(CreateCategoryRequest model) { try { CreateCategoryCommand command = new(model); var categoryDto = await _mediator.Send(command); return(Ok(_sender.SendResult(categoryDto, GenericLinks.GetCategoryLinks(), $"The category whose name is {categoryDto.CategoryName} has been created!"))); } catch (Exception ex) { var result = _sender.SendError(ex, GenericLinks.GetCategoryLinks()); Response.StatusCode = result.StatusCode; return(result); } }
public async Task <ActionResult <HateoasResponse> > GetExerciseStatistics(Guid exerciseId, int month, int year) { try { GetExerciseStatisticsQuery query = new(exerciseId : exerciseId, month : month, year : year); var result = await _mediator.Send(query); return(Ok(_sender.SendResult(result, GenericLinks.GetStatisticsLinks(), "The exercise statistics have been reached!"))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetStatisticsLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }
public async Task <ActionResult <HateoasResponse> > GetExerciseToDo() { try { GetExerciseToDoQuery query = new (); var result = await _mediator.Send(query); string message = (result is not null) ? $"You have to do the {result.Name}" : "You are done for today, go and get some rest!"; return(Ok(_sender.SendResult(result, GenericLinks.GetRoutineLinks(), message))); } catch (Exception ex) { var errorResponse = _sender.SendError(ex, GenericLinks.GetRoutineLinks()); Response.StatusCode = errorResponse.StatusCode; return(errorResponse); } }