edit and delete changes

This commit is contained in:
2023-05-07 12:15:47 +02:00
parent ccdd691ec6
commit cd79fed789
5 changed files with 19 additions and 14 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,6 +1,11 @@
export interface UserEntity {
id?: number;
id: number;
username: string;
password: string;
admin?: boolean;
}
export interface newUser {
username: string;
password: string;
}

View File

@@ -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<UserEntity>(GET_USER_BY_ID + "/" + id);
}
createUser(user: UserEntity) {
createUser(user: newUser) {
console.log("create " + user);
return this.http.post<UserEntity>(USER, user);
@@ -52,6 +52,6 @@ export class UserService {
}
deleteUser(id: number) {
return this.http.delete<UserEntity>(USER + id);
return this.http.delete<UserEntity>(USER+"/" + id);
}
}

View File

@@ -44,6 +44,6 @@ export class WaypointService {
}
deleteWaypoint(id: number) {
return this.http.delete<WaypointsEntity>(WAYPOINT + id);
return this.http.delete<WaypointsEntity>(WAYPOINT+"/" + id);
}
}