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<MovieDbContext> options) : base(options) + { + } + + public DbSet<Movie> 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<MovieDbContext>(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" + } }