refactor: API-Services umgestellt, URLs werden jetzt über den URL-Service bezogen
This commit is contained in:
parent
4d350bf6e8
commit
4a1f3f14da
@ -1,19 +1,28 @@
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Router } from '@angular/router';
|
||||
import Swal from 'sweetalert2';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthenticationService {
|
||||
|
||||
private loginUrl: string;
|
||||
private logoutUrl: string;
|
||||
private checkUrl: string;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private http: HttpClient,
|
||||
@Inject('LOGIN_URL') private loginUrl: string,
|
||||
@Inject('LOGOUT_URL') private logoutUrl: string,
|
||||
@Inject('LOGIN_CHECK_URL') private checkUrl: string) { }
|
||||
urlService : UrlService)
|
||||
{
|
||||
this.loginUrl = urlService.apiRoute.login;
|
||||
this.logoutUrl = urlService.apiRoute.logout;
|
||||
this.checkUrl = urlService.apiRoute.loginCheck;
|
||||
}
|
||||
|
||||
isAuthenticated(): Observable<boolean> {
|
||||
return new Observable(observer => {
|
||||
|
||||
@ -4,13 +4,14 @@ import { DirGroup, } from '../models/user-management.api.models';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import Swal from 'sweetalert2';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DirGroupService extends ApiService<DirGroup> {
|
||||
constructor(http: HttpClient, @Inject('DIR_GROUP_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.dirGroup);
|
||||
}
|
||||
|
||||
//TODO: Swal.fire
|
||||
|
||||
@ -3,13 +3,14 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { DirUser } from '../models/user-management.api.models';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DirUserService extends ApiService<DirUser> {
|
||||
constructor(http: HttpClient, @Inject('DIR_USER_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.dirUser);
|
||||
}
|
||||
|
||||
override getAll(groupName?: string): Observable<DirUser[]> {
|
||||
|
||||
@ -2,13 +2,16 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { DirUser } from '../models/user-management.api.models';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DirService {
|
||||
constructor(private http: HttpClient, @Inject('DIR_URL') private baseUrl: string) {
|
||||
private baseUrl: string
|
||||
constructor(private http: HttpClient, urlService : UrlService) {
|
||||
this.http = http;
|
||||
this.baseUrl = urlService.apiRoute.directory;
|
||||
}
|
||||
|
||||
getUser(groupName: string): Observable<DirUser[]> {
|
||||
|
||||
@ -3,13 +3,14 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { GroupOfUser } from '../models/user-management.api.models';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupOfUserService extends ApiService<GroupOfUser> {
|
||||
constructor(http: HttpClient, @Inject('GROUP_OF_USER_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.groupOfUser);
|
||||
}
|
||||
|
||||
deleteByGroupUserId(groupId: number, userId: number): Observable<any> {
|
||||
|
||||
@ -3,13 +3,14 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { DirGroup, Group, } from '../models/user-management.api.models';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupService extends ApiService<Group> {
|
||||
constructor(http: HttpClient, @Inject('GROUP_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.group);
|
||||
}
|
||||
|
||||
createByDir(createModel: DirGroup): Observable<DirGroup> {
|
||||
|
||||
@ -3,13 +3,14 @@ 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 { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ModuleOfUserService extends ApiService<ModuleOfUser> {
|
||||
constructor(http: HttpClient, @Inject('MODULE_OF_USER_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.moduleOfUser);
|
||||
}
|
||||
|
||||
deleteByModuleGroupId(moduleId: number, userId: number): Observable<any> {
|
||||
|
||||
@ -2,12 +2,13 @@ import { Injectable, Inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Module } from '../models/user-management.api.models';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ModuleService extends ApiService<Module> {
|
||||
constructor(http: HttpClient, @Inject('MODULE_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.module);
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ export class UrlService {
|
||||
return baseElement?.getAttribute('href') || '/';
|
||||
}
|
||||
|
||||
getApiUrl(route: string = ""): string | null {
|
||||
getApiUrl(route: string = ""): string {
|
||||
return env.api_url + route;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,8 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ApiService<Model> {
|
||||
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
|
||||
constructor(http: HttpClient, baseUrl: string) {
|
||||
this.http = http;
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
@ -3,13 +3,14 @@ import { UserRep } from "../models/user-management.api.models";
|
||||
import { ApiService } from "./user-management.api.service";
|
||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { UrlService } from "./url.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root"
|
||||
})
|
||||
export class UserRepService extends ApiService<UserRep> {
|
||||
constructor(http: HttpClient, @Inject('USER_REP_URL') private userRepUri: string) {
|
||||
super(http, userRepUri)
|
||||
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<UserRep[]> {
|
||||
|
||||
@ -3,13 +3,14 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { DirUser, User } from '../models/user-management.api.models';
|
||||
import { ApiService } from './user-management.api.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { UrlService } from './url.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService extends ApiService<User> {
|
||||
constructor(http: HttpClient, @Inject('USER_URL') private userUri: string) {
|
||||
super(http, userUri);
|
||||
constructor(http: HttpClient, urlService : UrlService) {
|
||||
super(http, urlService.apiRoute.user);
|
||||
}
|
||||
|
||||
getByModuleId(moduleId: number, assigned: boolean = true): Observable<User[]> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user