From cd79fed7892e6b26e34ae64528b0bc7af53d4821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sun, 7 May 2023 12:15:47 +0200 Subject: [PATCH] edit and delete changes --- src/app/component/login/login.component.ts | 4 ++-- .../component/management/management.component.ts | 14 +++++++------- src/app/interface/UserEntity.ts | 7 ++++++- src/app/service/http/user.service.ts | 6 +++--- src/app/service/http/waypoint.service.ts | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/app/component/login/login.component.ts b/src/app/component/login/login.component.ts index 3d6c50a..3bcd943 100644 --- a/src/app/component/login/login.component.ts +++ b/src/app/component/login/login.component.ts @@ -4,7 +4,7 @@ import {TranslateService} from "../../service/language/translate.service"; import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service"; import {cookieService} from "../../service/cookie.service"; import {UserService} from "../../service/http/user.service"; -import {UserEntity} from "../../interface/UserEntity"; +import {newUser, UserEntity} from "../../interface/UserEntity"; import {loginTranslations} from "../../interface/translations"; @Component({ @@ -35,7 +35,7 @@ export class LoginComponent implements OnInit { this.loginTranslation = this.readTranslationJsonService.getLoginTranslations(); } - createNewUser(createUser: UserEntity) { + createNewUser(createUser: newUser) { console.log(createUser.username+" "+createUser.password); if (createUser.username == '' || createUser.password == '') { this.errorCreateUser = true; diff --git a/src/app/component/management/management.component.ts b/src/app/component/management/management.component.ts index 5a317a7..25faa9a 100644 --- a/src/app/component/management/management.component.ts +++ b/src/app/component/management/management.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {UserEntity} from "../../interface/UserEntity"; +import {newUser, UserEntity} from "../../interface/UserEntity"; import {LocationEntity} from "../../interface/LocationEntity"; import {newWaypoint, WaypointsEntity} from "../../interface/WaypointsEntity"; import {Router} from "@angular/router"; @@ -24,7 +24,7 @@ export class ManagementComponent implements OnInit { showLocationForm: boolean = false; showWaypointForm: boolean = false; - newUser: UserEntity = {password: "", username: ""}; + newUser: newUser = {password: "", username: ""}; newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""}; newWaypoint: newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""}; @@ -133,11 +133,11 @@ export class ManagementComponent implements OnInit { }); } - // editUser(user: UserEntity) { - // this.userService.updateUser(user, user.id).subscribe(user => { - // this.users?.splice(this.users?.indexOf(user), 1, user); - // }); - // } + editUser(user: UserEntity) { + this.userService.updateUser(user, user.id).subscribe(user => { + this.users?.splice(this.users?.indexOf(user), 1, user); + }); + } openEditLocationForm(location: LocationEntity) { this.newLocation = location; diff --git a/src/app/interface/UserEntity.ts b/src/app/interface/UserEntity.ts index 43e8afd..0ffa1ab 100644 --- a/src/app/interface/UserEntity.ts +++ b/src/app/interface/UserEntity.ts @@ -1,6 +1,11 @@ export interface UserEntity { - id?: number; + id: number; username: string; password: string; admin?: boolean; } + +export interface newUser { + username: string; + password: string; +} diff --git a/src/app/service/http/user.service.ts b/src/app/service/http/user.service.ts index 26bb379..74ad295 100644 --- a/src/app/service/http/user.service.ts +++ b/src/app/service/http/user.service.ts @@ -1,6 +1,6 @@ import {Injectable} from "@angular/core"; import {HttpClient} from "@angular/common/http"; -import {UserEntity} from "../../interface/UserEntity"; +import {newUser, UserEntity} from "../../interface/UserEntity"; import {catchError, of} from "rxjs"; const BASE_URL = "progetto152"; @@ -41,7 +41,7 @@ export class UserService { return this.http.get(GET_USER_BY_ID + "/" + id); } - createUser(user: UserEntity) { + createUser(user: newUser) { console.log("create " + user); return this.http.post(USER, user); @@ -52,6 +52,6 @@ export class UserService { } deleteUser(id: number) { - return this.http.delete(USER + id); + return this.http.delete(USER+"/" + id); } } diff --git a/src/app/service/http/waypoint.service.ts b/src/app/service/http/waypoint.service.ts index 0a67d1b..53550f3 100644 --- a/src/app/service/http/waypoint.service.ts +++ b/src/app/service/http/waypoint.service.ts @@ -44,6 +44,6 @@ export class WaypointService { } deleteWaypoint(id: number) { - return this.http.delete(WAYPOINT + id); + return this.http.delete(WAYPOINT+"/" + id); } }