From 25a4b0752b57c53149bf08b36ea875a3a21c1e4a Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 9 Sep 2024 17:25:12 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20Entfernen=20der=20right=5Fgroup-Eig?= =?UTF-8?q?enschaft=20aus=20der=20Representation-Entit=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Die Spalte `right_group` aus der `Representation`-Entität entfernt, um die Zuordnung von Benutzern oder Gruppen zu spezifischen Gruppen zu entfernen. - Stattdessen wurde die `group`-Eigenschaft hinzugefügt, um flexible Zuordnungen zu ermöglichen. - Ermöglicht nun `user-user`, `user-group`, `group-user` und `group-group` Repräsentationen. --- .../user-rep-table.component.ts | 6 +- .../app/models/user-management.api.models.ts | 4 +- .../user-representation.component.html | 13 ++--- .../user-representation.component.ts | 55 ++++++++----------- .../api/user-representation.service.ts | 46 ++++++++++------ .../src/environments/environment.ts | 4 -- .../Controllers/UserRepController.cs | 4 +- .../Contracts/IUserRepService.cs | 2 +- .../DTOs/UserRep/UserRepCreateDto.cs | 3 +- .../DTOs/UserRep/UserRepReadDto.cs | 4 +- .../DTOs/UserRep/UserRepUpdateDto.cs | 2 +- .../Services/UserRepService.cs | 4 +- .../Entities/UserRep.cs | 9 ++- .../Contracts/IUserRepRepository.cs | 2 +- .../Repositories/UserRepRepository.cs | 13 +++-- 15 files changed, 86 insertions(+), 85 deletions(-) diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/user-rep-table/user-rep-table.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/user-rep-table/user-rep-table.component.ts index 329f60d..08ea2a1 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/user-rep-table/user-rep-table.component.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/user-rep-table/user-rep-table.component.ts @@ -22,13 +22,13 @@ export class UserRepTableComponent extends BaseTableComponent { this.source = response; this.loading = false; }, - error: (error: any) => {} + error: (error: any) => { } }); } } \ No newline at end of file diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts index 6432d19..4d0198e 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts @@ -58,12 +58,12 @@ export interface UserRep { id?: number, userId: number, repGroupId?: number, - rightGroupId: number, + groupId?: number, addedWho: string, repUserId?: number, user?: User, repGroup?: Group, - rightGroup?: Group, + group?: Group, repUser?: User } diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.html b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.html index cb3096b..9b1892d 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.html +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.html @@ -7,10 +7,13 @@ + + + -
+
@@ -20,14 +23,6 @@
- -
- - - - - -
diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts index c671597..dc94308 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/pages/user-representation/user-representation.component.ts @@ -8,6 +8,7 @@ import Swal from 'sweetalert2'; import { MatTabsModule, MatTabGroup } from '@angular/material/tabs'; import { env } from '../../../environments/environment'; import { BasePageComponent } from '../base-page/base-page.component'; +import { UserRep } from '../../models/user-management.api.models'; @Component({ standalone: true, @@ -19,8 +20,8 @@ import { BasePageComponent } from '../base-page/base-page.component'; export class UserRepresentationComponent extends BasePageComponent implements AfterViewInit { useRepLabel: string = ""; + groupColumns: Array; groupRepCols: Array; - groupRightColumns: Array; slUserId: null | number = null; slRepUserId: null | number = null; slRepGroupId: null | number = null; @@ -32,7 +33,7 @@ export class UserRepresentationComponent extends BasePageComponent implements Af constructor(private userRepService: UserRepService) { super() this.groupRepCols = env.columnNames.group.representative; - this.groupRightColumns = env.columnNames.group.right; + this.groupColumns = env.columnNames.group.right; this.userRepService = userRepService; } @@ -43,7 +44,7 @@ export class UserRepresentationComponent extends BasePageComponent implements Af this.users.fetchData(); this.repUsers.fetchData(); this.repGroups.fetchData(); - this.rightGroups.fetchData(); + this.groups.fetchData(); }) this.transferService.add(() => { this.repUsers.safelyUnselectAll(); @@ -53,26 +54,34 @@ export class UserRepresentationComponent extends BasePageComponent implements Af } @ViewChild("users") users!: UserTableComponent; + @ViewChild("groups") groups!: GroupTableComponent; @ViewChild("repUsers") repUsers!: UserTableComponent; @ViewChild("repGroups") repGroups!: GroupTableComponent; - @ViewChild("rightGroups") rightGroups!: GroupTableComponent; @ViewChild("userReps") userReps!: UserRepTableComponent; - userOnSelectedRows = (rows: GuiSelectedRow[]) => { + userGroupOnSelectedRows = (rows: GuiSelectedRow[], isUser: boolean = true) => { if (rows.length > 0) { this.users.safelyUnselectAll(); - this.useRepLabel = `Vertretungen von ${rows[0].source?.username}` - this.userReps.fetchData(rows[0].source?.id) - this.slUserId = rows[0].source?.id + + if (isUser) { + this.useRepLabel = `Vertretungen von ${rows[0].source?.username}` + this.userReps.fetchData(rows[0].source?.id) + this.slUserId = rows[0].source?.id + } + else { + this.useRepLabel = `Vertretungen von ${rows[0].source?.name}` + this.userReps.fetchData(undefined, rows[0].source?.id) + this.slUserId = rows[0].source?.id + } } } - rightGroupOnSelectedRows = (rows: GuiSelectedRow[]) => { - if (rows.length > 0) { - this.slRightGroupId = rows[0].source?.id - } else { - this.slRightGroupId = null; - } + userOnSelectedRows = (rows: GuiSelectedRow[]) => { + this.userGroupOnSelectedRows(rows, true); + } + + groupOnSelectedRows = (rows: GuiSelectedRow[]) => { + this.userGroupOnSelectedRows(rows, false); } repUserOnSelectedRows = (rows: GuiSelectedRow[]) => { @@ -91,17 +100,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af text: "Bitte wählen Sie die Vertretungen Benutzer!", }); } - else if (!this.slRightGroupId) { - Swal.fire({ - icon: "error", - title: "Oops...", - text: "Bitte wählen Sie die Rechte Gruppe!", - }); - } else { - var newUserRep = { + var newUserRep: UserRep = { userId: this.slUserId, - rightGroupId: this.slRightGroupId, repUserId: this.slRepUserId, addedWho: 'DEFAULT' } @@ -145,17 +146,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af text: "Bitte wählen Sie die Vertretungen Gruppe!", }); } - else if (!this.slRightGroupId) { - Swal.fire({ - icon: "error", - title: "Oops...", - text: "Bitte wählen Sie die rechte Gruppe!", - }); - } else { var newUserRep = { userId: this.slUserId, - rightGroupId: this.slRightGroupId, repGroupId: this.slRepGroupId, addedWho: 'DEFAULT' } diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/user-representation.service.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/user-representation.service.ts index c40d44e..a6d9aba 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/user-representation.service.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/api/user-representation.service.ts @@ -9,28 +9,42 @@ import { UrlService } from "./url.service"; providedIn: "root" }) export class UserRepService extends ApiService { - constructor(http: HttpClient, urlService : UrlService) { + constructor(http: HttpClient, urlService: UrlService) { super(http, urlService.apiRoute.userRep) } - override getAll(withUser: boolean = false, withRepGroup: boolean = false, withRightGroup: boolean = false, withRepUser: boolean = false, userId?: number): Observable { + override getAll(options?: Options): Observable { let params = new HttpParams(); - if (withUser) { - params = params.set('withUser', withUser); - } - if (withRepGroup) { - params = params.set('withRepGroup', withRepGroup); - } - if (withRightGroup) { - params = params.set('withRightGroup', withRightGroup); - } - if (withRepUser) { - params = params.set('withRepUser', withRepUser); - } - if (userId) { - params = params.set('userId', userId) + if (options) { + if (options.withUser) { + params = params.set('withUser', options.withUser); + } + if (options.withRepGroup) { + params = params.set('withRepGroup', options.withRepGroup); + } + if (options.withGroup) { + params = params.set('withRightGroup', options.withGroup); + } + if (options.withRepUser) { + params = params.set('withRepUser', options.withRepUser); + } + if (options.userId) { + params = params.set('userId', options.userId) + } + if (options.groupId) { + params = params.set('groupId', options.groupId) + } } return this.http.get(`${this.baseUrl}`, { params: params, withCredentials: true }); } +} + +interface Options { + withUser: boolean; + withRepGroup: boolean; + withGroup: boolean; + withRepUser: boolean; + userId?: number; + groupId?: number; } \ No newline at end of file diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.ts index a6180a7..4c6deb3 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.ts @@ -189,10 +189,6 @@ export const env = { header: "Repr. Gruppen", field: (ur: any) => ur.repGroup?.name }, - { - header: "Rechte Gruppen", - field: (ur: any) => ur.rightGroup?.name - }, { header: "Repr. Benutzer", field: (ur: any) => ur.repUser?.username diff --git a/DigitalData.UserManager.API/Controllers/UserRepController.cs b/DigitalData.UserManager.API/Controllers/UserRepController.cs index 0b4c35d..7a7286b 100644 --- a/DigitalData.UserManager.API/Controllers/UserRepController.cs +++ b/DigitalData.UserManager.API/Controllers/UserRepController.cs @@ -21,11 +21,11 @@ namespace DigitalData.UserManager.API.Controllers } [HttpGet] - public async Task GetAll(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null) + public async Task GetAll(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null) { try { - return await _service.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId).ThenAsync(Ok, IActionResult (m, n) => + return await _service.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId).ThenAsync(Ok, IActionResult (m, n) => { _logger.LogNotice(n); return NotFound(); diff --git a/DigitalData.UserManager.Application/Contracts/IUserRepService.cs b/DigitalData.UserManager.Application/Contracts/IUserRepService.cs index baccf5b..bd8e361 100644 --- a/DigitalData.UserManager.Application/Contracts/IUserRepService.cs +++ b/DigitalData.UserManager.Application/Contracts/IUserRepService.cs @@ -6,6 +6,6 @@ namespace DigitalData.UserManager.Application.Contracts { public interface IUserRepService : IBaseService { - Task>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null); + Task>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null); } } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepCreateDto.cs b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepCreateDto.cs index 6b22e40..26972e0 100644 --- a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepCreateDto.cs +++ b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepCreateDto.cs @@ -5,8 +5,7 @@ namespace DigitalData.UserManager.Application.DTOs.UserRep public record UserRepCreateDto( int UserId, int? RepGroupId, - int RightGroupId, - string AddedWho, + int? GroupId, int RepUserId ) : BaseCreateDto(); } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepReadDto.cs b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepReadDto.cs index 9b9c71d..0cc8948 100644 --- a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepReadDto.cs +++ b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepReadDto.cs @@ -8,13 +8,13 @@ namespace DigitalData.UserManager.Application.DTOs.UserRep int Id, int UserId, int? RepGroupId, - int RightGroupId, + int? GroupId, string AddedWho, string ChangedWho, int? RepUserId, UserReadDto? User, GroupReadDto? RepGroup, - GroupReadDto? RightGroup, + GroupReadDto? Group, UserReadDto? RepUser, DateTime? AddedWhen, DateTime? ChangedWhen diff --git a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepUpdateDto.cs b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepUpdateDto.cs index 02ffc0b..713d817 100644 --- a/DigitalData.UserManager.Application/DTOs/UserRep/UserRepUpdateDto.cs +++ b/DigitalData.UserManager.Application/DTOs/UserRep/UserRepUpdateDto.cs @@ -5,7 +5,7 @@ namespace DigitalData.UserManager.Application.DTOs.UserRep public record UserRepUpdateDto( int UserId, int? RepGroupId, - int RightGroupId, + int? GroupId, int RepUserId ) : BaseUpdateDto(); } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/Services/UserRepService.cs b/DigitalData.UserManager.Application/Services/UserRepService.cs index d6454d5..d7c1423 100644 --- a/DigitalData.UserManager.Application/Services/UserRepService.cs +++ b/DigitalData.UserManager.Application/Services/UserRepService.cs @@ -15,9 +15,9 @@ namespace DigitalData.UserManager.Application.Services { } - public async Task>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null) + public async Task>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null) { - var urs = await _repository.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId); + var urs = await _repository.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId); var urReadDTOs = _mapper.MapOrThrow>(urs); return Result.Success(urReadDTOs); } diff --git a/DigitalData.UserManager.Domain/Entities/UserRep.cs b/DigitalData.UserManager.Domain/Entities/UserRep.cs index f19fe80..f4c8293 100644 --- a/DigitalData.UserManager.Domain/Entities/UserRep.cs +++ b/DigitalData.UserManager.Domain/Entities/UserRep.cs @@ -14,9 +14,8 @@ namespace DigitalData.UserManager.Domain.Entities [Column("REPR_GROUP")] public int? RepGroupId { get; set; } - [Required] - [Column("RIGHT_GROUP")] - public int RightGroupId { get; set; } + [Column("GROUP_ID")] + public int? GroupId { get; set; } = null; [Column("REPR_USER")] public int? RepUserId { get; set; } @@ -27,8 +26,8 @@ namespace DigitalData.UserManager.Domain.Entities [ForeignKey("RepGroupId")] public virtual Group? RepGroup { get; set; } - [ForeignKey("RightGroupId")] - public virtual Group? RightGroup { get; set; } + [ForeignKey("GroupId")] + public virtual Group? Group { get; set; } [ForeignKey("RepUserId")] public virtual User? RepUser { get; set; } diff --git a/DigitalData.UserManager.Infrastructure/Contracts/IUserRepRepository.cs b/DigitalData.UserManager.Infrastructure/Contracts/IUserRepRepository.cs index 388e8e7..8747124 100644 --- a/DigitalData.UserManager.Infrastructure/Contracts/IUserRepRepository.cs +++ b/DigitalData.UserManager.Infrastructure/Contracts/IUserRepRepository.cs @@ -5,6 +5,6 @@ namespace DigitalData.UserManager.Infrastructure.Contracts { public interface IUserRepRepository : ICRUDRepository { - Task> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null); + Task> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null); } } \ No newline at end of file diff --git a/DigitalData.UserManager.Infrastructure/Repositories/UserRepRepository.cs b/DigitalData.UserManager.Infrastructure/Repositories/UserRepRepository.cs index 66995ec..5d1a28a 100644 --- a/DigitalData.UserManager.Infrastructure/Repositories/UserRepRepository.cs +++ b/DigitalData.UserManager.Infrastructure/Repositories/UserRepRepository.cs @@ -12,9 +12,9 @@ namespace DigitalData.UserManager.Infrastructure.Repositories { } - public async Task> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null) + public async Task> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null) { - var query = _dbSet.AsQueryable(); + var query = _dbSet.AsNoTracking(); if (withUser) query = query.Include(ur => ur.User); @@ -22,8 +22,8 @@ namespace DigitalData.UserManager.Infrastructure.Repositories if (withRepGroup) query = query.Include(ur => ur.RepGroup); - if (withRightGroup) - query = query.Include(ur => ur.RightGroup); + if (withGroup) + query = query.Include(ur => ur.Group); if (withRepUser) query = query.Include(ur => ur.RepUser); @@ -33,6 +33,11 @@ namespace DigitalData.UserManager.Infrastructure.Repositories query = query.Where(ur => ur.UserId == userId); } + if (groupId is not null) + { + query = query.Where(ur => ur.GroupId == groupId); + } + return await query.ToListAsync(); } }