Exemplo n.º 1
0
        public async Task <IUseCaseResult <UserPlantResponseDto> > GetUserPlantAsync(string userPlantId)
        {
            // get user plant
            var userPlant = await _userPlantService.GetUserPlantAsync(userPlantId);

            if (userPlant == null)
            {
                return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.UserPlantNotFound));
            }

            // get plant
            var plant = await _plantService.GetPlantAsync(userPlant.PlantId);

            if (userPlant == null)
            {
                return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.PlantNotFound));
            }

            // get user
            var user = await _userService.GetUserByIdAsync(userPlant.UserId);

            if (userPlant == null)
            {
                return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.UserNotFound));
            }

            // combine the data
            var userPlantResponseDto = new UserPlantResponseDto
            {
                Id       = userPlant.Id,
                PlantId  = userPlant.PlantId,
                UserId   = userPlant.UserId,
                Nickname = userPlant.Nickname,
                Plant    = plant,
                User     = user
            };

            return(UseCase.Success(userPlantResponseDto));
        }