diff --git a/Frontend/src/app/app-routing.module.ts b/Frontend/src/app/app-routing.module.ts index 90530f7..bc4a897 100644 --- a/Frontend/src/app/app-routing.module.ts +++ b/Frontend/src/app/app-routing.module.ts @@ -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) }, ] } diff --git a/Frontend/src/app/main-view/main-view.component.html b/Frontend/src/app/main-view/main-view.component.html index 0c92caf..56b22a0 100644 --- a/Frontend/src/app/main-view/main-view.component.html +++ b/Frontend/src/app/main-view/main-view.component.html @@ -29,7 +29,7 @@ dashboard Dashboard - + table Zbiory danych diff --git a/Frontend/src/app/models/dataSet.model.ts b/Frontend/src/app/models/layer.model.ts similarity index 69% rename from Frontend/src/app/models/dataSet.model.ts rename to Frontend/src/app/models/layer.model.ts index ab616f3..b37a999 100644 --- a/Frontend/src/app/models/dataSet.model.ts +++ b/Frontend/src/app/models/layer.model.ts @@ -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 = {}) { + constructor(data: Partial = {}) { 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 { + static add(input: Layer, _http: HttpClient): Promise { return new Promise((resolve, reject) => { - _http.post(`${environment.api.url}/datasets`, { ...input.serialize(), }).subscribe({ + _http.post(`${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(`${environment.api.url}/datasets`) - .pipe(map(data => data.map(x => new DataSet().deserialize(x)))) + _http.get(`${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 { + static getById(id: string, _http: HttpClient): Promise { return new Promise((resolve, reject) => { - _http.get(`${environment.api.url}/datasets/${id}`).pipe(map(x => new DataSet().deserialize(x))).subscribe({ + _http.get(`${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 { + static parseFile(file: any, _http: HttpClient): Promise { const formData = new FormData(); formData.append(file.name, file); return new Promise((resolve, reject) => { - _http.post(`${environment.api.url}/datasets/parseFile`, formData, - ).pipe(map(data => data.map(x => new DataRow().deserialize(x)))) + _http.post(`${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 { + static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise { return new Promise((resolve, reject) => { - _http.get(`${environment.api.url}/datasets/parseGoogleSheet/${sheetId}`, - ).pipe(map(data => new DataSet().deserialize(data))) + _http.get(`${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 { return new Promise((resolve, reject) => { - _http.get(`${environment.api.url}/datasets/exportToGoogleSheet/${id}`, + _http.get(`${environment.api.url}/layers/exportToGoogleSheet/${id}`, ).subscribe({ next: (data) => { resolve(data); diff --git a/Frontend/src/app/models/dataRow.model copy.ts b/Frontend/src/app/models/record.model.ts similarity index 89% rename from Frontend/src/app/models/dataRow.model copy.ts rename to Frontend/src/app/models/record.model.ts index 4399f0d..afc943b 100644 --- a/Frontend/src/app/models/dataRow.model copy.ts +++ b/Frontend/src/app/models/record.model.ts @@ -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 = {}) { + constructor(data: Partial = {}) { super(); Object.assign(this, data); } diff --git a/Frontend/src/app/modules/dashboard/board/board.component.ts b/Frontend/src/app/modules/dashboard/board/board.component.ts index 57157bd..9bc7184 100644 --- a/Frontend/src/app/modules/dashboard/board/board.component.ts +++ b/Frontend/src/app/modules/dashboard/board/board.component.ts @@ -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'] }) diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.spec.ts b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.spec.ts deleted file mode 100644 index 60c1e7f..0000000 --- a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ DataSetDetailComponent ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(DataSetDetailComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.spec.ts b/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.spec.ts deleted file mode 100644 index 7aac256..0000000 --- a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ DataSetEditComponent ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(DataSetEditComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.spec.ts b/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.spec.ts deleted file mode 100644 index b2e4456..0000000 --- a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ DataSetsListComponent ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(DataSetsListComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/Frontend/src/app/modules/data-sets/data-sets-routing.module.ts b/Frontend/src/app/modules/data-sets/data-sets-routing.module.ts deleted file mode 100644 index 39e471a..0000000 --- a/Frontend/src/app/modules/data-sets/data-sets-routing.module.ts +++ /dev/null @@ -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 { } diff --git a/Frontend/src/app/modules/data-sets/data-sets.module.ts b/Frontend/src/app/modules/data-sets/data-sets.module.ts deleted file mode 100644 index 96922c8..0000000 --- a/Frontend/src/app/modules/data-sets/data-sets.module.ts +++ /dev/null @@ -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 { } diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html b/Frontend/src/app/modules/layers/layer-detail/layer-detail.component.html similarity index 100% rename from Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html rename to Frontend/src/app/modules/layers/layer-detail/layer-detail.component.html diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss b/Frontend/src/app/modules/layers/layer-detail/layer-detail.component.scss similarity index 100% rename from Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss rename to Frontend/src/app/modules/layers/layer-detail/layer-detail.component.scss diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts b/Frontend/src/app/modules/layers/layer-detail/layer-detail.component.ts similarity index 64% rename from Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts rename to Frontend/src/app/modules/layers/layer-detail/layer-detail.component.ts index e271b68..81e3d8e 100644 --- a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts +++ b/Frontend/src/app/modules/layers/layer-detail/layer-detail.component.ts @@ -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; + dataSource!: MatTableDataSource; @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(this.document.dataRows); + this.dataSource = new MatTableDataSource(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 { - return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$); + private async load(): Promise { + 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"); diff --git a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.html b/Frontend/src/app/modules/layers/layer-edit/layer-edit.component.html similarity index 100% rename from Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.html rename to Frontend/src/app/modules/layers/layer-edit/layer-edit.component.html diff --git a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.scss b/Frontend/src/app/modules/layers/layer-edit/layer-edit.component.scss similarity index 100% rename from Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.scss rename to Frontend/src/app/modules/layers/layer-edit/layer-edit.component.scss diff --git a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts b/Frontend/src/app/modules/layers/layer-edit/layer-edit.component.ts similarity index 65% rename from Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts rename to Frontend/src/app/modules/layers/layer-edit/layer-edit.component.ts index 1dfbb4f..1cb78dc 100644 --- a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts +++ b/Frontend/src/app/modules/layers/layer-edit/layer-edit.component.ts @@ -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; + dataSource!: MatTableDataSource; @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; } diff --git a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.html b/Frontend/src/app/modules/layers/layers-list/layers-list.component.html similarity index 100% rename from Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.html rename to Frontend/src/app/modules/layers/layers-list/layers-list.component.html diff --git a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.scss b/Frontend/src/app/modules/layers/layers-list/layers-list.component.scss similarity index 100% rename from Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.scss rename to Frontend/src/app/modules/layers/layers-list/layers-list.component.scss diff --git a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.ts b/Frontend/src/app/modules/layers/layers-list/layers-list.component.ts similarity index 64% rename from Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.ts rename to Frontend/src/app/modules/layers/layers-list/layers-list.component.ts index d97fa8a..0949f5f 100644 --- a/Frontend/src/app/modules/data-sets/data-sets-list/data-sets-list.component.ts +++ b/Frontend/src/app/modules/layers/layers-list/layers-list.component.ts @@ -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; + dataSource!: MatTableDataSource; @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; } } diff --git a/Frontend/src/app/modules/layers/layers-routing.module.ts b/Frontend/src/app/modules/layers/layers-routing.module.ts new file mode 100644 index 0000000..67cdc72 --- /dev/null +++ b/Frontend/src/app/modules/layers/layers-routing.module.ts @@ -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 { } diff --git a/Frontend/src/app/modules/layers/layers.module.ts b/Frontend/src/app/modules/layers/layers.module.ts new file mode 100644 index 0000000..cec47d4 --- /dev/null +++ b/Frontend/src/app/modules/layers/layers.module.ts @@ -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 { } diff --git a/Frontend/src/environments/environment.ts b/Frontend/src/environments/environment.ts index 511c096..9acd79a 100644 --- a/Frontend/src/environments/environment.ts +++ b/Frontend/src/environments/environment.ts @@ -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" diff --git a/WebAPI/AppDbContext.cs b/WebAPI/AppDbContext.cs index 2497739..6e563d1 100644 --- a/WebAPI/AppDbContext.cs +++ b/WebAPI/AppDbContext.cs @@ -7,8 +7,8 @@ namespace WebAPI public class AppDbContext : DbContext { public DbSet Users { get; set; } - public DbSet DataSets { get; set; } - public DbSet DataRows { get; set; } + public DbSet Layers { get; set; } + public DbSet Records { get; set; } public AppDbContext(DbContextOptions options) : base(options) { diff --git a/WebAPI/Controllers/LayersController.cs b/WebAPI/Controllers/LayersController.cs index aae5d21..f595dc1 100644 --- a/WebAPI/Controllers/LayersController.cs +++ b/WebAPI/Controllers/LayersController.cs @@ -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 dataRows, Guid currentUserId) + private void SaveRecords(Guid id, ICollection records, Guid currentUserId) { try { List ids = new List(); - 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) diff --git a/WebAPI/Exports/googleSheet.export.cs b/WebAPI/Exports/googleSheet.export.cs index 9ce07f6..ba40244 100644 --- a/WebAPI/Exports/googleSheet.export.cs +++ b/WebAPI/Exports/googleSheet.export.cs @@ -15,14 +15,14 @@ namespace WebAPI.Exports googleDriveHelper = _googleDriveHelper; googleSheetValues = _googleSheetValues; } - public void export(Layer dataSet) + public void export(Layer layer) { try { - List> data = new List>() { new List() { dataSet.Name, dataSet.Number } }; - foreach (Record dataRow in dataSet.Records) + List> data = new List>() { new List() { layer.Name!, layer.Number! } }; + foreach (Record record in layer.Records!) { - data.Add(new List { dataRow.Code, dataRow.Value }); + data.Add(new List { record.Code!, record.Value }); } Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File(); diff --git a/WebAPI/Migrations/20230106095427_RenameModels.Designer.cs b/WebAPI/Migrations/20230106095427_RenameModels.Designer.cs new file mode 100644 index 0000000..386d9a2 --- /dev/null +++ b/WebAPI/Migrations/20230106095427_RenameModels.Designer.cs @@ -0,0 +1,199 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Number") + .IsRequired() + .HasColumnType("int"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc2") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc3") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc4") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc5") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("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 + } + } +} diff --git a/WebAPI/Migrations/20230106095427_RenameModels.cs b/WebAPI/Migrations/20230106095427_RenameModels.cs new file mode 100644 index 0000000..0e542ec --- /dev/null +++ b/WebAPI/Migrations/20230106095427_RenameModels.cs @@ -0,0 +1,227 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebAPI.Migrations +{ + /// + public partial class RenameModels : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DataRows"); + + migrationBuilder.DropTable( + name: "DataSets"); + + migrationBuilder.CreateTable( + name: "Layers", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Number = table.Column(type: "int", nullable: false), + Source = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(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(type: "uniqueidentifier", nullable: false), + Code = table.Column(type: "nvarchar(max)", nullable: false), + Value = table.Column(type: "real", nullable: false), + Desc1 = table.Column(type: "nvarchar(max)", nullable: true), + Desc2 = table.Column(type: "nvarchar(max)", nullable: true), + Desc3 = table.Column(type: "nvarchar(max)", nullable: true), + Desc4 = table.Column(type: "nvarchar(max)", nullable: true), + Desc5 = table.Column(type: "nvarchar(max)", nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + LayerId = table.Column(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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Records"); + + migrationBuilder.DropTable( + name: "Layers"); + + migrationBuilder.CreateTable( + name: "DataSets", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Number = table.Column(type: "int", nullable: false), + Source = table.Column(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(type: "uniqueidentifier", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + Code = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + DataSetId = table.Column(type: "uniqueidentifier", nullable: false), + Desc1 = table.Column(type: "nvarchar(max)", nullable: true), + Desc2 = table.Column(type: "nvarchar(max)", nullable: true), + Desc3 = table.Column(type: "nvarchar(max)", nullable: true), + Desc4 = table.Column(type: "nvarchar(max)", nullable: true), + Desc5 = table.Column(type: "nvarchar(max)", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + Value = table.Column(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"); + } + } +} diff --git a/WebAPI/Migrations/AppDbContextModelSnapshot.cs b/WebAPI/Migrations/AppDbContextModelSnapshot.cs index e177aae..dcff365 100644 --- a/WebAPI/Migrations/AppDbContextModelSnapshot.cs +++ b/WebAPI/Migrations/AppDbContextModelSnapshot.cs @@ -22,64 +22,7 @@ namespace WebAPI.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("WebAPI.Models.DataRow", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Code") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedById") - .HasColumnType("uniqueidentifier"); - - b.Property("DataSetId") - .HasColumnType("uniqueidentifier"); - - b.Property("Desc1") - .HasColumnType("nvarchar(max)"); - - b.Property("Desc2") - .HasColumnType("nvarchar(max)"); - - b.Property("Desc3") - .HasColumnType("nvarchar(max)"); - - b.Property("Desc4") - .HasColumnType("nvarchar(max)"); - - b.Property("Desc5") - .HasColumnType("nvarchar(max)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("ModifiedAt") - .HasColumnType("datetime2"); - - b.Property("ModifiedById") - .HasColumnType("uniqueidentifier"); - - b.Property("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("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc2") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc3") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc4") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc5") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("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 } diff --git a/WebAPI/Models/Record.cs b/WebAPI/Models/Record.cs index 4f0109f..3669a78 100644 --- a/WebAPI/Models/Record.cs +++ b/WebAPI/Models/Record.cs @@ -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 } } diff --git a/WebAPI/dataParsers/csv.parser.cs b/WebAPI/dataParsers/csv.parser.cs index 3eb57d5..2ea2785 100644 --- a/WebAPI/dataParsers/csv.parser.cs +++ b/WebAPI/dataParsers/csv.parser.cs @@ -13,9 +13,8 @@ namespace WebAPI.dataParsers public List parse(IFormFile file) { var info = CultureInfo.CurrentCulture; - Console.WriteLine(info); - List dataRows = new List(); + List records = new List(); 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; } } }