Giter Site home page Giter Site logo

onlinewebmediaplayer / movieranking Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adritasharma/movieranking

0.0 0.0 0.0 3.39 MB

A Basic CRUD Operation using ASP.NET Core and DynamoDB on AWS

JavaScript 4.37% C# 53.60% TypeScript 24.09% CSS 3.82% HTML 14.12%

movieranking's Introduction

MovieRanking

A Basic ASP.NET Core Application to perform CRUD Operation with DynamoDB on AWS.

AWS DynamoDB

Amazon DynamoDB is a fast and flexible NoSQL database service. It is a fully managed database that supports both document and key-value data models.

Create a DynamoDB Table

AWS Console Steps for DynamoDB

  • Go to Service -> DynamoDB
  • Create table

Connect .NET Core Application with DynamoDB

To connect with DynamoDB, AWS Nuget Package AWSSDK.DynamoDBv2 has been used.

using (var client = new AmazonDynamoDBClient())
{
   using (var context = new DynamoDBContext(client))
   {
      await context.SaveAsync(dbModel);
   }
}

In order to use DataModel with DynamoDB, some attributes from Amazon.DynamoDBv2.DataModel like [DynamoDBTable], [DynamoDBProperty] has been added to it.

    [DynamoDBTable("MovieRank")]
    public class MovieDb
    {
        [DynamoDBHashKey]
        public int UserId { get; set; }
        [DynamoDBGlobalSecondaryIndexHashKey]
        public string MovieName { get; set; }
        public string Description { get; set; }
        public List<string> Actors { get; set; }
        public int Ranking { get; set; }
        public string RankedDateTime { get; set; }

    }

Scan and Query

To retrieve data from DynamoDBm we can use 2 options Scan and Query function.

  • Scan : Reads all item in table but comes at a cost. All items are read before the filter is applied.
     public async Task<IEnumerable<MovieDb>> GetAllItems()
     {
        return await _dbContext.ScanAsync<MovieDb>(new List<ScanCondition>()).GetRemainingAsync();
     }

  • Query : Reads items more efficiently, but we must add the Partition key and optionally the sort key to the correct attributes.
        public async Task<IEnumerable<MovieDb>> GetUserRankedMoviesByMovieTitle(int userId, string movieName)
        {
            var config = new DynamoDBOperationConfig
            {
                QueryFilter = new List<ScanCondition>
                {
                    new ScanCondition("MovieName", ScanOperator.BeginsWith, movieName)
                }
            };
            return await _dbContext.QueryAsync<MovieDb>(userId, config).GetRemainingAsync();

        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.