feat: Frontend- und Backend-APIs aktualisiert, um Module basierend auf der Benutzerauswahl zu filtern
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ export interface ModuleOfUser {
|
||||
comment?: string;
|
||||
addedWho?: string;
|
||||
changedWho?: string;
|
||||
module?: Module;
|
||||
}
|
||||
|
||||
export interface GroupOfUser {
|
||||
|
||||
@@ -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 }));
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -8,5 +8,7 @@ namespace DigitalData.UserManager.Application.Contracts
|
||||
public interface IModuleOfUserService : ICRUDService<ModuleOfUserCreateDto, ModuleOfUserReadDto, ModuleOfUserUpdateDto, ModuleOfUser, int>
|
||||
{
|
||||
Task<Result> DeleteAsyncByModuleUserId(int moduleId, int userId);
|
||||
|
||||
Task<DataResult<IEnumerable<ModuleOfUserReadDto>>> ReadByUserAsync(string username);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace DigitalData.UserManager.Application.DTOs.ModuleOfUser
|
||||
using DigitalData.UserManager.Application.DTOs.Module;
|
||||
using DigitalData.UserManager.Application.DTOs.User;
|
||||
|
||||
namespace DigitalData.UserManager.Application.DTOs.ModuleOfUser
|
||||
{
|
||||
public record ModuleOfUserReadDto(
|
||||
int Id,
|
||||
@@ -6,6 +9,8 @@
|
||||
int ModuleId,
|
||||
string? Comment,
|
||||
string? AddedWho,
|
||||
string? ChangedWho
|
||||
string? ChangedWho,
|
||||
UserReadDto User,
|
||||
ModuleDto? Module
|
||||
);
|
||||
}
|
||||
@@ -26,5 +26,12 @@ namespace DigitalData.UserManager.Application.Services
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
public async Task<DataResult<IEnumerable<ModuleOfUserReadDto>>> ReadByUserAsync(string username)
|
||||
{
|
||||
var mous = await _repository.ReadByUserAsync(username: username);
|
||||
var mous_dtos = _mapper.MapOrThrow<IEnumerable<ModuleOfUserReadDto>>(mous);
|
||||
return Result.Success(mous_dtos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,7 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
|
||||
IQueryable<ModuleOfUser> ReadByModuleId(int moduleId);
|
||||
|
||||
Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId);
|
||||
|
||||
Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
|
||||
public async Task<IEnumerable<GroupOfUser>> ReadByGroupUserIdAsync(int groupId, int userId)
|
||||
{
|
||||
return await _dbSet.Where<GroupOfUser>(gou => gou.GroupId == groupId && gou.UserId == userId).ToListAsync();
|
||||
return await _dbSet.Where(gou => gou.GroupId == groupId && gou.UserId == userId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroup() => await _dbSet.Include(gou => gou.Group).ToListAsync();
|
||||
|
||||
@@ -12,14 +12,21 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
{
|
||||
}
|
||||
|
||||
private IQueryable<ModuleOfUser> ReadByUser(string username)
|
||||
{
|
||||
return _dbSet.Where(mou => mou.User!.Username == username).Include(mou => mou.Module);
|
||||
}
|
||||
|
||||
public IQueryable<ModuleOfUser> ReadByModuleId(int moduleId)
|
||||
{
|
||||
return _dbSet.Where<ModuleOfUser>(mou => mou.ModuleId == moduleId);
|
||||
return _dbSet.Where(mou => mou.ModuleId == moduleId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId)
|
||||
{
|
||||
return await _dbSet.Where<ModuleOfUser>(mou => mou.ModuleId == moduleId && mou.UserId == userId).ToListAsync();
|
||||
return await _dbSet.Where(mou => mou.ModuleId == moduleId && mou.UserId == userId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username) => await ReadByUser(username).ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user