diff --git a/backend/.gitignore b/backend/.gitignore index 20c38ef..63d4574 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,5 +1,5 @@ obj/ bin/ appsettings.json -db.sqlite3 +db.sqlite3* diff --git a/backend/Controllers/DispenserController.cs b/backend/Controllers/DispenserController.cs index ffa5ca8..48bc2fb 100644 --- a/backend/Controllers/DispenserController.cs +++ b/backend/Controllers/DispenserController.cs @@ -24,4 +24,3 @@ public class DispenserController : ControllerBase ApplicationState.MqttClient!.PublishAsync(message, CancellationToken.None); } } - diff --git a/backend/Controllers/UserController.cs b/backend/Controllers/UserController.cs new file mode 100644 index 0000000..c7306b1 --- /dev/null +++ b/backend/Controllers/UserController.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using backend.Application; +using backend.Models; + +namespace backend.Controllers; + +[ApiController] +public class UserController : ControllerBase +{ + [HttpPost("Register")] + public void Register() + { + ApplicationState.DbContext!.Add(new User { Username = "test", Password = "test", TouchCode = "1234" }); + ApplicationState.DbContext!.SaveChanges(); + } +} diff --git a/backend/DispenserContext.cs b/backend/DispenserContext.cs index d99ef29..0cd9304 100644 --- a/backend/DispenserContext.cs +++ b/backend/DispenserContext.cs @@ -8,6 +8,7 @@ using backend.Models; public class DispenserContext : DbContext { public DbSet DispenserLogs { get; set; } + public DbSet Users { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) { diff --git a/backend/Migrations/20231206130439_CreateUser.Designer.cs b/backend/Migrations/20231206130439_CreateUser.Designer.cs new file mode 100644 index 0000000..c257b83 --- /dev/null +++ b/backend/Migrations/20231206130439_CreateUser.Designer.cs @@ -0,0 +1,61 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace backend.Migrations +{ + [DbContext(typeof(DispenserContext))] + [Migration("20231206130439_CreateUser")] + partial class CreateUser + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("backend.Models.DispenserLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("DispenserLogs"); + }); + + modelBuilder.Entity("backend.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TouchCode") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/Migrations/20231206130439_CreateUser.cs b/backend/Migrations/20231206130439_CreateUser.cs new file mode 100644 index 0000000..729b12b --- /dev/null +++ b/backend/Migrations/20231206130439_CreateUser.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace backend.Migrations +{ + /// + public partial class CreateUser : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Username = table.Column(type: "TEXT", nullable: false), + Password = table.Column(type: "TEXT", nullable: false), + TouchCode = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/backend/Migrations/DispenserContextModelSnapshot.cs b/backend/Migrations/DispenserContextModelSnapshot.cs index c49025e..934fa00 100644 --- a/backend/Migrations/DispenserContextModelSnapshot.cs +++ b/backend/Migrations/DispenserContextModelSnapshot.cs @@ -29,6 +29,29 @@ namespace backend.Migrations b.ToTable("DispenserLogs"); }); + + modelBuilder.Entity("backend.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TouchCode") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); #pragma warning restore 612, 618 } } diff --git a/backend/Models/DispenserLog.cs b/backend/Models/DispenserLog.cs index 4a146cb..7c08de5 100644 --- a/backend/Models/DispenserLog.cs +++ b/backend/Models/DispenserLog.cs @@ -1,6 +1,3 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -14,4 +11,3 @@ public class DispenserLog public DateTime Timestamp { get; set; } } - diff --git a/backend/Models/User.cs b/backend/Models/User.cs new file mode 100644 index 0000000..f251a7e --- /dev/null +++ b/backend/Models/User.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace backend.Models; + +public class User +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + + public string Username { get; set; } + public string Password { get; set; } + public string TouchCode { get; set; } +}