forked from ReiMerc/skantravels
Create database and users table
This commit is contained in:
parent
037ca9d824
commit
bbf442e00c
1
API/.gitignore
vendored
Normal file
1
API/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
database.sqlite3*
|
@ -11,6 +11,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0-preview.6.24327.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0-preview.6.24327.4" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
|
9
API/AppDBContext.cs
Normal file
9
API/AppDBContext.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using API.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API;
|
||||
|
||||
public class AppDBContext(DbContextOptions<AppDBContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
}
|
@ -4,11 +4,17 @@ namespace API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class HealthCheckController : ControllerBase
|
||||
public class HealthCheckController(AppDBContext context) : ControllerBase
|
||||
{
|
||||
[HttpGet(Name = "HealthCheck")]
|
||||
public void Get()
|
||||
public StatusCodeResult Get()
|
||||
{
|
||||
if (!context.Database.CanConnect())
|
||||
{
|
||||
return new StatusCodeResult(500);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
API/Models/User.cs
Normal file
11
API/Models/User.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Models;
|
||||
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API
|
||||
{
|
||||
public class Program
|
||||
@ -23,6 +25,11 @@ namespace API
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
IConfiguration Configuration = builder.Configuration;
|
||||
|
||||
var connectionString = Configuration.GetConnectionString("DefaultConnection") ?? Environment.GetEnvironmentVariable("DefaultConnection");
|
||||
builder.Services.AddDbContext<AppDBContext>(options => options.UseSqlite(connectionString));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=database.sqlite3"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user