public async Task UpdateMovieReturnsUpdatedMovieRankValue() { const int userId = 4; const string movieName = "Test-UpdateMovie"; const int ranking = 10; await AddMovieRankData(userId, movieName); var updateMovie = new MovieUpdateRequest { MovieName = movieName, Ranking = ranking }; var json = JsonConvert.SerializeObject(updateMovie); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); await _sut.Client.PatchAsync($"movies/{userId}", stringContent); var response = await _sut.Client.GetAsync($"movies/{userId}/{movieName}"); MovieResponse result; using (var content = response.Content.ReadAsStringAsync()) { result = JsonConvert.DeserializeObject <MovieResponse>(await content); } Assert.Equal(ranking, result.Ranking); }
public MovieUpdateResponse UpdateMovie(MovieUpdateRequest movieUpdateRequest) { try { var session = GetSession(_appConfiguration.MovieService.api_key); IRestClient restClient = new RestClient(_appConfiguration.MovieService.api_endpoint); var request = new RestRequest("/3/movie/" + movieUpdateRequest.MovieId + "/rating", Method.POST); request.AddQueryParameter("api_key", _appConfiguration.MovieService.api_key); request.AddQueryParameter("guest_session_id", session.guest_session_id); request.RequestFormat = DataFormat.Json; request.AddJsonBody(new { value = movieUpdateRequest.Vote }); var response = restClient.Post <MovieUpdateResponse>(request); if (response.Data != null & response.Data.success) { new FileManager(_appConfiguration.FilePath).AppendToFile <VoteData>( new VoteData { Vote = movieUpdateRequest.Vote, Comment = movieUpdateRequest.Note, MovieId = movieUpdateRequest.MovieId, Key = session.guest_session_id }); } return(response.Data); } catch (Exception) { throw; } }
public async Task UpdateMovie(int userId, MovieUpdateRequest request) { var response = await _movieRankRepository.GetMovie(userId, request.MovieName); var movieDb = _mapper.ToMovieDbModel(userId, response, request); await _movieRankRepository.UpdateMovie(movieDb); }
public async Task UpdateMovie(int userId, MovieUpdateRequest updateRequest) { var request = new UpdateItemRequest { TableName = TableName, Key = new Dictionary <string, AttributeValue> { { "UserId", new AttributeValue { N = userId.ToString() } }, { "MovieName", new AttributeValue { S = updateRequest.MovieName } } }, AttributeUpdates = new Dictionary <string, AttributeValueUpdate> { { "Ranking", new AttributeValueUpdate { Action = AttributeAction.PUT, Value = new AttributeValue { N = updateRequest.Ranking.ToString() } } }, { "RankedDateTime", new AttributeValueUpdate { Action = AttributeAction.PUT, Value = new AttributeValue { S = DateTime.UtcNow.ToString() } } } } }; await _dynamoDbClient.UpdateItemAsync(request); }
public async Task <IActionResult> UpdateMovie(int userId, [FromBody] MovieUpdateRequest movieUpdateRequest) { await _movieRankService.UpdateMovie(userId, movieUpdateRequest); return(Ok()); }
/// <summary> /// Add new entity /// </summary> public async Task UpdateMovie(int userID, MovieUpdateRequest newDetails) { var movie = await GetMovie(userID, newDetails.MovieName); movie.Ranking = newDetails.Ranking; await _context.SaveAsync <MovieDb>(movie); }
public async Task UpdateMovie(int userId, MovieUpdateRequest movieUpdateRequest, MovieResponse movieResponse, CancellationToken cancellationToken) { var documentFromDb = _documentMapper.FromMovieResponseToDbModel(movieResponse, userId); var document = _documentMapper.ToUpdateMovieDbModel(userId, movieUpdateRequest, documentFromDb); await _table.UpdateItemAsync(document, cancellationToken); }
public async Task UpdateMovie(int userId, MovieUpdateRequest movieUpdateRequest, MovieResponse movieResponse, CancellationToken cancellationToken) { var movieResponseToDbModel = _mapper.FromMovieResponseToDbModel(movieResponse, userId); var request = _mapper.ToUpdateMovieDbModel(userId, movieUpdateRequest, movieResponseToDbModel); await _dynamoDbContext.SaveAsync(request, cancellationToken); }
public async Task <MovieResponse> UpdatePartial(MovieUpdateRequest movieToPatch, Movie movieFromDatabase) { _mapper.Map(movieToPatch, movieFromDatabase); await _movieRepository.Update(_mapper.Map <Movie>(movieFromDatabase)); return(_mapper.Map <MovieResponse>(movieFromDatabase)); }
public async Task UpdateMovie(int userId, MovieUpdateRequest movieUpdateRequest) { var movieResponse = await GetMovie(userId, movieUpdateRequest.MovieName); var documentModel = _map.ToDocumentModel(userId, movieResponse, movieUpdateRequest); await _movieRankRepository.UpdateMovie(documentModel); }
public async Task UpdateMovie(int userId, MovieUpdateRequest updateRequest) { var movieDb = await _repository.GetMovie(userId, updateRequest.MovieName); if (movieDb != null) { var movieToBeUpdated = _mapper.ToMovieDbModel(userId, movieDb, updateRequest); await _repository.UpdateMovie(movieToBeUpdated); } }
public MovieDb ToMovieDbModel(int userId, MovieDb movie, MovieUpdateRequest movieUpdateRequest) { return(new MovieDb { UserId = userId, MovieName = movie.MovieName, Description = movie.Description, Actors = movie.Actors, Ranking = movieUpdateRequest.Ranking, RankedDateTime = DateTime.UtcNow.ToString() }); }
public MovieUpdateRequestHandlerTests() { var fixture = new Fixture(); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _commandDispatcher = new Mock <ICommandDispatcher>(); _testRequest = fixture.Create <MovieUpdateRequest>(); _handler = new MovieUpdateRequestHandler(_commandDispatcher.Object); }
public Document ToDocumentModel(int userId, MovieResponse movieResponse, MovieUpdateRequest movieUpdateRequest) { return(new Document { ["UserId"] = userId, ["MovieName"] = movieResponse.MovieName, ["Description"] = movieResponse.Description, ["Actors"] = movieResponse.Actors, ["Ranking"] = movieUpdateRequest.Ranking, ["RankedDateTime"] = DateTime.UtcNow.ToString(), }); }
public async Task UpdateMovie(int userId, MovieUpdateRequest request) { /* * var response = await GetMovie(userId, request.MovieName); * * //var movieDb = _map.ToMovieDbModel(userId, response, request); * var movieDb = _map.ToDocumentModel(userId, response, request); * * await _movieRankRepository.UpdateMovie(movieDb); */ await _movieRankRepository.UpdateMovie(userId, request); }
public MovieDb ToMovieDbModel(int userId, MovieDb current, MovieUpdateRequest updated) { return(new MovieDb { UserId = userId, MovieName = current.MovieName, Description = current.Description, Actors = current.Actors, Ranking = updated.Ranking, RankedDateTime = DateTime.UtcNow.ToString() }); }
public async Task <IActionResult> Update(int id, [FromBody] MovieUpdateRequest request) { try { var movie = await _movieService.Update(id, request); return(Ok(movie)); } catch (MovieNotFound) { return(NotFound()); } }
public void UpdateById(MovieUpdateRequest model) { _baseService.SqlAdapter.ExecuteQuery(new DbCommandDef { DbCommandText = "dbo.Movies_UpdateById", DbCommandType = System.Data.CommandType.StoredProcedure, DbParameters = new SqlParameter[] { new SqlParameter("@Id", model.Id), new SqlParameter("@Title", model.Title), new SqlParameter("@Genre", model.Genre) } }); }
public async Task <MovieResponse> Update(int id, MovieUpdateRequest request) { var movieToUpdate = await _movieRepository.GetById(id); if (movieToUpdate == null) { throw new MovieNotFound(); } _mapper.Map(request, movieToUpdate); var movie = await _movieRepository.Update(movieToUpdate); return(_mapper.Map <MovieResponse>(movie)); }
public async Task UpdateMovie(int userId, string movieName, MovieUpdateRankingRequest movieUpdateRankingRequest, CancellationToken cancellationToken) { var movieResponse = await _movieRankRepository.GetMovie(userId, movieName, cancellationToken); if (movieResponse == null) { throw new InvalidOperationException($"Invalid userId/MovieName : {userId}/{movieName}"); } var movieUpdateRequest = new MovieUpdateRequest { Ranking = movieUpdateRankingRequest.Ranking, MovieName = movieName }; await _movieRankRepository.UpdateMovie(userId, movieUpdateRequest, movieResponse, cancellationToken); }
public async Task <bool> UpdateMovie(MovieUpdateRequest request) { var movie = await MovieRepo .GetAll() .FirstOrDefaultAsync(m => m.Id == request.Id); if (movie == null) { return(false); } Mapper.Map(request, movie); MovieRepo.Update(movie); await MovieRepo.SaveChangesAsync(); return(true); }
public IActionResult UpdateMovie([FromBody] MovieUpdateRequest updateRequest) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } return(Ok(_movieService.UpdateMovie(updateRequest))); } catch (System.Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task <IActionResult> UpdateMovie([FromForm] MovieUpdateRequest request) { var movie = await MovieService.GetMovie(request.Id, true); if (movie == null) { return(NotFound(ApiResponse.Failure("Movie", $"Movie with id: {request.Id} does not exist"))); } if (request.RemovedImages?.Any() ?? false) { var imageUrls = await ImageService.RemoveMovieImages(request.RemovedImages); var removed = DeleteImagesService.DeleteImages(imageUrls); } var imagesToUpload = new List <ImageUpRequest>(); if (request.NewImages?.Any() ?? false) { var imgsAdded = request.NewImages .Select(i => new ImageUpRequest { Image = i, ImageType = MovieImageType.Image }).ToList(); imagesToUpload.AddRange(imgsAdded); } if (request.NewCover?.Length > 0) { imagesToUpload.Add(new ImageUpRequest { Image = request.NewCover, ImageType = MovieImageType.Cover }); } if (imagesToUpload.Any()) { var uploadedImages = await UploadService.UploadImages(imagesToUpload); await ImageService.AddMovieImages(uploadedImages, movie.Id); } await MovieService.UpdateMovie(request); return(Ok(ApiResponse.Success())); }
public async Task UpdateMovie(int userId, MovieUpdateRequest movieUpdateRequest, MovieResponse movieResponse, CancellationToken cancellationToken) { var request = new UpdateItemRequest //build an object UpdateItemRequest (from amazon sdk) to update the DynamoDB table //(update a ranking for user and movie) { TableName = TableName, Key = new Dictionary <string, AttributeValue> { //use the partition key (i.e. UserId) and sort key (i.e. MovieName) to locate the object in DynamoDB table. { "UserId", new AttributeValue { N = userId.ToString() } }, { "MovieName", new AttributeValue { S = movieUpdateRequest.MovieName } } }, //set the properties to update (i.e. Ranking and RankedDateTime) AttributeUpdates = new Dictionary <string, AttributeValueUpdate> { { "Ranking", new AttributeValueUpdate { //Pass in the action to perform Action = AttributeAction.PUT, Value = new AttributeValue { N = movieUpdateRequest.Ranking.ToString() } } }, { "RankedDateTime", new AttributeValueUpdate { //Pass in the action to perform Action = AttributeAction.PUT, Value = new AttributeValue { S = DateTime.UtcNow.ToString() } } } } }; await _amazonDynamoDbClient.UpdateItemAsync(request, cancellationToken); }
public Document ToUpdateMovieDbModel(int userId, MovieUpdateRequest movieUpdateRequest, Document document) { return(new Document {
public async Task UpdateMovieAsync(int userId, MovieUpdateRequest request) { await movieRankRepository.UpdateMovieAsync(userId, request); }