From dc22f1b045cba291af36306d989824cfc468af28 Mon Sep 17 00:00:00 2001 From: flo Date: Sat, 4 Jan 2025 04:17:53 +0100 Subject: [PATCH] weedkeeper changes --- src/app/app.component.ts | 2 +- src/app/app.module.ts | 8 +- src/app/core/auth/auth.module.ts | 6 + .../auth/components/auth/auth.component.ts | 2 +- .../confirm-registration.component.ts | 2 +- .../forgot-password.component.ts | 2 +- .../auth/components/login/login.component.ts | 4 +- .../registration/registration.component.ts | 4 +- .../reset-password.component.ts | 2 +- src/app/core/{ => auth}/guards/auth.guard.ts | 0 .../models/confirm-registration.model.ts} | 0 .../models/forgot-password.model.ts} | 2 +- .../models/login-user.model.ts} | 6 +- .../models/logout-user.model.ts} | 2 +- .../models/register-user.model.ts} | 6 +- .../models/reset-password.model.ts} | 6 +- src/app/core/auth/services/auth.service.ts | 86 ++++++++++++ src/app/core/core.module.ts | 4 - .../navigation/navigation.component.ts | 10 +- .../components/settings/settings.component.ts | 4 +- .../tab-security/tab-security.component.ts | 9 +- src/app/core/home/home.module.ts | 2 +- src/app/core/services/auth.service.ts | 122 ------------------ .../models/change-password.model.ts} | 4 +- .../models/change-username.model.ts} | 4 +- src/app/core/user/models/create.model.ts | 14 ++ src/app/core/user/models/read-list.model.ts | 18 +++ .../models/state.model.ts} | 3 +- src/app/core/user/services/user.service.ts | 54 ++++++++ src/app/core/user/user.module.ts | 21 +++ 30 files changed, 245 insertions(+), 164 deletions(-) rename src/app/core/{ => auth}/guards/auth.guard.ts (100%) rename src/app/core/{models/confirm-registration-request.model.ts => auth/models/confirm-registration.model.ts} (100%) rename src/app/core/{models/forgot-password-request.model.ts => auth/models/forgot-password.model.ts} (83%) rename src/app/core/{models/login-request.model.ts => auth/models/login-user.model.ts} (54%) rename src/app/core/{models/logout-request.model.ts => auth/models/logout-user.model.ts} (71%) rename src/app/core/{models/register-user-request.model.ts => auth/models/register-user.model.ts} (55%) rename src/app/core/{models/reset-password-request.model.ts => auth/models/reset-password.model.ts} (50%) create mode 100644 src/app/core/auth/services/auth.service.ts delete mode 100644 src/app/core/services/auth.service.ts rename src/app/core/{models/change-password-request.model.ts => user/models/change-password.model.ts} (66%) rename src/app/core/{models/change-username-request.model.ts => user/models/change-username.model.ts} (66%) create mode 100644 src/app/core/user/models/create.model.ts create mode 100644 src/app/core/user/models/read-list.model.ts rename src/app/core/{models/user-state-request.model.ts => user/models/state.model.ts} (75%) create mode 100644 src/app/core/user/services/user.service.ts create mode 100644 src/app/core/user/user.module.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6e2d87d..2d3d68f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import { AuthService } from "./core/services/auth.service"; +import { AuthService } from "./core/auth/services/auth.service"; import { TranslateService } from "@ngx-translate/core"; @Component({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2e9badd..9d69ab3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,9 @@ import { SharedModule } from "./shared/shared.module"; import { CoreModule } from "./core/core.module"; import { AngularSvgIconModule } from 'angular-svg-icon'; import { DatePipe } from "@angular/common"; +import { AuthService } from "./core/auth/services/auth.service"; +import { AuthGuard } from "./core/auth/guards/auth.guard"; +import { UserService } from "./core/user/services/user.service"; const routes: Routes = [ { @@ -50,7 +53,10 @@ export function createTranslateLoader(http: HttpClient) { providers: [ provideHttpClient(withInterceptorsFromDi()), TranslatePipe, - DatePipe + DatePipe, + AuthGuard, + AuthService, + UserService, ], }) export class AppModule {} diff --git a/src/app/core/auth/auth.module.ts b/src/app/core/auth/auth.module.ts index e126ed9..e4a29a6 100644 --- a/src/app/core/auth/auth.module.ts +++ b/src/app/core/auth/auth.module.ts @@ -12,6 +12,8 @@ import { SharedModule } from "src/app/shared/shared.module"; import { CoreModule } from "../core.module"; import { AuthComponent } from "./components/auth/auth.component"; import { AngularSvgIconModule } from "angular-svg-icon"; +import { AuthService } from "./services/auth.service"; +import { AuthGuard } from "./guards/auth.guard"; const routes: Routes = [ { @@ -53,5 +55,9 @@ const routes: Routes = [ SharedModule, CoreModule ], + providers: [ + AuthGuard, + AuthService, + ] }) export class AuthModule {} diff --git a/src/app/core/auth/components/auth/auth.component.ts b/src/app/core/auth/components/auth/auth.component.ts index c7fd40a..4b3f651 100644 --- a/src/app/core/auth/components/auth/auth.component.ts +++ b/src/app/core/auth/components/auth/auth.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from "@angular/core"; import { ActivatedRoute, NavigationEnd, Router } from "@angular/router"; import { initFlowbite } from "flowbite"; import { filter, map } from "rxjs"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-auth", diff --git a/src/app/core/auth/components/confirm-registration/confirm-registration.component.ts b/src/app/core/auth/components/confirm-registration/confirm-registration.component.ts index 1753f09..528e390 100644 --- a/src/app/core/auth/components/confirm-registration/confirm-registration.component.ts +++ b/src/app/core/auth/components/confirm-registration/confirm-registration.component.ts @@ -1,7 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-confirm-registration", diff --git a/src/app/core/auth/components/forgot-password/forgot-password.component.ts b/src/app/core/auth/components/forgot-password/forgot-password.component.ts index cf19bcc..e64c970 100644 --- a/src/app/core/auth/components/forgot-password/forgot-password.component.ts +++ b/src/app/core/auth/components/forgot-password/forgot-password.component.ts @@ -1,7 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; import { Router } from "@angular/router"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-forgot-password", diff --git a/src/app/core/auth/components/login/login.component.ts b/src/app/core/auth/components/login/login.component.ts index eeda3c9..2952f6f 100644 --- a/src/app/core/auth/components/login/login.component.ts +++ b/src/app/core/auth/components/login/login.component.ts @@ -1,7 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; import { Router } from "@angular/router"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-login", @@ -19,7 +19,7 @@ export class LoginComponent { } login(): void { - this.authService.login({ + this.authService.loginUser({ identifier: this.loginForm.value.identifier!, password: this.loginForm.value.password!, }).subscribe(response => { diff --git a/src/app/core/auth/components/registration/registration.component.ts b/src/app/core/auth/components/registration/registration.component.ts index 1c4d447..9cd0e93 100644 --- a/src/app/core/auth/components/registration/registration.component.ts +++ b/src/app/core/auth/components/registration/registration.component.ts @@ -1,7 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; import { Router } from "@angular/router"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-registration", @@ -19,7 +19,7 @@ export class RegistrationComponent { } register(): void { - this.authService.register({ + this.authService.registerUser({ mail: this.registrationForm.value.mail!, username: this.registrationForm.value.username!, }).subscribe(response => { diff --git a/src/app/core/auth/components/reset-password/reset-password.component.ts b/src/app/core/auth/components/reset-password/reset-password.component.ts index 09988d7..20cdd87 100644 --- a/src/app/core/auth/components/reset-password/reset-password.component.ts +++ b/src/app/core/auth/components/reset-password/reset-password.component.ts @@ -3,7 +3,7 @@ import { FormControl, FormGroup, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; import { initFlowbite } from "flowbite"; import { filter } from "rxjs"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; @Component({ selector: "app-reset-password", diff --git a/src/app/core/guards/auth.guard.ts b/src/app/core/auth/guards/auth.guard.ts similarity index 100% rename from src/app/core/guards/auth.guard.ts rename to src/app/core/auth/guards/auth.guard.ts diff --git a/src/app/core/models/confirm-registration-request.model.ts b/src/app/core/auth/models/confirm-registration.model.ts similarity index 100% rename from src/app/core/models/confirm-registration-request.model.ts rename to src/app/core/auth/models/confirm-registration.model.ts diff --git a/src/app/core/models/forgot-password-request.model.ts b/src/app/core/auth/models/forgot-password.model.ts similarity index 83% rename from src/app/core/models/forgot-password-request.model.ts rename to src/app/core/auth/models/forgot-password.model.ts index 95d83c3..a4606b5 100644 --- a/src/app/core/models/forgot-password-request.model.ts +++ b/src/app/core/auth/models/forgot-password.model.ts @@ -1,5 +1,5 @@ export interface ForgotPasswordRequest { - mail: string; + mail: string; } export interface ForgotPasswordResponse { diff --git a/src/app/core/models/login-request.model.ts b/src/app/core/auth/models/login-user.model.ts similarity index 54% rename from src/app/core/models/login-request.model.ts rename to src/app/core/auth/models/login-user.model.ts index 7d4d58e..1d96f82 100644 --- a/src/app/core/models/login-request.model.ts +++ b/src/app/core/auth/models/login-user.model.ts @@ -1,8 +1,8 @@ export interface LoginUserRequest { - identifier: string; - password: string; + identifier: string; + password: string; } export interface LoginUserResponse { - sessionId: string; + sessionId: string; } diff --git a/src/app/core/models/logout-request.model.ts b/src/app/core/auth/models/logout-user.model.ts similarity index 71% rename from src/app/core/models/logout-request.model.ts rename to src/app/core/auth/models/logout-user.model.ts index 0bbb074..cedd5aa 100644 --- a/src/app/core/models/logout-request.model.ts +++ b/src/app/core/auth/models/logout-user.model.ts @@ -2,5 +2,5 @@ export interface LogoutUserRequest { } export interface LogoutUserResponse { - response?: string|undefined; + response: string; } diff --git a/src/app/core/models/register-user-request.model.ts b/src/app/core/auth/models/register-user.model.ts similarity index 55% rename from src/app/core/models/register-user-request.model.ts rename to src/app/core/auth/models/register-user.model.ts index 4a1df17..4c48f78 100644 --- a/src/app/core/models/register-user-request.model.ts +++ b/src/app/core/auth/models/register-user.model.ts @@ -1,8 +1,8 @@ export interface RegisterUserRequest { - username: string; - mail: string; + username: string; + mail: string; } export interface RegisterUserResponse { - response?: string|undefined; + response: string; } diff --git a/src/app/core/models/reset-password-request.model.ts b/src/app/core/auth/models/reset-password.model.ts similarity index 50% rename from src/app/core/models/reset-password-request.model.ts rename to src/app/core/auth/models/reset-password.model.ts index d45ebf6..8a7ad76 100644 --- a/src/app/core/models/reset-password-request.model.ts +++ b/src/app/core/auth/models/reset-password.model.ts @@ -1,7 +1,7 @@ export interface ResetPasswordRequest { - passwordToken: string; - newPassword: string; - passwordConfirmation: string; + passwordToken: string; + newPassword: string; + passwordConfirmation: string; } export interface ResetPasswordResponse { diff --git a/src/app/core/auth/services/auth.service.ts b/src/app/core/auth/services/auth.service.ts new file mode 100644 index 0000000..77a2bc5 --- /dev/null +++ b/src/app/core/auth/services/auth.service.ts @@ -0,0 +1,86 @@ +import { Injectable } from "@angular/core"; +import { BehaviorSubject, catchError, Observable } from "rxjs"; +import { RequestService } from "src/app/core/services/request.service"; +import { LoginUserRequest, LoginUserResponse } from '../models/login-user.model'; +import { LogoutUserRequest, LogoutUserResponse } from '../models/logout-user.model'; +import { ConfirmRegistrationRequest, ConfirmRegistrationResponse } from '../models/confirm-registration.model'; +import { RegisterUserRequest, RegisterUserResponse } from '../models/register-user.model'; +import { ForgotPasswordRequest, ForgotPasswordResponse } from '../models/forgot-password.model'; +import { ResetPasswordRequest, ResetPasswordResponse } from '../models/reset-password.model'; +import { StateResponse } from "../../user/models/state.model"; + +@Injectable() +export class AuthService { + currentState$ = new BehaviorSubject( + undefined + ); + + constructor(private requestService: RequestService) {} + + readUserState() + { + return this.requestService.request( + 'get', + this.requestService.obtainUrl("user/state"), + {} + ) + .pipe( + catchError( + error => { + this.currentState$.next(undefined); + throw 'User State not readable'; + } + ) + ); + } + + + + loginUser(body: LoginUserRequest): Observable { + return this.requestService.call( + 'post', + 'auth/login-user', + body + ); + } + + logoutUser(body: LogoutUserRequest): Observable { + return this.requestService.call( + 'get', + 'auth/logout-user', + body + ); + } + + confirmRegistration(body: ConfirmRegistrationRequest): Observable { + return this.requestService.call( + 'post', + 'auth/confirm-registration', + body + ); + } + + registerUser(body: RegisterUserRequest): Observable { + return this.requestService.call( + 'post', + 'auth/register-user', + body + ); + } + + forgotPassword(body: ForgotPasswordRequest): Observable { + return this.requestService.call( + 'post', + 'auth/forgot-password', + body + ); + } + + resetPassword(body: ResetPasswordRequest): Observable { + return this.requestService.call( + 'post', + 'auth/reset-password', + body + ); + } +} \ No newline at end of file diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 3e68725..e61a7dc 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -1,7 +1,5 @@ import { NgModule } from "@angular/core"; import { CommonModule } from "@angular/common"; -import { AuthGuard } from "./guards/auth.guard"; -import { AuthService } from "./services/auth.service"; import { RequestService } from "./services/request.service"; import { AppService } from "./services/app.service"; import { SharedModule } from "../shared/shared.module"; @@ -34,8 +32,6 @@ import { ThemePickerComponent } from "./components/theme-picker/theme-picker.com TranslateModule, ], providers: [ - AuthGuard, - AuthService, RequestService, AppService, NotificationService, diff --git a/src/app/core/home/components/navigation/navigation.component.ts b/src/app/core/home/components/navigation/navigation.component.ts index a84613d..b25886c 100644 --- a/src/app/core/home/components/navigation/navigation.component.ts +++ b/src/app/core/home/components/navigation/navigation.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit } from "@angular/core"; import { initFlowbite } from "flowbite"; import { Router } from "@angular/router"; -import { StateResponse } from "src/app/core/models/user-state-request.model"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; +import { StateResponse } from "src/app/core/user/models/state.model"; +import { UserService } from "src/app/core/user/services/user.service"; interface NavigationLink { imageSrc?: string; @@ -57,12 +58,13 @@ export class NavigationComponent implements OnInit { state: StateResponse | undefined; constructor( + private userService: UserService, private authService: AuthService, private router: Router, ) { this.state = undefined; - this.authService.readUserState().subscribe(response => { + this.userService.state({}).subscribe(response => { this.authService.currentState$.next(response); this.state = response; }); @@ -74,7 +76,7 @@ export class NavigationComponent implements OnInit { logout(): void { this.authService - .logout() + .logoutUser({}) .subscribe( response => { this.state = undefined; this.router.navigateByUrl('/') diff --git a/src/app/core/home/components/settings/settings.component.ts b/src/app/core/home/components/settings/settings.component.ts index 50028d7..8d53a3b 100644 --- a/src/app/core/home/components/settings/settings.component.ts +++ b/src/app/core/home/components/settings/settings.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from "@angular/core"; import { initFlowbite } from "flowbite"; -import { StateResponse } from "src/app/core/models/user-state-request.model"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; +import { StateResponse } from "src/app/core/user/models/state.model"; @Component({ selector: "app-settings", diff --git a/src/app/core/home/components/settings/tabs/tab-security/tab-security.component.ts b/src/app/core/home/components/settings/tabs/tab-security/tab-security.component.ts index d5f3277..8341bc7 100644 --- a/src/app/core/home/components/settings/tabs/tab-security/tab-security.component.ts +++ b/src/app/core/home/components/settings/tabs/tab-security/tab-security.component.ts @@ -1,6 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; -import { AuthService } from "src/app/core/services/auth.service"; +import { AuthService } from "src/app/core/auth/services/auth.service"; +import { UserService } from "src/app/core/user/services/user.service"; @Component({ selector: "app-tab-security", @@ -20,20 +21,20 @@ export class TabSecurityComponent { newUsername: new FormControl("", [Validators.required]), }); - constructor(private authService: AuthService) {} + constructor(private userService: UserService) {} changePassword(): void { if (this.changePasswordForm.value.newPassword !== this.changePasswordForm.value.newPasswordConfirmation) return; - this.authService.changePassword({ + this.userService.changePassword({ password: this.changePasswordForm.value.password!, newPassword: this.changePasswordForm.value.newPassword!, }).subscribe(response => {}); } changeUsername(): void { - this.authService.changeUsername({ + this.userService.changeUsername({ password: this.changeUsernameForm.value.password!, newUsername: this.changeUsernameForm.value.newUsername!, }).subscribe(response => {}); diff --git a/src/app/core/home/home.module.ts b/src/app/core/home/home.module.ts index 9aa300b..0c1f324 100644 --- a/src/app/core/home/home.module.ts +++ b/src/app/core/home/home.module.ts @@ -6,12 +6,12 @@ import { TranslateModule } from "@ngx-translate/core"; import { SharedModule } from "src/app/shared/shared.module"; import { AngularSvgIconModule } from "angular-svg-icon"; import { HomeComponent } from "./components/home/home.component"; -import { AuthGuard } from "../guards/auth.guard"; import { SettingsComponent } from "./components/settings/settings.component"; import { TabProfileComponent } from "./components/settings/tabs/tab-profile/tab-profile.component"; import { TabSecurityComponent } from "./components/settings/tabs/tab-security/tab-security.component"; import { NavigationComponent } from "./components/navigation/navigation.component"; import { CoreModule } from "../core.module"; +import { AuthGuard } from "../auth/guards/auth.guard"; const routes: Routes = [ { diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts deleted file mode 100644 index a4a296d..0000000 --- a/src/app/core/services/auth.service.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { Injectable } from "@angular/core"; -import { RequestService } from "./request.service"; -import { StateResponse } from "../models/user-state-request.model"; -import { BehaviorSubject, catchError, Observable } from "rxjs"; -import { LoginUserRequest, LoginUserResponse } from "../models/login-request.model"; -import { Router } from "@angular/router"; -import { - RegisterUserRequest, - RegisterUserResponse, -} from "../models/register-user-request.model"; -import { - ConfirmRegistrationRequest, - ConfirmRegistrationResponse, -} from "../models/confirm-registration-request.model"; -import { - ResetPasswordRequest, - ResetPasswordResponse, -} from "../models/reset-password-request.model"; -import { - ForgotPasswordRequest, - ForgotPasswordResponse, -} from "../models/forgot-password-request.model"; -import { - ChangePasswordRequest, - ChangePasswordResponse, -} from "../models/change-password-request.model"; -import { - ChangeUsernameRequest, - ChangeUsernameResponse, -} from "../models/change-username-request.model"; -import { LogoutUserResponse } from "../models/logout-request.model"; - -@Injectable() -export class AuthService { - currentState$ = new BehaviorSubject( - undefined - ); - - constructor(private requestService: RequestService, private router: Router) {} - - readUserState() - { - return this.requestService.request( - 'get', - this.requestService.obtainUrl("user/state"), - {} - ) - .pipe( - catchError( - error => { - this.currentState$.next(undefined); - throw 'User State not readable'; - } - ) - ); - } - - logout(): Observable { - this.currentState$.next(undefined); - return this.requestService.call( - "get", - "auth/logout-user", - {} - ); - } - - login(body: LoginUserRequest): Observable { - return this.requestService.call( - 'post', - "auth/login-user", - body - ); - } - - register(body: RegisterUserRequest): Observable { - return this.requestService.call( - "post", - "auth/register-user", - body, - ); - } - - confirmRegistration(body: ConfirmRegistrationRequest): Observable { - return this.requestService.call( - 'post', - 'auth/confirm-registration', - body, - ); - } - - resetPassword(body: ResetPasswordRequest): Observable { - return this.requestService.call( - "post", - "auth/reset-password", - body, - ); - } - - forgotPassword(body: ForgotPasswordRequest): Observable { - return this.requestService.call( - 'post', - "auth/forgot-password", - body, - ); - } - - changePassword(body: ChangePasswordRequest): Observable { - return this.requestService.call( - 'post', - "user/change-password", - body, - ); - } - - changeUsername(body: ChangeUsernameRequest): Observable { - return this.requestService.call( - 'post', - "user/change-username", - body, - ); - } -} diff --git a/src/app/core/models/change-password-request.model.ts b/src/app/core/user/models/change-password.model.ts similarity index 66% rename from src/app/core/models/change-password-request.model.ts rename to src/app/core/user/models/change-password.model.ts index d612faf..a95b5be 100644 --- a/src/app/core/models/change-password-request.model.ts +++ b/src/app/core/user/models/change-password.model.ts @@ -1,6 +1,6 @@ export interface ChangePasswordRequest { - password: string; - newPassword: string; + password: string; + newPassword: string; } export interface ChangePasswordResponse { diff --git a/src/app/core/models/change-username-request.model.ts b/src/app/core/user/models/change-username.model.ts similarity index 66% rename from src/app/core/models/change-username-request.model.ts rename to src/app/core/user/models/change-username.model.ts index 1137d5b..24893b1 100644 --- a/src/app/core/models/change-username-request.model.ts +++ b/src/app/core/user/models/change-username.model.ts @@ -1,6 +1,6 @@ export interface ChangeUsernameRequest { - password: string; - newUsername: string; + password: string; + newUsername: string; } export interface ChangeUsernameResponse { diff --git a/src/app/core/user/models/create.model.ts b/src/app/core/user/models/create.model.ts new file mode 100644 index 0000000..eaa8708 --- /dev/null +++ b/src/app/core/user/models/create.model.ts @@ -0,0 +1,14 @@ +export interface CreateRequest { + username: string; + mail: string; + password: string; +} + +export interface CreateResponse { + id: string; + username: string; + role: "admin"|"user"; + permissions: string[]; + createdAt: string; + updatedAt: string; +} diff --git a/src/app/core/user/models/read-list.model.ts b/src/app/core/user/models/read-list.model.ts new file mode 100644 index 0000000..0657c82 --- /dev/null +++ b/src/app/core/user/models/read-list.model.ts @@ -0,0 +1,18 @@ +export interface ReadListRequest { + page: number; + perPage: number; + query: string|null; +} + +export interface ReadListResponse { + total: number; + items: ReadListResponseItem[]; +} + +export interface ReadListResponseItem { + id: string; + role: "admin"|"user"; + username: string; + mail: string; + lastLoginAt: string|null; +} diff --git a/src/app/core/models/user-state-request.model.ts b/src/app/core/user/models/state.model.ts similarity index 75% rename from src/app/core/models/user-state-request.model.ts rename to src/app/core/user/models/state.model.ts index 634a869..dd98b2a 100644 --- a/src/app/core/models/user-state-request.model.ts +++ b/src/app/core/user/models/state.model.ts @@ -4,10 +4,9 @@ export interface StateRequest { export interface StateResponse { id: string; username: string; - roleIdentifier: any|null; + roleIdentifier: "admin"|"user"; permissions: string[]; createdAt: string; updatedAt: string; sessionId: string; - role?: "admin"|"user"|undefined; } diff --git a/src/app/core/user/services/user.service.ts b/src/app/core/user/services/user.service.ts new file mode 100644 index 0000000..d1a1653 --- /dev/null +++ b/src/app/core/user/services/user.service.ts @@ -0,0 +1,54 @@ +import { Injectable } from "@angular/core"; +import { Observable } from "rxjs"; +import { RequestService } from "src/app/core/services/request.service"; +import { CreateRequest, CreateResponse } from '../models/create.model'; +import { ChangePasswordRequest, ChangePasswordResponse } from '../models/change-password.model'; +import { ChangeUsernameRequest, ChangeUsernameResponse } from '../models/change-username.model'; +import { ReadListRequest, ReadListResponse } from '../models/read-list.model'; +import { StateRequest, StateResponse } from '../models/state.model'; + +@Injectable() +export class UserService { + constructor(private requestService: RequestService) { + } + + create(body: CreateRequest): Observable { + return this.requestService.call( + 'post', + 'user/create', + body + ); + } + + changePassword(body: ChangePasswordRequest): Observable { + return this.requestService.call( + 'post', + 'user/change-password', + body + ); + } + + changeUsername(body: ChangeUsernameRequest): Observable { + return this.requestService.call( + 'post', + 'user/change-username', + body + ); + } + + readList(body: ReadListRequest): Observable { + return this.requestService.call( + 'post', + 'user/read-list', + body + ); + } + + state(body: StateRequest): Observable { + return this.requestService.call( + 'get', + 'user/state', + body + ); + } +} \ No newline at end of file diff --git a/src/app/core/user/user.module.ts b/src/app/core/user/user.module.ts new file mode 100644 index 0000000..fdc5cc6 --- /dev/null +++ b/src/app/core/user/user.module.ts @@ -0,0 +1,21 @@ +import { NgModule } from "@angular/core"; +import { CommonModule } from "@angular/common"; +import { CoreModule } from "../core.module"; +import { UserService } from "./services/user.service"; + + + +@NgModule({ + declarations: [ + ], + exports: [ + ], + imports: [ + CommonModule, + CoreModule + ], + providers: [ + UserService, + ] +}) +export class UserModule {}