Skip to content

Commit 1e688cb

Browse files
committed
MovieRating updated
DB schema updated
1 parent 4e6da3c commit 1e688cb

10 files changed

Lines changed: 33 additions & 98 deletions

File tree

StarWars.API/AutoMapperProfile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public AutoMapperProfile()
1313
.ForMember(o => o.ID, map => map.MapFrom(o => o.ID))
1414
.ForMember(o => o.Title, map => map.MapFrom(o => o.Title))
1515
.ForMember(o => o.Year, map => map.MapFrom(o => o.Year))
16-
.ForMember(o => o.Type, map => map.MapFrom(o => o.Type))
1716
.ForMember(o => o.Poster, map => map.MapFrom(o => o.Poster))
1817
.ForMember(o => o.Price, map => map.MapFrom(o => GetRandomPrice(o.Price)))
1918
.ReverseMap();

StarWars.API/Migrations/20241024132639_Init_DB.Designer.cs renamed to StarWars.API/Migrations/20250821090823_Init_DB.Designer.cs

Lines changed: 6 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StarWars.API/Migrations/20241024132639_Init_DB.cs renamed to StarWars.API/Migrations/20250821090823_Init_DB.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#nullable disable
55

6-
namespace StarWars.Api.Migrations
6+
namespace StarWars.API.Migrations
77
{
88
/// <inheritdoc />
99
public partial class Init_DB : Migration
@@ -15,10 +15,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
1515
name: "Movie",
1616
columns: table => new
1717
{
18-
ID = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
18+
ID = table.Column<string>(type: "nvarchar(450)", nullable: false),
1919
Title = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
20-
Year = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
21-
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
20+
Year = table.Column<int>(type: "int", nullable: false),
2221
Poster = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
2322
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
2423
IsActive = table.Column<bool>(type: "bit", nullable: false),
@@ -35,20 +34,15 @@ protected override void Up(MigrationBuilder migrationBuilder)
3534
columns: table => new
3635
{
3736
ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
38-
MovieID = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
39-
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
40-
Rated = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
41-
Released = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
42-
Runtime = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
43-
Genre = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
44-
Director = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
45-
Writer = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
46-
Language = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
47-
Country = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
48-
Awards = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
37+
MovieID = table.Column<string>(type: "nvarchar(450)", nullable: false),
38+
Rated = table.Column<string>(type: "nvarchar(max)", nullable: true),
39+
Released = table.Column<DateTime>(type: "datetime2", nullable: false),
40+
Runtime = table.Column<string>(type: "nvarchar(max)", nullable: true),
41+
Genre = table.Column<string>(type: "nvarchar(max)", nullable: true),
42+
Director = table.Column<string>(type: "nvarchar(max)", nullable: true),
43+
Language = table.Column<string>(type: "nvarchar(max)", nullable: true),
4944
Metascore = table.Column<int>(type: "int", nullable: false),
5045
Rating = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
51-
Votes = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
5246
UpdatedOn = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
5347
CreatedOn = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
5448
},

StarWars.API/Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#nullable disable
1010

11-
namespace StarWars.Api.Migrations
11+
namespace StarWars.API.Migrations
1212
{
1313
[DbContext(typeof(ApplicationDbContext))]
1414
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
@@ -45,14 +45,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
4545
.HasMaxLength(100)
4646
.HasColumnType("nvarchar(100)");
4747

48-
b.Property<string>("Type")
49-
.HasColumnType("nvarchar(max)");
50-
5148
b.Property<DateTimeOffset?>("UpdatedOn")
5249
.HasColumnType("datetimeoffset");
5350

54-
b.Property<string>("Year")
55-
.HasColumnType("nvarchar(max)");
51+
b.Property<int>("Year")
52+
.HasColumnType("int");
5653

5754
b.HasKey("ID")
5855
.HasName("PK_Movie");
@@ -67,12 +64,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
6764
.HasColumnType("uniqueidentifier")
6865
.HasDefaultValueSql("NEWID()");
6966

70-
b.Property<string>("Awards")
71-
.HasColumnType("nvarchar(max)");
72-
73-
b.Property<string>("Country")
74-
.HasColumnType("nvarchar(max)");
75-
7667
b.Property<DateTimeOffset?>("CreatedOn")
7768
.HasColumnType("datetimeoffset");
7869

@@ -92,32 +83,21 @@ protected override void BuildModel(ModelBuilder modelBuilder)
9283
.IsRequired()
9384
.HasColumnType("nvarchar(450)");
9485

95-
b.Property<decimal>("Price")
96-
.HasColumnType("decimal(18,2)");
97-
9886
b.Property<string>("Rated")
9987
.HasColumnType("nvarchar(max)");
10088

10189
b.Property<decimal>("Rating")
10290
.HasColumnType("decimal(18,2)");
10391

104-
b.Property<string>("Released")
105-
.HasColumnType("nvarchar(max)");
92+
b.Property<DateTime>("Released")
93+
.HasColumnType("datetime2");
10694

10795
b.Property<string>("Runtime")
10896
.HasColumnType("nvarchar(max)");
10997

11098
b.Property<DateTimeOffset?>("UpdatedOn")
11199
.HasColumnType("datetimeoffset");
112100

113-
b.Property<string>("Votes")
114-
.IsRequired()
115-
.HasMaxLength(100)
116-
.HasColumnType("nvarchar(100)");
117-
118-
b.Property<string>("Writer")
119-
.HasColumnType("nvarchar(max)");
120-
121101
b.HasKey("ID")
122102
.HasName("PK_MovieRating");
123103

StarWars.Common/MovieFaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static List<Movie> Generate(int count, string alphabet)
4141
{
4242
var id = GenerateUniqueCode(9, alphabet);
4343
var title = GenerateMovieTitle();
44-
var year = faker.Date.Past(20).Year.ToString();
44+
var year = faker.Date.Past(20).Year;
4545
var posterUrl = faker.Image.PicsumUrl();
4646
var price = faker.Finance.Amount(5, 1000, 2);
4747

StarWars.Model/Movie.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ public class Movie : AuditableEntity
66
{
77
public string ID { get; set; }
88
public string Title { get; set; }
9-
public string Year { get; set; }
10-
public string Type { get; set; } = "Movie";
9+
public int Year { get; set; }
1110
public string Poster { get; set; }
1211
public decimal Price { get; set; }
1312
public bool IsActive { get; set; } = true;
14-
public ICollection<MovieRating> MovieRatings { get; set; } = new List<MovieRating>();
13+
public IEnumerable<MovieRating> MovieRatings { get; set; } = new List<MovieRating>();
1514
}
1615
}

StarWars.Model/MovieRating.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ public class MovieRating : AuditableEntity
66
{
77
public Guid ID { get; set; }
88
public string MovieID { get; set; }
9-
public decimal Price { get; set; }
109
public string Rated { get; set; }
11-
public string Released { get; set; }
10+
public DateTime Released { get; set; }
1211
public string Runtime { get; set; }
1312
public string Genre { get; set; }
1413
public string Director { get; set; }
15-
public string Writer { get; set; }
1614
public string Language { get; set; }
17-
public string Country { get; set; }
18-
public string Awards { get; set; }
1915
public int Metascore { get; set; }
2016
public decimal Rating { get; set; }
21-
public string Votes { get; set; }
2217
}
2318
}
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
using FluentValidation;
2+
using System;
23

34
namespace StarWars.Model.ViewModels
45
{
56
public class MovieRatingView
67
{
78
public string ID { get; set; }
8-
public string Title { get; set; }
9-
public string Year { get; set; }
10-
public string Type { get; set; }
11-
public string Poster { get; set; }
12-
public decimal Price { get; set; }
9+
public string MovieID { get; set; }
1310
public string Rated { get; set; }
14-
public string Released { get; set; }
11+
public DateTime Released { get; set; }
1512
public string Runtime { get; set; }
1613
public string Genre { get; set; }
1714
public string Director { get; set; }
18-
public string Writer { get; set; }
1915
public string Language { get; set; }
20-
public string Country { get; set; }
21-
public string Awards { get; set; }
2216
public int Metascore { get; set; }
2317
public decimal Rating { get; set; }
24-
public string Votes { get; set; }
2518
}
2619

2720
public class MovieRatingViewValidator : AbstractValidator<MovieRatingView>
2821
{
2922
public MovieRatingViewValidator()
3023
{
31-
RuleFor(x => x.Price)
24+
RuleFor(x => x.Released)
3225
.NotEmpty()
3326
.NotNull()
34-
.WithMessage("Price is required");
27+
.WithMessage("Released date is required")
28+
.Must(date => date <= DateTime.Now)
29+
.WithMessage("Released date cannot be in the future");
3530
RuleFor(x => x.Metascore)
3631
.NotEmpty()
3732
.NotNull()
@@ -40,10 +35,6 @@ public MovieRatingViewValidator()
4035
.NotEmpty()
4136
.NotNull()
4237
.WithMessage("Rating is required");
43-
RuleFor(x => x.Votes)
44-
.NotEmpty()
45-
.NotNull()
46-
.WithMessage("Votes is required");
4738
}
4839
}
4940
}

StarWars.Model/ViewModels/MovieView.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public class MovieView
77
{
88
public string ID { get; set; }
99
public string Title { get; set; }
10-
public string Year { get; set; }
11-
public string Type { get; set; }
10+
public int Year { get; set; }
1211
public string Poster { get; set; }
1312
public decimal Price { get; set; }
1413
public IEnumerable<MovieRatingView> MovieRatings { get; set; } = new List<MovieRatingView>();

StarWars.Repository/Configuration/MovieRatingConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public void Configure(EntityTypeBuilder<MovieRating> builder)
1111
builder.HasKey(m => m.ID).HasName("PK_MovieRating");
1212
builder.Property(m => m.ID).IsRequired().HasDefaultValueSql("NEWID()");
1313
builder.Property(m => m.MovieID).IsRequired();
14-
builder.Property(m => m.Price).HasColumnType("decimal(18,2)");
15-
builder.Property(m => m.Votes).IsRequired().HasMaxLength(100);
1614
builder.Property(m => m.Rating).HasColumnType("decimal(18,2)");
1715
builder.ToTable("MovieRating");
1816
}

0 commit comments

Comments
 (0)