refactor(user): reorganize imports and code structure
This commit is contained in:
		
					parent
					
						
							
								6c025cc8d2
							
						
					
				
			
			
				commit
				
					
						7bd06dee62
					
				
			
		
					 4 changed files with 22 additions and 20 deletions
				
			
		|  | @ -1,14 +1,20 @@ | ||||||
| package de.szut.casino.user; | package de.szut.casino.user; | ||||||
| 
 | 
 | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.http.HttpHeaders; | ||||||
|  | import org.springframework.http.HttpStatus; | ||||||
|  | import org.springframework.http.ResponseEntity; | ||||||
|  | import org.springframework.web.bind.annotation.GetMapping; | ||||||
|  | import org.springframework.web.bind.annotation.PathVariable; | ||||||
|  | import org.springframework.web.bind.annotation.PostMapping; | ||||||
|  | import org.springframework.web.bind.annotation.RequestBody; | ||||||
|  | import org.springframework.web.bind.annotation.RequestHeader; | ||||||
|  | import org.springframework.web.bind.annotation.RestController; | ||||||
|  | 
 | ||||||
| import de.szut.casino.user.dto.CreateUserDto; | import de.szut.casino.user.dto.CreateUserDto; | ||||||
| import de.szut.casino.user.dto.GetUserDto; | import de.szut.casino.user.dto.GetUserDto; | ||||||
| import jakarta.validation.Valid; | import jakarta.validation.Valid; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.http.HttpHeaders; |  | ||||||
| import org.springframework.http.HttpStatus; |  | ||||||
| import org.springframework.http.ResponseEntity; |  | ||||||
| import org.springframework.web.bind.annotation.*; |  | ||||||
| 
 | 
 | ||||||
| @Slf4j | @Slf4j | ||||||
| @RestController | @RestController | ||||||
|  | @ -22,6 +28,7 @@ public class UserController { | ||||||
|         if (id == null || !userService.exists(id)) { |         if (id == null || !userService.exists(id)) { | ||||||
|             return ResponseEntity.notFound().build(); |             return ResponseEntity.notFound().build(); | ||||||
|         } |         } | ||||||
|  |          | ||||||
|         return ResponseEntity.ok(userService.getUser(id)); |         return ResponseEntity.ok(userService.getUser(id)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,23 +1,18 @@ | ||||||
| package de.szut.casino.user; | package de.szut.casino.user; | ||||||
| 
 | 
 | ||||||
| import de.szut.casino.user.dto.CreateUserDto; | import java.util.Optional; | ||||||
| import de.szut.casino.user.dto.GetUserDto; | 
 | ||||||
| import de.szut.casino.user.dto.KeycloakUserDto; |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.http.HttpEntity; | import org.springframework.http.HttpEntity; | ||||||
|  | import org.springframework.http.HttpHeaders; | ||||||
| import org.springframework.http.HttpMethod; | import org.springframework.http.HttpMethod; | ||||||
| import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||||
| 
 | 
 | ||||||
| import java.net.URI; | import de.szut.casino.user.dto.CreateUserDto; | ||||||
| import java.net.http.HttpClient; | import de.szut.casino.user.dto.GetUserDto; | ||||||
| import org.springframework.http.HttpHeaders; | import de.szut.casino.user.dto.KeycloakUserDto; | ||||||
| import java.net.http.HttpRequest; |  | ||||||
| import java.time.Duration; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.Optional; |  | ||||||
| 
 | 
 | ||||||
| @Service | @Service | ||||||
| public class UserService { | public class UserService { | ||||||
|  | @ -39,8 +34,8 @@ public class UserService { | ||||||
| 
 | 
 | ||||||
|     public GetUserDto getUser(String keycloakId) { |     public GetUserDto getUser(String keycloakId) { | ||||||
|         Optional<UserEntity> user = this.userRepository.findOneByKeycloakId(keycloakId); |         Optional<UserEntity> user = this.userRepository.findOneByKeycloakId(keycloakId); | ||||||
|         return user.map(userEntity -> mappingService.mapToGetUserDto(userEntity)).orElse(null); |  | ||||||
| 
 | 
 | ||||||
|  |         return user.map(userEntity -> mappingService.mapToGetUserDto(userEntity)).orElse(null); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public GetUserDto getCurrentUser(String token) { |     public GetUserDto getCurrentUser(String token) { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| import { Routes } from '@angular/router'; | import { Routes } from '@angular/router'; | ||||||
| import { LandingComponent } from './feature/landing/landing.component'; | import { LandingComponent } from './feature/landing/landing.component'; | ||||||
| import { HomeComponent } from './feature/home/home.component'; |  | ||||||
| import { authGuard } from './auth.guard'; | import { authGuard } from './auth.guard'; | ||||||
| 
 | 
 | ||||||
| export const routes: Routes = [ | export const routes: Routes = [ | ||||||
|  | @ -11,10 +10,10 @@ export const routes: Routes = [ | ||||||
|   { |   { | ||||||
|     path: 'login/success', |     path: 'login/success', | ||||||
|     loadComponent: () => import('./feature/login-success/login-success.component'), |     loadComponent: () => import('./feature/login-success/login-success.component'), | ||||||
|   }, |   },   | ||||||
|   { |   { | ||||||
|     path: 'home', |     path: 'home', | ||||||
|     component: HomeComponent, |     loadComponent: () => import('./feature/home/home.component'), | ||||||
|     canActivate: [authGuard], |     canActivate: [authGuard], | ||||||
|   }, |   }, | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
|  | @ -31,6 +31,7 @@ export class UserService { | ||||||
|         if (user) { |         if (user) { | ||||||
|           return user; |           return user; | ||||||
|         } |         } | ||||||
|  |          | ||||||
|         return await this.createUser(userProfile.id ?? '', userProfile.username ?? '').toPromise(); |         return await this.createUser(userProfile.id ?? '', userProfile.username ?? '').toPromise(); | ||||||
|       }); |       }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Reference in a new issue