mirror of
https://codeberg.org/beerbrawl/beerbrawl.git
synced 2024-09-23 05:40:51 +02:00
impl comments
This commit is contained in:
parent
938f1ff601
commit
8242cfe7ce
|
@ -70,7 +70,7 @@ public class UserEndpoint {
|
|||
*
|
||||
* @param username to identify the suer to delete
|
||||
*/
|
||||
@DeleteMapping("delete/{username}")
|
||||
@DeleteMapping("{username}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@PreAuthorize("isAuthenticated()") //see JwtAuthFilter UsernamePasswordAuthenticationToken
|
||||
public ResponseEntity<?> delete(@PathVariable(value = "username") String username, Authentication authentication) {
|
||||
|
@ -89,7 +89,7 @@ public class UserEndpoint {
|
|||
* @param username target user for update
|
||||
* @param userUpdate updated user
|
||||
*/
|
||||
@PutMapping("update/{username}")
|
||||
@PutMapping("{username}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public ResponseEntity<?> update(@PathVariable(value = "username") String username, @RequestBody UserLoginDto userUpdate, Authentication authentication) {
|
||||
|
@ -105,17 +105,16 @@ public class UserEndpoint {
|
|||
* Get Username and password for user. ToDo: Add futher info like Num of Tournaments
|
||||
* The target user is retrieved through the JWT
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@GetMapping("/detail/{username}")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public ResponseEntity<UserDetailDto> details(Authentication authentication) {
|
||||
public ResponseEntity<UserDetailDto> details(@PathVariable(value = "username") String username, Authentication authentication) {
|
||||
LOG.info("GET-DETAILS {}", BASE_ENDPOINT);
|
||||
|
||||
var targetUser = authentication.getPrincipal();
|
||||
if (targetUser == null) {
|
||||
return ResponseEntity.status(401).build();
|
||||
if (!username.equals(authentication.getPrincipal())) {
|
||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
var user = userService.findApplicationUserByUsername(targetUser.toString());
|
||||
var user = userService.findApplicationUserByUsername(username);
|
||||
if (user != null) {
|
||||
var dto = UserDetailDto.UserDetailDtoBuilder
|
||||
.anUserDetailDto()
|
||||
|
|
|
@ -18,7 +18,7 @@ const routes: Routes = [
|
|||
canActivate: mapToCanActivate([AuthGuard]),
|
||||
component: TournamentCreateComponent,
|
||||
},
|
||||
{ path: 'user-detail', canActivate: mapToCanActivate([AuthGuard]), component: UserDetailComponent },
|
||||
{ path: 'details/:username', canActivate: mapToCanActivate([AuthGuard]), component: UserDetailComponent },
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
|
|
@ -4,6 +4,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|||
import { LoginDialogComponent } from '../login/login-dialog.component';
|
||||
import { Router } from '@angular/router';
|
||||
import { OpenLoginService } from '../../services/open-login.service';
|
||||
import { UsernameService } from 'src/app/services/user/username.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-header',
|
||||
|
@ -15,6 +16,7 @@ export class HeaderComponent implements OnInit {
|
|||
public authService: AuthService,
|
||||
private router: Router,
|
||||
public openLoginService: OpenLoginService,
|
||||
private usernameService: UsernameService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
@ -25,6 +27,7 @@ export class HeaderComponent implements OnInit {
|
|||
}
|
||||
|
||||
navigateToUserDetail() {
|
||||
this.router.navigate(["/user-detail"])
|
||||
console.log( this.usernameService.getData())
|
||||
this.router.navigate(["/details", this.usernameService.getData()])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { AuthService } from '../../services/auth.service';
|
|||
import { AuthRequest } from '../../dtos/auth-request';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { UsernameService } from 'src/app/services/user/username.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login-dialog',
|
||||
|
@ -23,6 +24,7 @@ export class LoginDialogComponent {
|
|||
private router: Router,
|
||||
private dialogRef: MatDialogRef<LoginDialogComponent>,
|
||||
private snackBar: MatSnackBar,
|
||||
private usernameService: UsernameService,
|
||||
) {
|
||||
this.loginForm = this.formBuilder.group({
|
||||
username: ['', [Validators.required]],
|
||||
|
@ -59,6 +61,7 @@ export class LoginDialogComponent {
|
|||
this.snackBar.open('Successfully logged in', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
this.usernameService.setData(authRequest.username)
|
||||
this.router.navigate(['/message']);
|
||||
},
|
||||
error: error => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Router } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { OpenLoginService } from 'src/app/services/open-login.service';
|
||||
import { UserService } from 'src/app/services/user/user.service';
|
||||
|
@ -20,6 +20,7 @@ export class UserDetailComponent implements OnInit{
|
|||
constructor(
|
||||
//private service: UserService,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private authService: AuthService,
|
||||
private openLoginService: OpenLoginService,
|
||||
private userService: UserService,
|
||||
|
@ -29,16 +30,21 @@ export class UserDetailComponent implements OnInit{
|
|||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.detail().subscribe({
|
||||
next: next => {
|
||||
this.username = next.username;
|
||||
this.password = next.password;
|
||||
},
|
||||
error: error => {
|
||||
console.error('Error deleting user', error);
|
||||
this.defaultServiceErrorHandling(error);
|
||||
}
|
||||
})
|
||||
|
||||
this.route.params.subscribe(params => {
|
||||
this.username = params["username"];
|
||||
console.log(params["username"])
|
||||
this.userService.detail(this.username).subscribe({
|
||||
next: next => {
|
||||
this.username = next.username;
|
||||
this.password = next.password;
|
||||
},
|
||||
error: error => {
|
||||
console.error('Error fetching user data', error);
|
||||
this.defaultServiceErrorHandling(error);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onDelete() {
|
||||
|
|
|
@ -19,21 +19,21 @@ export class UserService {
|
|||
/**
|
||||
* Fetch user information
|
||||
*/
|
||||
detail() : Observable<UserDetail> {
|
||||
return this.httpClient.get<UserDetail>(this.messageBaseUri + `/detail`);
|
||||
detail(username: String) : Observable<UserDetail> {
|
||||
return this.httpClient.get<UserDetail>(this.messageBaseUri + `/detail/${username}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete User and all entities belonging to user.
|
||||
*/
|
||||
delete(username: String) {
|
||||
return this.httpClient.delete(this.messageBaseUri + `/delete/${username}`);
|
||||
return this.httpClient.delete(this.messageBaseUri + `/${username}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update User
|
||||
*/
|
||||
update(updates: AuthRequest, targetUsername: String) {
|
||||
return this.httpClient.put(this.messageBaseUri + `/update/${targetUsername}`, updates);
|
||||
return this.httpClient.put(this.messageBaseUri + `/${targetUsername}`, updates);
|
||||
}
|
||||
}
|
16
frontend/src/app/services/user/username.service.ts
Normal file
16
frontend/src/app/services/user/username.service.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UsernameService {
|
||||
private username: string = "";
|
||||
|
||||
setData(data: string) {
|
||||
this.username = data;
|
||||
}
|
||||
|
||||
getData() : string {
|
||||
return this.username;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue