chore(#8): Add sqlite database

This commit is contained in:
Josh Creek
2023-09-14 22:14:08 +01:00
parent da9f711ff9
commit 06df9e2fa7
10 changed files with 273 additions and 23 deletions
+6
View File
@@ -25,3 +25,9 @@ This is plugged in to an LLM (GPT) with search capability, so you can find the p
- linking to calendars to make it clear if people are available or away - linking to calendars to make it clear if people are available or away
- embedding into Jira to make it easy to assign the right people to the right tickets - embedding into Jira to make it easy to assign the right people to the right tickets
## Local development instructions
1. Clone the repo
2. Run `dotnet tool install --global dotnet-ef` to install the Entity Framework CLI if you haven't already
3. Within the WhoAtX folder, run `dotnet ef migrations add InitialCreate` then `dotnet ef database update` to create the database
+42 -22
View File
@@ -1,39 +1,59 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using WhoAtX.Data;
using WhoAtX.Models; using WhoAtX.Models;
namespace WhoAtX.Controllers namespace WhoAtX.Controllers
{ {
public class UserController : Controller public class UserController : Controller
{ {
// TODO(#8): Get data from database rather than hard-coding it private readonly ApplicationDbContext _context;
private UserProfileViewModel GetUserProfile()
{
// Sample user profile data
var userProfile = new UserProfileViewModel
{
Name = "John Doe",
Pronouns = "He/Him",
NamePronunciationPath = "/audio/john_doe_pronunciation.mp3",
// NamePronunciationPath = null,
// Add more user profile data here
AreasOfKnowledge = "Web Development",
Projects = "Project X",
Team = "Development Team",
WorkingHours = "9:00 AM - 5:00 PM",
TimeZone = "UTC-05:00",
// Add more professional details here
};
return userProfile; public UserController(ApplicationDbContext context)
{
_context = context;
} }
public IActionResult Profile() public IActionResult Profile()
{ {
// Retrieve user profile data // Retrieve user profile data from the database
var userProfile = GetUserProfile(); var userProfile = _context.UserProfiles.FirstOrDefault();
if (userProfile is null)
{
// throw new NullReferenceException("User not found");
// For now, just give the default data
userProfile = new UserProfile
{
Name = "John Doe",
Pronouns = "He/Him",
NamePronunciationPath = "/audio/john_doe_pronunciation.mp3",
// NamePronunciationPath = null,
// Add more user profile data here
AreasOfKnowledge = "Web Development",
Projects = "Project X",
Team = "Development Team",
WorkingHours = "9:00 AM - 5:00 PM",
TimeZone = "UTC-05:00",
// Add more professional details here
};
}
// Map UserProfile to UserProfileViewModel
var userProfileViewModel = new UserProfileViewModel
{
Name = userProfile.Name,
Pronouns = userProfile.Pronouns,
NamePronunciationPath = userProfile.NamePronunciationPath,
AreasOfKnowledge = userProfile.AreasOfKnowledge,
Projects = userProfile.Projects,
Team = userProfile.Team,
WorkingHours = userProfile.WorkingHours,
TimeZone = userProfile.TimeZone,
};
// Pass the user profile data to the view // Pass the user profile data to the view
return View(userProfile); return View(userProfileViewModel);
} }
} }
} }
+13
View File
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using WhoAtX.Models;
namespace WhoAtX.Data;
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
@@ -0,0 +1,67 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WhoAtX.Data;
#nullable disable
namespace WhoAtX.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20230914205826_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.11");
modelBuilder.Entity("WhoAtX.Models.UserProfile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AreasOfKnowledge")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("NamePronunciationPath")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Projects")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pronouns")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Team")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TimeZone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("WorkingHours")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("UserProfiles");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,41 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WhoAtX.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UserProfiles",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Pronouns = table.Column<string>(type: "TEXT", nullable: false),
NamePronunciationPath = table.Column<string>(type: "TEXT", nullable: false),
AreasOfKnowledge = table.Column<string>(type: "TEXT", nullable: false),
Projects = table.Column<string>(type: "TEXT", nullable: false),
Team = table.Column<string>(type: "TEXT", nullable: false),
WorkingHours = table.Column<string>(type: "TEXT", nullable: false),
TimeZone = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserProfiles", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserProfiles");
}
}
}
@@ -0,0 +1,64 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WhoAtX.Data;
#nullable disable
namespace WhoAtX.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.11");
modelBuilder.Entity("WhoAtX.Models.UserProfile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AreasOfKnowledge")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("NamePronunciationPath")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Projects")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pronouns")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Team")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TimeZone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("WorkingHours")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("UserProfiles");
});
#pragma warning restore 612, 618
}
}
}
+14
View File
@@ -0,0 +1,14 @@
namespace WhoAtX.Models;
public class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
public string Pronouns { get; set; }
public string NamePronunciationPath { get; set; }
public string AreasOfKnowledge { get; set; }
public string Projects { get; set; }
public string Team { get; set; }
public string WorkingHours { get; set; }
public string TimeZone { get; set; }
}
+9
View File
@@ -1,8 +1,17 @@
using WhoAtX.Data;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlite(connectionString);
});
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
+13
View File
@@ -7,7 +7,20 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.11" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.24.230912.2-preview" /> <PackageReference Include="Microsoft.SemanticKernel" Version="0.24.230912.2-preview" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="UserDatabase.sqlite">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
+4 -1
View File
@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=UserDatabase.sqlite"
}
} }