From 15dc10ff863856e41650098e1f39be3bd2105af6 Mon Sep 17 00:00:00 2001 From: Johan Reitan Date: Fri, 22 Aug 2025 15:59:07 +0200 Subject: [PATCH] this shit good --- .../Data/CinemaContext.cs | 26 ++++++++++++++++++- .../api-cinema-challenge/Program.cs | 11 ++++++++ .../api-cinema-challenge.csproj | 6 ++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs b/api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs index ad4fe854..9c8ef515 100644 --- a/api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs +++ b/api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs @@ -1,4 +1,7 @@ -using Microsoft.EntityFrameworkCore; +using api_cinema_challenge.Models; +using exercise.webapi.Data; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; using Newtonsoft.Json.Linq; namespace api_cinema_challenge.Data @@ -20,7 +23,28 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { + Seeder seeder = new Seeder(); + + + + modelBuilder.Entity().HasMany(a => a.Tickets).WithOne(b => b.Customer).HasForeignKey(c => c.CustomerId); + + modelBuilder.Entity().HasMany(a => a.Screenings).WithOne(b => b.Movie).HasForeignKey(c => c.MovieId); + + modelBuilder.Entity().HasOne(a => a.Screening).WithMany(b => b.Tickets).HasForeignKey(c => c.ScreeningId); + + + modelBuilder.Entity().HasData(seeder.Customers); + modelBuilder.Entity().HasData(seeder.Movies); + modelBuilder.Entity().HasData(seeder.Screenings); + modelBuilder.Entity().HasData(seeder.Tickets); } + + + public DbSet Customers { get; set; } + public DbSet Movies { get; set; } + public DbSet Screenings { get; set; } + public DbSet Tickets { get; set; } } } diff --git a/api-cinema-challenge/api-cinema-challenge/Program.cs b/api-cinema-challenge/api-cinema-challenge/Program.cs index e55d9d54..ae152cd9 100644 --- a/api-cinema-challenge/api-cinema-challenge/Program.cs +++ b/api-cinema-challenge/api-cinema-challenge/Program.cs @@ -1,4 +1,7 @@ using api_cinema_challenge.Data; +using api_cinema_challenge.Endpoints; +using api_cinema_challenge.Models; +using api_cinema_challenge.Repository; var builder = WebApplication.CreateBuilder(args); @@ -6,7 +9,12 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddDbContext(); +builder.Services.AddScoped, GenericRepository>(); +builder.Services.AddScoped, GenericRepository>(); +builder.Services.AddScoped, GenericRepository>(); +builder.Services.AddScoped, GenericRepository>(); +builder.Services.AddOpenApi(); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -17,4 +25,7 @@ } app.UseHttpsRedirection(); +app.ConfigureCustomerAPI(); +app.ConfigureMovieAPI(); +app.ConfigureScreeningAPI(); app.Run(); diff --git a/api-cinema-challenge/api-cinema-challenge/api-cinema-challenge.csproj b/api-cinema-challenge/api-cinema-challenge/api-cinema-challenge.csproj index 11e5c66b..725d822a 100644 --- a/api-cinema-challenge/api-cinema-challenge/api-cinema-challenge.csproj +++ b/api-cinema-challenge/api-cinema-challenge/api-cinema-challenge.csproj @@ -24,11 +24,9 @@ + + - - - -