示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#4
0
        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());
        }
示例#6
0
        /// <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);
        }
示例#7
0
 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);
        }
示例#9
0
        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));
        }
示例#10
0
        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);
        }
示例#11
0
        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);
            }
        }
示例#12
0
 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);
        }
示例#14
0
 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);
 }
示例#16
0
 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()
     });
 }
示例#17
0
        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)
         }
     });
 }
示例#19
0
        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));
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        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));
            }
        }
示例#23
0
        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()));
        }
示例#24
0
        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);
        }
示例#25
0
 public Document ToUpdateMovieDbModel(int userId, MovieUpdateRequest movieUpdateRequest, Document document)
 {
     return(new Document
     {
示例#26
0
 public async Task UpdateMovieAsync(int userId, MovieUpdateRequest request)
 {
     await movieRankRepository.UpdateMovieAsync(userId, request);
 }