Update names part 2

This commit is contained in:
2023-01-06 11:10:58 +01:00
parent fd179d82ca
commit 0daf0c582a
30 changed files with 664 additions and 313 deletions

View File

@@ -19,8 +19,8 @@ const routes: Routes = [
loadChildren: () => import('./modules/dashboard/dashboard.module').then(m => m.DashboardModule)
},
{
path: 'datasets',
loadChildren: () => import('./modules/data-sets/data-sets.module').then(m => m.DataSetsModule)
path: 'layers',
loadChildren: () => import('./modules/layers/layers.module').then(m => m.LayersModule)
},
]
}

View File

@@ -29,7 +29,7 @@
<mat-icon class="menu-icon">dashboard</mat-icon>
Dashboard
</a>
<a mat-list-item routerLink="./datasets">
<a mat-list-item routerLink="./layers">
<mat-icon class="menu-icon">table</mat-icon>
Zbiory danych
</a>

View File

@@ -3,22 +3,22 @@ import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { map } from 'rxjs';
import { DataRow } from './dataRow.model copy';
import { Record } from 'src/app/models/record.model';
export class DataSet extends Base {
export class Layer extends Base {
number?: Number;
source?: string;
name?: string;
dataRows: DataRow[] = [];
records: Record[] = [];
created?: string;
constructor(data: Partial<DataSet> = {}) {
constructor(data: Partial<Layer> = {}) {
super();
Object.assign(this, data);
}
override deserialize(input: any): this {
Object.assign(this, Object.assign(this, super.deserialize(input)));
if (this.dataRows) { this.dataRows = this.dataRows.map(x => new DataRow().deserialize(x)); }
if (this.records) { this.records = this.records.map(x => new Record().deserialize(x)); }
return this;
}
override serialize() {
@@ -48,15 +48,15 @@ export class DataSet extends Base {
}
loadForm(form: UntypedFormGroup) {
for (let field of Object.keys(form.controls)) {
this[field as keyof DataSet] = form.controls[field].value;
this[field as keyof Layer] = form.controls[field].value;
}
this.createdBy = undefined;
this.modifiedBy = undefined;
}
//API Actions
static add(input: DataSet, _http: HttpClient): Promise<string> {
static add(input: Layer, _http: HttpClient): Promise<string> {
return new Promise((resolve, reject) => {
_http.post<string>(`${environment.api.url}/datasets`, { ...input.serialize(), }).subscribe({
_http.post<string>(`${environment.api.url}/layers`, { ...input.serialize(), }).subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
}
@@ -65,28 +65,28 @@ export class DataSet extends Base {
}
static getList(_http: HttpClient): any {
return new Promise((resolve, reject) => {
_http.get<DataSet[]>(`${environment.api.url}/datasets`)
.pipe(map(data => data.map(x => new DataSet().deserialize(x))))
_http.get<Layer[]>(`${environment.api.url}/layers`)
.pipe(map(data => data.map(x => new Layer().deserialize(x))))
.subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
})
});
}
static getById(id: string, _http: HttpClient): Promise<DataSet> {
static getById(id: string, _http: HttpClient): Promise<Layer> {
return new Promise((resolve, reject) => {
_http.get<DataSet>(`${environment.api.url}/datasets/${id}`).pipe(map(x => new DataSet().deserialize(x))).subscribe({
_http.get<Layer>(`${environment.api.url}/layers/${id}`).pipe(map(x => new Layer().deserialize(x))).subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
})
});
}
static parseFile(file: any, _http: HttpClient): Promise<DataRow[]> {
static parseFile(file: any, _http: HttpClient): Promise<Layer[]> {
const formData = new FormData();
formData.append(file.name, file);
return new Promise((resolve, reject) => {
_http.post<DataRow[]>(`${environment.api.url}/datasets/parseFile`, formData,
).pipe(map(data => data.map(x => new DataRow().deserialize(x))))
_http.post<Layer[]>(`${environment.api.url}/layers/parseFile`, formData,
).pipe(map(data => data.map(x => new Layer().deserialize(x))))
.subscribe({
next: (data) => {
resolve(data);
@@ -95,10 +95,10 @@ export class DataSet extends Base {
})
})
}
static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<DataSet> {
static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<Layer> {
return new Promise((resolve, reject) => {
_http.get<DataSet>(`${environment.api.url}/datasets/parseGoogleSheet/${sheetId}`,
).pipe(map(data => new DataSet().deserialize(data)))
_http.get<Layer>(`${environment.api.url}/layers/parseGoogleSheet/${sheetId}`,
).pipe(map(data => new Layer().deserialize(data)))
.subscribe({
next: (data) => {
resolve(data);
@@ -109,7 +109,7 @@ export class DataSet extends Base {
}
static exportToGoogleSheet(id: string, _http: HttpClient): Promise<boolean> {
return new Promise((resolve, reject) => {
_http.get<boolean>(`${environment.api.url}/datasets/exportToGoogleSheet/${id}`,
_http.get<boolean>(`${environment.api.url}/layers/exportToGoogleSheet/${id}`,
).subscribe({
next: (data) => {
resolve(data);

View File

@@ -5,7 +5,7 @@ import { environment } from 'src/environments/environment';
import { DataService } from '../services/data.service';
import { map } from 'rxjs';
export class DataRow extends Base {
export class Record extends Base {
code?: string;
value?: number;
desc1?: string;
@@ -14,7 +14,7 @@ export class DataRow extends Base {
desc4?: string;
desc5?: string;
constructor(data: Partial<DataRow> = {}) {
constructor(data: Partial<Record> = {}) {
super();
Object.assign(this, data);
}

View File

@@ -6,7 +6,7 @@ import { environment } from 'src/environments/environment';
@Component({
selector: 'b-crm-board',
selector: 'diunaBI-board',
templateUrl: './board.component.html',
styleUrls: ['./board.component.scss']
})

View File

@@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DataSetDetailComponent } from './data-set-detail.component';
describe('DataSetDetailComponent', () => {
let component: DataSetDetailComponent;
let fixture: ComponentFixture<DataSetDetailComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DataSetDetailComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(DataSetDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DataSetEditComponent } from './data-set-edit.component';
describe('DataSetEditComponent', () => {
let component: DataSetEditComponent;
let fixture: ComponentFixture<DataSetEditComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DataSetEditComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(DataSetEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DataSetsListComponent } from './data-sets-list.component';
describe('DataSetsListComponent', () => {
let component: DataSetsListComponent;
let fixture: ComponentFixture<DataSetsListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DataSetsListComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(DataSetsListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -1,17 +0,0 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DataSetDetailComponent } from './data-set-detail/data-set-detail.component';
import { DataSetEditComponent } from './data-set-edit/data-set-edit.component';
import { DataSetsListComponent } from './data-sets-list/data-sets-list.component';
const routes: Routes = [
{ path: '', component: DataSetsListComponent },
{ path: 'Edit/:id', component: DataSetEditComponent },
{ path: 'Detail/:id', component: DataSetDetailComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DataSetsRoutingModule { }

View File

@@ -1,27 +0,0 @@
import { NgModule } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { DataSetsRoutingModule } from './data-sets-routing.module';
import { DataSetsListComponent } from './data-sets-list/data-sets-list.component';
import { MaterialModule } from 'src/app/material.module';
import { DataSetDetailComponent } from './data-set-detail/data-set-detail.component';
import { DataSetEditComponent } from './data-set-edit/data-set-edit.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [
DataSetsListComponent,
DataSetDetailComponent,
DataSetEditComponent
],
imports: [
CommonModule,
DataSetsRoutingModule,
MaterialModule,
FormsModule,
ReactiveFormsModule
],
providers: [
DatePipe
]
})
export class DataSetsModule { }

View File

@@ -1,5 +1,4 @@
import { DataSource } from '@angular/cdk/collections';
import { DatePipe, DecimalPipe } from '@angular/common';
import { DatePipe } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, ViewChild } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder } from '@angular/forms';
@@ -8,23 +7,22 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { MatSort, MatSortable } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { Router, ActivatedRoute } from '@angular/router';
import moment from 'moment';
import { AuthService } from 'src/app/auth/auth.service';
import { DataRow } from 'src/app/models/dataRow.model copy';
import { DataSet } from 'src/app/models/dataSet.model';
import { Layer } from 'src/app/models/layer.model';
import { Record } from 'src/app/models/record.model';
@Component({
selector: 'app-data-set-detail',
templateUrl: './data-set-detail.component.html',
styleUrls: ['./data-set-detail.component.scss']
selector: 'diunaBI-layer-detail',
templateUrl: './layer-detail.component.html',
styleUrls: ['./layer-detail.component.scss']
})
export class DataSetDetailComponent {
export class LayerDetailComponent {
public form!: UntypedFormGroup;
public document!: DataSet;
public document!: Layer;
displayedColumns = ['code', 'value'];
dataSource!: MatTableDataSource<DataRow>;
dataSource!: MatTableDataSource<Record>;
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
@@ -40,9 +38,9 @@ export class DataSetDetailComponent {
) { }
async ngOnInit() {
this.form = DataSet.getForm(this.fb$);
this.form = Layer.getForm(this.fb$);
this.document = await this.load();
this.dataSource = new MatTableDataSource<DataRow>(this.document.dataRows);
this.dataSource = new MatTableDataSource<Record>(this.document.records);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.document.fillForm(this.form);
@@ -50,14 +48,14 @@ export class DataSetDetailComponent {
this.document.created = `${this.datePipe.transform(this.document.createdAt?.toDate(), 'short')}, ${this.document.createdBy?.userName}`;
this.dataSource.sort.sort({ id: 'code', start: 'desc' } as MatSortable);
}
private async load(): Promise<DataSet> {
return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);
private async load(): Promise<Layer> {
return await Layer.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);
}
trackByUid(index : number, item : DataRow) {
trackByUid(index : number, item : Record) {
return item.id;
}
async export() {
if (await DataSet.exportToGoogleSheet(this.document.id || "", this.http$)) {
if (await Layer.exportToGoogleSheet(this.document.id || "", this.http$)) {
this.snackBar.open("Plik został zapisany na dysku Google", "OK");
} else {
this.snackBar.open("Zapis się nie udał.", "OK");

View File

@@ -8,23 +8,22 @@ import { MatTableDataSource } from '@angular/material/table';
import { Router, ActivatedRoute } from '@angular/router';
import moment from 'moment';
import { AuthService } from 'src/app/auth/auth.service';
import { DataRow } from 'src/app/models/dataRow.model copy';
import { DataSet } from 'src/app/models/dataSet.model';
import { DataService } from 'src/app/services/data.service';
import { Layer } from 'src/app/models/layer.model';
import { Record } from 'src/app/models/record.model';
import { v4 as uuidv4 } from 'uuid';
@Component({
selector: 'app-data-set-edit',
templateUrl: './data-set-edit.component.html',
styleUrls: ['./data-set-edit.component.scss']
selector: 'diunaBI-layer-edit',
templateUrl: './layer-edit.component.html',
styleUrls: ['./layer-edit.component.scss']
})
export class DataSetEditComponent implements OnInit {
export class LayerEditComponent implements OnInit {
public form!: UntypedFormGroup;
private document!: DataSet;
private document!: Layer;
displayedColumns = ['code', 'value', 'desc1'];
dataSource!: MatTableDataSource<DataRow>;
dataSource!: MatTableDataSource<Record>;
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
@@ -38,8 +37,8 @@ export class DataSetEditComponent implements OnInit {
) { }
async ngOnInit() {
this.form = DataSet.getForm(this.fb$);
this.document = new DataSet({
this.form = Layer.getForm(this.fb$);
this.document = new Layer({
id: uuidv4(), createdById: this.auth$.user.id, createdAt: moment(),
modifiedAt: moment()
})
@@ -50,24 +49,24 @@ export class DataSetEditComponent implements OnInit {
return;
}
this.document.loadForm(this.form);
const id = await DataSet.add(this.document, this.http$);
const id = await Layer.add(this.document, this.http$);
this.router$.navigate(['../../Detail', id], { relativeTo: this.route$ });
}
async onFileSelected(event: any) {
const file = event.target.files[0];
this.document.dataRows = await DataSet.parseFile(file, this.http$);
this.dataSource = new MatTableDataSource(this.document.dataRows);
this.document.records = await Layer.parseFile(file, this.http$);
this.dataSource = new MatTableDataSource(this.document.records);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
trackByUid(index: number, item: DataRow) {
trackByUid(index: number, item: Record) {
return item.id;
}
async parseGoogleSheet() {
const id = this.form.get('sheetId')?.value;
this.document = await DataSet.parseGoogleSheet(id, this.http$);
this.document = await Layer.parseGoogleSheet(id, this.http$);
this.document.fillForm(this.form);
this.dataSource = new MatTableDataSource(this.document.dataRows);
this.dataSource = new MatTableDataSource(this.document.records);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}

View File

@@ -3,28 +3,26 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort, MatSortable } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { DataSet } from 'src/app/models/dataSet.model';
import { Layer } from 'src/app/models/layer.model';
@Component({
selector: 'app-data-sets-list',
templateUrl: './data-sets-list.component.html',
styleUrls: ['./data-sets-list.component.scss']
selector: 'diunaBI-layers-list',
templateUrl: './layers-list.component.html',
styleUrls: ['./layers-list.component.scss']
})
export class DataSetsListComponent implements OnInit {
export class LayersListComponent implements OnInit {
displayedColumns = ['number', 'name', 'source'];
dataSource!: MatTableDataSource<DataSet>;
dataSource!: MatTableDataSource<Layer>;
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
constructor(
private _http: HttpClient
) {
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone);
}
) { }
async ngOnInit() {
this.dataSource = new MatTableDataSource(await DataSet.getList(this._http));
this.dataSource = new MatTableDataSource(await Layer.getList(this._http));
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.sort.sort({ id: 'number', start: 'desc' } as MatSortable);
@@ -34,7 +32,7 @@ export class DataSetsListComponent implements OnInit {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
}
trackByUid(index : number, item : DataSet) {
trackByUid(index : number, item : Layer) {
return item.id;
}
}

View File

@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LayerDetailComponent } from './layer-detail/layer-detail.component';
import { LayerEditComponent } from './layer-edit/layer-edit.component';
import { LayersListComponent } from './layers-list/layers-list.component';
const routes: Routes = [
{ path: '', component: LayersListComponent },
{ path: 'Edit/:id', component: LayerEditComponent },
{ path: 'Detail/:id', component: LayerDetailComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LayersRoutingModule { }

View File

@@ -0,0 +1,27 @@
import { NgModule } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { MaterialModule } from 'src/app/material.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LayersListComponent } from './layers-list/layers-list.component';
import { LayerEditComponent } from './layer-edit/layer-edit.component';
import { LayerDetailComponent } from './layer-detail/layer-detail.component';
import { LayersRoutingModule } from './layers-routing.module';
@NgModule({
declarations: [
LayersListComponent,
LayerEditComponent,
LayerDetailComponent
],
imports: [
CommonModule,
LayersRoutingModule,
MaterialModule,
FormsModule,
ReactiveFormsModule
],
providers: [
DatePipe
]
})
export class LayersModule { }

View File

@@ -5,8 +5,8 @@
export const environment = {
production: false,
api: {
//url: "http://localhost:5400/api"
url: "https://diunabi.bim-it.pl/api"
url: "http://localhost:5400/api"
//url: "https://diunabi.bim-it.pl/api"
},
google: {
clientId: "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com"

View File

@@ -7,8 +7,8 @@ namespace WebAPI
public class AppDbContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Layer> DataSets { get; set; }
public DbSet<Record> DataRows { get; set; }
public DbSet<Layer> Layers { get; set; }
public DbSet<Record> Records { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{

View File

@@ -44,7 +44,7 @@ namespace WebAPI.Controllers
{
try
{
return Ok(db.DataSets.Where(x => !x.IsDeleted).ToList());
return Ok(db.Layers.Where(x => !x.IsDeleted).ToList());
}
catch (Exception e)
{
@@ -58,7 +58,7 @@ namespace WebAPI.Controllers
{
Request.Headers.TryGetValue("userId", out var value);
Guid currentUserId = new Guid(value!);
return Ok(AddDataSet(input, currentUserId).Id);
return Ok(AddLayer(input, currentUserId).Id);
} catch (Exception e)
{
return BadRequest(e.ToString());
@@ -70,7 +70,7 @@ namespace WebAPI.Controllers
{
try
{
return Ok(db.DataSets
return Ok(db.Layers
.Include(x => x.CreatedBy)
.Include(x => x.Records)
.Where(x => x.Id == id && !x.IsDeleted).First());
@@ -100,12 +100,12 @@ namespace WebAPI.Controllers
[Route("exportToGoogleSheet/{id}")]
public IActionResult ExportToGoogleSheet(Guid id)
{
Layer dataSet = db.DataSets
Layer layer = db.Layers
.Include(x => x.Records)
.Where(x => x.Id == id && !x.IsDeleted).First();
var export = new googleSheetExport(googleDriveHelper, googleSheetValues);
export.export(dataSet);
export.export(layer);
return Ok(true);
}
@@ -121,47 +121,47 @@ namespace WebAPI.Controllers
string sheetId = "1G_Hu8DTP-PSPNXTaVYhc_ppnTQi6HWoA4oXSSdUmM9E";
string sheetName = "KOSZTY";
Layer dataSet = new Layer();
dataSet.Source = "GoogleSheet";
dataSet.Number = db.DataSets.Count() + 1;
Layer layer = new Layer();
layer.Source = "GoogleSheet";
layer.Number = db.Layers.Count() + 1;
var parser = new googleSheetParser(googleSheetValues);
dynamic parsedSheet = parser.parse(sheetId);
dataSet.Records = parsedSheet.records;
dataSet.Name = $"W{dataSet.Number}-I-{sheetName}-{parsedSheet.date}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
AddDataSet(dataSet, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
layer.Records = parsedSheet.records;
layer.Name = $"W{layer.Number}-I-{sheetName}-{parsedSheet.date}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
AddLayer(layer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
return Ok("OK");
}
//
private Layer AddDataSet(Layer input, Guid currentUserId)
private Layer AddLayer(Layer input, Guid currentUserId)
{
input.Number = db.DataSets.Count() + 1;
input.Number = db.Layers.Count() + 1;
input.CreatedById = currentUserId;
input.ModifiedById = currentUserId;
input.CreatedAt = DateTime.UtcNow;
input.ModifiedAt = DateTime.UtcNow;
db.DataSets.Add(input);
SaveDataRows(input.Id, input.Records!, currentUserId);
db.Layers.Add(input);
SaveRecords(input.Id, input.Records!, currentUserId);
db.SaveChanges();
return input;
}
private void SaveDataRows(Guid id, ICollection<Models.Record> dataRows, Guid currentUserId)
private void SaveRecords(Guid id, ICollection<Models.Record> records, Guid currentUserId)
{
try
{
List<Guid> ids = new List<Guid>();
foreach (Models.Record dataRow in dataRows)
foreach (Record record in records)
{
dataRow.CreatedById = currentUserId;
dataRow.CreatedAt = DateTime.UtcNow;
dataRow.ModifiedById = currentUserId;
dataRow.ModifiedAt = DateTime.UtcNow;
dataRow.DataSetId= id;
record.CreatedById = currentUserId;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedById = currentUserId;
record.ModifiedAt = DateTime.UtcNow;
record.LayerId= id;
db.DataRows.Add(dataRow);
db.Records.Add(record);
}
}
catch (Exception)

View File

@@ -15,14 +15,14 @@ namespace WebAPI.Exports
googleDriveHelper = _googleDriveHelper;
googleSheetValues = _googleSheetValues;
}
public void export(Layer dataSet)
public void export(Layer layer)
{
try
{
List<IList<object>> data = new List<IList<object>>() { new List<object>() { dataSet.Name, dataSet.Number } };
foreach (Record dataRow in dataSet.Records)
List<IList<object>> data = new List<IList<object>>() { new List<object>() { layer.Name!, layer.Number! } };
foreach (Record record in layer.Records!)
{
data.Add(new List<object> { dataRow.Code, dataRow.Value });
data.Add(new List<object> { record.Code!, record.Value });
}
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();

View File

@@ -0,0 +1,199 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebAPI;
#nullable disable
namespace WebAPI.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20230106095427_RenameModels")]
partial class RenameModels
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("Number")
.IsRequired()
.HasColumnType("int");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("ModifiedById");
b.ToTable("Layers");
});
modelBuilder.Entity("WebAPI.Models.Record", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Desc1")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc2")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc3")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc4")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc5")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<float>("Value")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("LayerId");
b.HasIndex("ModifiedById");
b.ToTable("Records");
});
modelBuilder.Entity("WebAPI.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Email")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserName")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.HasOne("WebAPI.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("WebAPI.Models.Record", b =>
{
b.HasOne("WebAPI.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.Layer", null)
.WithMany("Records")
.HasForeignKey("LayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.Navigation("Records");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,227 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebAPI.Migrations
{
/// <inheritdoc />
public partial class RenameModels : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DataRows");
migrationBuilder.DropTable(
name: "DataSets");
migrationBuilder.CreateTable(
name: "Layers",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Number = table.Column<int>(type: "int", nullable: false),
Source = table.Column<string>(type: "nvarchar(max)", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
CreatedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ModifiedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Layers", x => x.Id);
table.ForeignKey(
name: "FK_Layers_Users_CreatedById",
column: x => x.CreatedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_Layers_Users_ModifiedById",
column: x => x.ModifiedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "Records",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Code = table.Column<string>(type: "nvarchar(max)", nullable: false),
Value = table.Column<float>(type: "real", nullable: false),
Desc1 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc2 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc3 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc4 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc5 = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
CreatedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ModifiedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
LayerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Records", x => x.Id);
table.ForeignKey(
name: "FK_Records_Layers_LayerId",
column: x => x.LayerId,
principalTable: "Layers",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_Records_Users_CreatedById",
column: x => x.CreatedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_Records_Users_ModifiedById",
column: x => x.ModifiedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateIndex(
name: "IX_Layers_CreatedById",
table: "Layers",
column: "CreatedById");
migrationBuilder.CreateIndex(
name: "IX_Layers_ModifiedById",
table: "Layers",
column: "ModifiedById");
migrationBuilder.CreateIndex(
name: "IX_Records_CreatedById",
table: "Records",
column: "CreatedById");
migrationBuilder.CreateIndex(
name: "IX_Records_LayerId",
table: "Records",
column: "LayerId");
migrationBuilder.CreateIndex(
name: "IX_Records_ModifiedById",
table: "Records",
column: "ModifiedById");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Records");
migrationBuilder.DropTable(
name: "Layers");
migrationBuilder.CreateTable(
name: "DataSets",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreatedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ModifiedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Number = table.Column<int>(type: "int", nullable: false),
Source = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DataSets", x => x.Id);
table.ForeignKey(
name: "FK_DataSets_Users_CreatedById",
column: x => x.CreatedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_DataSets_Users_ModifiedById",
column: x => x.ModifiedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "DataRows",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreatedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ModifiedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Code = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
DataSetId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Desc1 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc2 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc3 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc4 = table.Column<string>(type: "nvarchar(max)", nullable: true),
Desc5 = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
Value = table.Column<float>(type: "real", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DataRows", x => x.Id);
table.ForeignKey(
name: "FK_DataRows_DataSets_DataSetId",
column: x => x.DataSetId,
principalTable: "DataSets",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_DataRows_Users_CreatedById",
column: x => x.CreatedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
table.ForeignKey(
name: "FK_DataRows_Users_ModifiedById",
column: x => x.ModifiedById,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateIndex(
name: "IX_DataRows_CreatedById",
table: "DataRows",
column: "CreatedById");
migrationBuilder.CreateIndex(
name: "IX_DataRows_DataSetId",
table: "DataRows",
column: "DataSetId");
migrationBuilder.CreateIndex(
name: "IX_DataRows_ModifiedById",
table: "DataRows",
column: "ModifiedById");
migrationBuilder.CreateIndex(
name: "IX_DataSets_CreatedById",
table: "DataSets",
column: "CreatedById");
migrationBuilder.CreateIndex(
name: "IX_DataSets_ModifiedById",
table: "DataSets",
column: "ModifiedById");
}
}
}

View File

@@ -22,64 +22,7 @@ namespace WebAPI.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("WebAPI.Models.DataRow", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("DataSetId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Desc1")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc2")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc3")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc4")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc5")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<float>("Value")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("DataSetId");
b.HasIndex("ModifiedById");
b.ToTable("DataRows");
});
modelBuilder.Entity("WebAPI.Models.DataSet", b =>
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@@ -118,7 +61,64 @@ namespace WebAPI.Migrations
b.HasIndex("ModifiedById");
b.ToTable("DataSets");
b.ToTable("Layers");
});
modelBuilder.Entity("WebAPI.Models.Record", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Desc1")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc2")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc3")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc4")
.HasColumnType("nvarchar(max)");
b.Property<string>("Desc5")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<float>("Value")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("LayerId");
b.HasIndex("ModifiedById");
b.ToTable("Records");
});
modelBuilder.Entity("WebAPI.Models.User", b =>
@@ -142,32 +142,7 @@ namespace WebAPI.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("WebAPI.Models.DataRow", b =>
{
b.HasOne("WebAPI.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.DataSet", null)
.WithMany("DataRows")
.HasForeignKey("DataSetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("WebAPI.Models.DataSet", b =>
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.HasOne("WebAPI.Models.User", "CreatedBy")
.WithMany()
@@ -186,9 +161,34 @@ namespace WebAPI.Migrations
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("WebAPI.Models.DataSet", b =>
modelBuilder.Entity("WebAPI.Models.Record", b =>
{
b.Navigation("DataRows");
b.HasOne("WebAPI.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.Layer", null)
.WithMany("Records")
.HasForeignKey("LayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPI.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("WebAPI.Models.Layer", b =>
{
b.Navigation("Records");
});
#pragma warning restore 612, 618
}

View File

@@ -28,7 +28,7 @@ namespace WebAPI.Models
[Required]
public Guid ModifiedById { get; set; }
public User? ModifiedBy { get; set; }
public Guid DataSetId { get; set; }
public Guid LayerId { get; set; }
#endregion
}
}

View File

@@ -13,9 +13,8 @@ namespace WebAPI.dataParsers
public List<Record> parse(IFormFile file)
{
var info = CultureInfo.CurrentCulture;
Console.WriteLine(info);
List<Record> dataRows = new List<Record>();
List<Record> records = new List<Record>();
var stream = new StreamReader(file.OpenReadStream());
string content = stream.ReadToEnd();
@@ -35,20 +34,20 @@ namespace WebAPI.dataParsers
float value = float.Parse(data[j][i], CultureInfo.GetCultureInfo("pl-PL"));
if (value > 0)
{
Record dataRow = new Record();
dataRow.Id = Guid.NewGuid();
dataRow.Code = data[0][i];
dataRow.Desc1 = data[j][0];
dataRow.Value = value;
dataRow.CreatedAt = DateTime.UtcNow;
dataRow.ModifiedAt= DateTime.UtcNow;
dataRows.Add(dataRow);
Record record = new Record();
record.Id = Guid.NewGuid();
record.Code = data[0][i];
record.Desc1 = data[j][0];
record.Value = value;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedAt= DateTime.UtcNow;
records.Add(record);
}
}
};
}
return dataRows;
return records;
}
}
}