feat: Frontend- und Backend-APIs aktualisiert, um Module basierend auf der Benutzerauswahl zu filtern

This commit is contained in:
Developer 02
2024-07-25 11:42:17 +02:00
parent 19ba6f0da9
commit e3f4b78083
12 changed files with 69 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import { ColorModeService } from '../../../services/color-mode.service';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { env } from '../../../../environments/environment';
import { ModuleOfUserService } from '../../../services/module-of-user.service';
@Component({
standalone: true,
@@ -17,7 +18,13 @@ import { env } from '../../../../environments/environment';
})
export class ModuleTableComponent extends BaseTableComponent<Module, ModuleService> {
constructor(
service: ModuleService, cModeService: ColorModeService) {
service: ModuleService, cModeService: ColorModeService, private mouService: ModuleOfUserService) {
super(service, env.columnNames.module, cModeService)
}
fetchDataByUsername(username: string) {
this.mouService.getByUsername(username)
.then(mou_list => mou_list.map(mou => mou.module))
.then(modules => this.source = modules)
}
}

View File

@@ -34,6 +34,10 @@ export class UserComponent implements AfterViewInit {
this.refreshService.removeAll()
this.refreshService.add(() => {
this.userTable.fetchData();
if (this.sUsername != null){
this.groupTable.fetchDataByUsername(this.sUsername);
this.moduleTable.fetchDataByUsername(this.sUsername)
}
});
}
@@ -45,8 +49,10 @@ export class UserComponent implements AfterViewInit {
if (rows.length > 0) {
this.sUsername = rows[0].source.username;
if (this.sUsername != null)
if (this.sUsername != null){
this.groupTable.fetchDataByUsername(this.sUsername);
this.moduleTable.fetchDataByUsername(this.sUsername)
}
}
}
}

View File

@@ -40,6 +40,7 @@ export interface ModuleOfUser {
comment?: string;
addedWho?: string;
changedWho?: string;
module?: Module;
}
export interface GroupOfUser {

View File

@@ -2,7 +2,7 @@ import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ModuleOfUser } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { Observable } from 'rxjs';
import { Observable, firstValueFrom } from 'rxjs';
import { UrlService } from './url.service';
@Injectable({
@@ -17,4 +17,9 @@ export class ModuleOfUserService extends ApiService<ModuleOfUser> {
const url = `${this.baseUrl}?moduleId=${moduleId}&userId=${userId}`;
return this.http.delete<any>(url, { withCredentials: true });
}
async getByUsername(username: string): Promise<ModuleOfUser[]> {
const url = `${this.baseUrl}?username=${username}`;
return await firstValueFrom(this.http.get<ModuleOfUser[]>(url, { withCredentials: true }));
}
}

View File

@@ -23,7 +23,7 @@ namespace DigitalData.UserManager.API.Controllers
return await _service.DeleteAsyncByGroupUserId(groupId, userId).ThenAsync(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return BadRequest();
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch (Exception ex)

View File

@@ -14,7 +14,24 @@ namespace DigitalData.UserManager.API.Controllers
public ModuleOfUserController(ILogger<ModuleOfUserController> logger, IModuleOfUserService service) : base(logger, service)
{
}
[NonAction]
public override Task<IActionResult> GetAll() => base.GetAll();
[HttpGet]
public async Task<IActionResult> GetAll(string? username = null)
{
if (username is not null)
return await _service.ReadByUserAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status500InternalServerError);
});
return await base.GetAll();
}
[HttpDelete]
public async Task<IActionResult> Delete([FromQuery] int moduleId, [FromQuery]int userId)
{