Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,10 @@ FodyWeavers.xsd
*/**/bin/Release
*/**/obj/Debug
*/**/obj/Release
**/**/appsettings.json
**/**/appsettings.Development.json
**/**/bin/Debug
**/**/bin/Release
**/**/obj/Debug
**/**/obj/Release
/api-cinema-challenge/api-cinema-challenge/Migrations
Binary file added ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/CustomerDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace api_cinema_challenge.DTOs
{
public class CustomerDTO
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
}
17 changes: 17 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/MovieDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using api_cinema_challenge.Models;

namespace api_cinema_challenge.DTOs
{
public class MovieDTO
{
public string Title { get; set; }

public string Rating { get; set; }

public string Description { get; set; }

public int RuntimeMins { get; set; }

public List<ScreeningDTO>? Screenings { get; set; }
}
}
10 changes: 10 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/ScreeningDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace api_cinema_challenge.DTOs
{
public class ScreeningDTO
{
public int ScreenNumber { get; set; }
public int Capacity { get; set; }
public DateTime StartsAt { get; set; }

}
}
8 changes: 8 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTOs/TicketDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace api_cinema_challenge.DTOs
{
public class TicketDTO
{
public int NumSeats { get; set; }

}
}
210 changes: 209 additions & 1 deletion api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;
using api_cinema_challenge.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using System.Diagnostics;

namespace api_cinema_challenge.Data
{
Expand All @@ -16,11 +18,217 @@ public CinemaContext(DbContextOptions<CinemaContext> options) : base(options)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(_connectionString);
optionsBuilder.LogTo(message => Debug.WriteLine(message));
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var now = new DateTime(2025, 01, 01, 0, 0, 0, DateTimeKind.Utc);
modelBuilder.Entity<Movie>().HasData(
new Movie
{
Id = 1,
Title = "Inception",
Rating = "PG-13",
Description = "A thief who steals corporate secrets through the use of dream-sharing technology is tasked with planting an idea into the mind of a C.E.O.",
RuntimeMins = 148,
CreatedAt = now,
UpdatedAt = now
},
new Movie
{
Id = 2,
Title = "The Dark Knight",
Rating = "PG-13",
Description = "When the menace known as The Joker emerges from his mysterious past, he wreaks havoc and chaos on the people of Gotham.",
RuntimeMins = 152,
CreatedAt = now,
UpdatedAt = now
},
new Movie
{
Id = 3,
Title = "Interstellar",
Rating = "PG-13",
Description = "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
RuntimeMins = 169,
CreatedAt = now,
UpdatedAt = now
},
new Movie
{
Id = 4,
Title = "The Shawshank Redemption",
Rating = "R",
Description = "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
RuntimeMins = 142,
CreatedAt = now,
UpdatedAt = now
},
new Movie
{
Id = 5,
Title = "Dunkirk",
Rating = "PG-13",
Description = "Allied soldiers from Belgium, the British Empire, and France are surrounded by the German Army and evacuated during a fierce battle in World War II.",
RuntimeMins = 106,
CreatedAt = now,
UpdatedAt = now
}

);
modelBuilder.Entity<Customer>().HasData(
new Customer
{
Id = 1,
Name = "John Doe",
Email = "john.doe@example.com",
Phone = "123-456-7890",
CreatedAt = now,
UpdatedAt = now
},
new Customer
{
Id = 2,
Name = "Jane Smith",
Email = "jane.smith@example.com",
Phone = "098-765-4321",
CreatedAt = now,
UpdatedAt = now
},
new Customer
{
Id = 3,
Name = "Emily Davis",
Email = "emily.davis@example.com",
Phone = "555-123-4567",
CreatedAt = now,
UpdatedAt = now
},
new Customer
{
Id = 4,
Name = "Michael Brown",
Email = "michael.brown@example.com",
Phone = "444-567-8901",
CreatedAt = now,
UpdatedAt = now
},
new Customer
{
Id = 5,
Name = "Sarah Johnson",
Email = "sarah.johnson@example.com",
Phone = "222-345-6789",
CreatedAt = now,
UpdatedAt = now
}
);
modelBuilder.Entity<Screening>().HasData(
new Screening
{
Id = 1,
MovieId = 1,
ScreenNumber = 1,
Capacity = 100,
StartsAt = now.AddHours(2),
CreatedAt = now,
UpdatedAt = now
},
new Screening
{
Id = 2,
MovieId = 4,
ScreenNumber = 2,
Capacity = 80,
StartsAt = now.AddHours(3),
CreatedAt = now,
UpdatedAt = now
},
new Screening
{
Id = 3,
MovieId = 5,
ScreenNumber = 3,
Capacity = 120,
StartsAt = now.AddDays(1).AddHours(2),
CreatedAt = now,
UpdatedAt = now
},
new Screening
{
Id = 4,
MovieId = 3,
ScreenNumber = 1,
Capacity = 90,
StartsAt = now.AddDays(1).AddHours(5),
CreatedAt = now,
UpdatedAt = now
},
new Screening
{
Id = 5,
MovieId = 3,
ScreenNumber = 2,
Capacity = 110,
StartsAt = now.AddHours(6),
CreatedAt = now,
UpdatedAt = now
}
);
modelBuilder.Entity<Ticket>().HasData(
new Ticket
{
Id = 1,
ScreeningId = 1,
CustomerId = 1,
NumSeats = 2,
CreatedAt = now,
UpdatedAt = now
},
new Ticket
{
Id = 2,
ScreeningId = 2,
CustomerId = 2,
NumSeats = 1,
CreatedAt = now,
UpdatedAt = now
},
new Ticket
{
Id = 3,
ScreeningId = 3,
CustomerId = 3,
NumSeats = 4,
CreatedAt = now,
UpdatedAt = now
},
new Ticket
{
Id = 4,
ScreeningId = 4,
CustomerId = 4,
NumSeats = 3,
CreatedAt = now,
UpdatedAt = now
},
new Ticket
{
Id = 5,
ScreeningId = 5,
CustomerId = 5,
NumSeats = 2,
CreatedAt = now,
UpdatedAt = now
}
);
}

public DbSet<Customer> Customers { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<Screening> Screenings { get; set; }
public DbSet<Ticket> Tickets { get; set; }

}
}
Loading