public async Task <ActionResult <PlantLog> > CreatePlantLog(Guid plantId, CreatePlantLogForPlantRequest request) { var command = new CreatePlantLogForPlantCommand { Id = Guid.NewGuid(), PlantId = plantId, PlantLogTypeId = request.PlantLogTypeId, Log = request.Log, DateTime = request.DateTime, }; var response = await mediator.Send(command); if (!response.Success) { return(BadRequest(response.ErrorMessages)); } var createdQuery = new GetPlantLogForPlantByIdQuery { Id = command.Id, PlantId = plantId }; var createdResult = await mediator.Send(createdQuery); var createdObj = PlantLog.FromCore(createdResult.Data); return(CreatedAtRoute(nameof(PlantController) + "/" + nameof(GetPlantLog), new { plantId = command.PlantId, logId = command.Id }, createdObj)); }
public async Task <ActionResult <PlantLog> > GetPlantLog(Guid plantId, Guid logId) { var query = new GetPlantLogForPlantByIdQuery { Id = logId, PlantId = plantId }; var response = await mediator.Send(query); if (!response.Success) { return(BadRequest(response.ErrorMessages)); } return(Ok(PlantLog.FromCore(response.Data))); }