From f925b8788377e5a0d89b05361376afe4b764fc13 Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Fri, 15 Sep 2023 11:52:44 +0200 Subject: [PATCH] :card_file_box: created dbcontext Co-authored-by: Sindre Kjelsrud --- backend/Context/DbContext.cs | 11 +++++++++++ backend/Program.cs | 7 +++++++ backend/appsettings.json | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 backend/Context/DbContext.cs diff --git a/backend/Context/DbContext.cs b/backend/Context/DbContext.cs new file mode 100644 index 0000000..61cfa8d --- /dev/null +++ b/backend/Context/DbContext.cs @@ -0,0 +1,11 @@ +using backend; +using Microsoft.EntityFrameworkCore; + +public class MovieDbContext: DbContext +{ + public MovieDbContext(DbContextOptions options) : base(options) + { + } + + public DbSet Movies { get; set; } +} \ No newline at end of file diff --git a/backend/Program.cs b/backend/Program.cs index 48863a6..4510a88 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -1,3 +1,5 @@ +using Microsoft.EntityFrameworkCore; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +9,11 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +var configuration = builder.Configuration; + +builder.Services.AddDbContext(options => + options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/backend/appsettings.json b/backend/appsettings.json index 10f68b8..9adc0dc 100644 --- a/backend/appsettings.json +++ b/backend/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Server=localhost;Database=movie-database;Port=5432;;Username=postgres;Password=moviedatabase" + } }