public ActionResult findUserCreatedCustomizedProducts([FromHeader(Name = "UserToken")] string userAuthToken) { if (userAuthToken == null) { return(BadRequest(new SimpleJSONMessageService(MISSING_USER_TOKEN))); } try { FindUserCreatedCustomizedProductsModelView userCreatedCustomizedProductsModelView = new FindUserCreatedCustomizedProductsModelView(); userCreatedCustomizedProductsModelView.userAuthToken = userAuthToken; GetAllCustomizedProductsModelView allCustomizedProductsCreatedByUser = new core.application.CustomizedProductController() .findUserCreatedCustomizedProducts(userCreatedCustomizedProductsModelView); return(Ok(allCustomizedProductsCreatedByUser)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Retrieves all the instances of CustomizedProduct created by a given user. /// </summary> /// <returns>An instance of GetAllCustomizedProductsModelView representing the CustomizedProducts created by the user.</returns> /// <exceptions cref="ResourceNotFoundException">Thrown when no instance of CustomizeProduct was found.</exception> public GetAllCustomizedProductsModelView findUserCreatedCustomizedProducts(FindUserCreatedCustomizedProductsModelView findUserCreatedCustomizedProductsModelView) { IEnumerable <CustomizedProduct> userCreatedCustomizedProducts = PersistenceContext.repositories().createCustomizedProductRepository() .findUserCreatedCustomizedProducts(findUserCreatedCustomizedProductsModelView.userAuthToken); if (!userCreatedCustomizedProducts.Any()) { throw new ResourceNotFoundException(ERROR_NO_CUSTOMIZED_PRODUCTS_FOUND); } return(CustomizedProductModelViewService.fromCollection(userCreatedCustomizedProducts)); }