Fixed map profile, added migration for services

This commit is contained in:
Richárd Kunkli 2020-10-25 16:52:39 +01:00
parent 1c61f5ec63
commit c837f592d0
6 changed files with 189 additions and 7 deletions

View File

@ -7,6 +7,7 @@ namespace Birdmap.DAL
public class BirdmapContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Service> Services { get; set; }
public BirdmapContext([NotNull] DbContextOptions<BirdmapContext> options) : base(options)
{

View File

@ -0,0 +1,108 @@
// <auto-generated />
using System;
using Birdmap.DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Birdmap.DAL.Migrations
{
[DbContext(typeof(BirdmapContext))]
[Migration("20201025155153_AddedServices")]
partial class AddedServices
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Birdmap.DAL.Entities.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Uri")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Services");
b.HasData(
new
{
Id = 1,
Name = "KMLabz services",
Uri = "https://birb.k8s.kmlabz.com/devices"
},
new
{
Id = 2,
Name = "Local Database",
Uri = "/health"
});
});
modelBuilder.Entity("Birdmap.DAL.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<byte[]>("PasswordHash")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<byte[]>("PasswordSalt")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<int>("Role")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Name = "admin",
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 1
},
new
{
Id = 2,
Name = "user",
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 0
});
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Birdmap.DAL.Migrations
{
public partial class AddedServices : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Service",
table: "Service");
migrationBuilder.RenameTable(
name: "Service",
newName: "Services");
migrationBuilder.AddPrimaryKey(
name: "PK_Services",
table: "Services",
column: "Id");
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 }, new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 } });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 }, new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 } });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Services",
table: "Services");
migrationBuilder.RenameTable(
name: "Services",
newName: "Service");
migrationBuilder.AddPrimaryKey(
name: "PK_Service",
table: "Service",
column: "Id");
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 182, 156, 97, 101, 71, 25, 1, 147, 227, 96, 95, 0, 109, 186, 93, 70, 175, 182, 11, 77, 231, 91, 77, 46, 38, 241, 58, 9, 217, 227, 116, 97, 153, 200, 188, 237, 136, 224, 209, 148, 211, 183, 193, 59, 248, 219, 7, 64, 215, 234, 35, 102, 226, 124, 253, 113, 109, 120, 48, 158, 62, 75, 49, 25 }, new byte[] { 113, 114, 194, 22, 187, 116, 36, 33, 217, 100, 136, 225, 215, 1, 130, 131, 192, 198, 22, 50, 117, 244, 84, 85, 171, 4, 191, 0, 110, 145, 128, 150, 48, 226, 10, 149, 26, 111, 235, 125, 150, 120, 1, 168, 228, 110, 171, 2, 202, 54, 48, 214, 65, 75, 62, 245, 108, 82, 23, 226, 118, 218, 182, 177, 223, 124, 238, 67, 191, 103, 17, 159, 139, 44, 33, 62, 183, 22, 8, 193, 222, 60, 119, 240, 85, 179, 3, 35, 125, 23, 123, 232, 214, 193, 190, 13, 53, 131, 126, 124, 15, 238, 179, 202, 98, 173, 58, 29, 118, 253, 35, 34, 80, 79, 61, 185, 226, 99, 123, 195, 50, 46, 101, 45, 246, 1, 152, 61 } });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 182, 156, 97, 101, 71, 25, 1, 147, 227, 96, 95, 0, 109, 186, 93, 70, 175, 182, 11, 77, 231, 91, 77, 46, 38, 241, 58, 9, 217, 227, 116, 97, 153, 200, 188, 237, 136, 224, 209, 148, 211, 183, 193, 59, 248, 219, 7, 64, 215, 234, 35, 102, 226, 124, 253, 113, 109, 120, 48, 158, 62, 75, 49, 25 }, new byte[] { 113, 114, 194, 22, 187, 116, 36, 33, 217, 100, 136, 225, 215, 1, 130, 131, 192, 198, 22, 50, 117, 244, 84, 85, 171, 4, 191, 0, 110, 145, 128, 150, 48, 226, 10, 149, 26, 111, 235, 125, 150, 120, 1, 168, 228, 110, 171, 2, 202, 54, 48, 214, 65, 75, 62, 245, 108, 82, 23, 226, 118, 218, 182, 177, 223, 124, 238, 67, 191, 103, 17, 159, 139, 44, 33, 62, 183, 22, 8, 193, 222, 60, 119, 240, 85, 179, 3, 35, 125, 23, 123, 232, 214, 193, 190, 13, 53, 131, 126, 124, 15, 238, 179, 202, 98, 173, 58, 29, 118, 253, 35, 34, 80, 79, 61, 185, 226, 99, 123, 195, 50, 46, 101, 45, 246, 1, 152, 61 } });
}
}
}

View File

@ -36,7 +36,7 @@ namespace Birdmap.DAL.Migrations
b.HasKey("Id");
b.ToTable("Service");
b.ToTable("Services");
b.HasData(
new
@ -87,16 +87,16 @@ namespace Birdmap.DAL.Migrations
{
Id = 1,
Name = "admin",
PasswordHash = new byte[] { 182, 156, 97, 101, 71, 25, 1, 147, 227, 96, 95, 0, 109, 186, 93, 70, 175, 182, 11, 77, 231, 91, 77, 46, 38, 241, 58, 9, 217, 227, 116, 97, 153, 200, 188, 237, 136, 224, 209, 148, 211, 183, 193, 59, 248, 219, 7, 64, 215, 234, 35, 102, 226, 124, 253, 113, 109, 120, 48, 158, 62, 75, 49, 25 },
PasswordSalt = new byte[] { 113, 114, 194, 22, 187, 116, 36, 33, 217, 100, 136, 225, 215, 1, 130, 131, 192, 198, 22, 50, 117, 244, 84, 85, 171, 4, 191, 0, 110, 145, 128, 150, 48, 226, 10, 149, 26, 111, 235, 125, 150, 120, 1, 168, 228, 110, 171, 2, 202, 54, 48, 214, 65, 75, 62, 245, 108, 82, 23, 226, 118, 218, 182, 177, 223, 124, 238, 67, 191, 103, 17, 159, 139, 44, 33, 62, 183, 22, 8, 193, 222, 60, 119, 240, 85, 179, 3, 35, 125, 23, 123, 232, 214, 193, 190, 13, 53, 131, 126, 124, 15, 238, 179, 202, 98, 173, 58, 29, 118, 253, 35, 34, 80, 79, 61, 185, 226, 99, 123, 195, 50, 46, 101, 45, 246, 1, 152, 61 },
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 1
},
new
{
Id = 2,
Name = "user",
PasswordHash = new byte[] { 182, 156, 97, 101, 71, 25, 1, 147, 227, 96, 95, 0, 109, 186, 93, 70, 175, 182, 11, 77, 231, 91, 77, 46, 38, 241, 58, 9, 217, 227, 116, 97, 153, 200, 188, 237, 136, 224, 209, 148, 211, 183, 193, 59, 248, 219, 7, 64, 215, 234, 35, 102, 226, 124, 253, 113, 109, 120, 48, 158, 62, 75, 49, 25 },
PasswordSalt = new byte[] { 113, 114, 194, 22, 187, 116, 36, 33, 217, 100, 136, 225, 215, 1, 130, 131, 192, 198, 22, 50, 117, 244, 84, 85, 171, 4, 191, 0, 110, 145, 128, 150, 48, 226, 10, 149, 26, 111, 235, 125, 150, 120, 1, 168, 228, 110, 171, 2, 202, 54, 48, 214, 65, 75, 62, 245, 108, 82, 23, 226, 118, 218, 182, 177, 223, 124, 238, 67, 191, 103, 17, 159, 139, 44, 33, 62, 183, 22, 8, 193, 222, 60, 119, 240, 85, 179, 3, 35, 125, 23, 123, 232, 214, 193, 190, 13, 53, 131, 126, 124, 15, 238, 179, 202, 98, 173, 58, 29, 118, 253, 35, 34, 80, 79, 61, 185, 226, 99, 123, 195, 50, 46, 101, 45, 246, 1, 152, 61 },
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 0
});
});

View File

@ -7,7 +7,10 @@ namespace Birdmap.API.MapperProfiles
{
public BirdmapProfile()
{
CreateMap<User, DTOs.AuthenticateResponse>().ReverseMap();
CreateMap<User, DTOs.AuthenticateResponse>()
.ForMember(m => m.Username, opt => opt.MapFrom(m => m.Name))
.ForMember(m => m.UserRole, opt => opt.MapFrom(m => m.Role))
.ReverseMap();
}
}
}

View File

@ -29,6 +29,8 @@ namespace Birdmap
services.AddControllersWithViews()
.AddJsonOptions(opt =>
{
opt.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
opt.JsonSerializerOptions.IgnoreNullValues = true;
//opt.JsonSerializerOptions.PropertyNamingPolicy = new JsonNamingPolicy()
});
@ -87,7 +89,7 @@ namespace Birdmap
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health").RequireAuthorization();
endpoints.MapHealthChecks("/health");
endpoints.MapControllers();
});