Add version handling

This commit is contained in:
Peter
2023-10-06 12:14:31 +02:00
parent bba6229c2b
commit 10e0894dcf
10 changed files with 95 additions and 22 deletions

View File

@@ -1,16 +1,22 @@
// package com.rossa.api.controllers; package com.rossa.api.controllers;
// import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod;
// import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;
// import org.springframework.web.servlet.ModelAndView; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
// @Controller @RestController
// public class AppContoller { @PreAuthorize("isAuthenticated()")
// @RequestMapping(value = "/public/index", method = RequestMethod.GET) public class AppContoller {
// public ModelAndView index() {
// ModelAndView retVal = new ModelAndView(); @Value("${rossatech.api.version}")
// retVal.setViewName("indexPage"); private String apiVersion;
// return retVal;
// } @RequestMapping(value = "/version", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
// } public String getApiVersion() {
return apiVersion;
}
}

View File

@@ -19,3 +19,6 @@ spring.jackson.serialization.fail-on-empty-beans=false
# spring.security.user.name=pezi # spring.security.user.name=pezi
# spring.security.user.password=Password123! # spring.security.user.password=Password123!
security.basic.enabled=false security.basic.enabled=false
#api version
rossatech.api.version=0.2

View File

@@ -1,3 +1,8 @@
INSTALL MAVEN: https://mkyong.com/maven/how-to-install-maven-in-windows/
build API: mvn package // oder mvn clean package?!?
- login (simple) - login (simple)
? - https://www.bezkoder.com/angular-12-jwt-auth/ ? - https://www.bezkoder.com/angular-12-jwt-auth/
? - https://martinelli.ch/angular-15-spring-boot-3-and-jwt/ ? - https://martinelli.ch/angular-15-spring-boot-3-and-jwt/

View File

@@ -1,8 +1,18 @@
<div class="footer-wrapper" *ngIf="userLoggedIn"> <div class="footer-wrapper" *ngIf="userLoggedIn">
<div class="version-web" *ngIf="versionWeb"> <div class="version-web" *ngIf="versionWeb">
Web: v{{versionWeb}} <span class="label">
Web:
</span>
<span class="version">
v.{{versionWeb}}
</span>
</div> </div>
<div class="version-api" *ngIf="versionApi"> <div class="version-api" *ngIf="versionApi">
API: v{{versionApi}} <span class="label">
API:
</span>
<span class="version">
v.{{versionApi}}
</span>
</div> </div>
</div> </div>

View File

@@ -5,4 +5,17 @@ div.footer-wrapper {
justify-content: flex-end; justify-content: flex-end;
padding-right: 16px; padding-right: 16px;
align-items: center; align-items: center;
div.version-api {
margin-left: 16px;
}
span.version {
font-size: 12px;
font-style: italic;
}
span.label {
font-size: 12px;
font-weight: bold;
}
} }

View File

@@ -4,6 +4,7 @@ import { HttpErrorResponse } from '@angular/common/http';
import { LoaderService } from '../loader/loader.service'; import { LoaderService } from '../loader/loader.service';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { AuthService } from 'src/app/auth/auth.service'; import { AuthService } from 'src/app/auth/auth.service';
import { DatabaseService } from 'src/app/core/services/database.service';
@Component({ @Component({
selector: 'app-footer', selector: 'app-footer',
@@ -14,11 +15,12 @@ import { AuthService } from 'src/app/auth/auth.service';
}) })
export class FooterComponent implements OnInit { export class FooterComponent implements OnInit {
versionWeb: number | undefined = environment.version; versionWeb: number | undefined = environment.version;
versionApi: number | undefined; versionApi: string | undefined;
userLoggedIn: Boolean = false; userLoggedIn: Boolean = false;
//injects //injects
private authService: AuthService = inject(AuthService); private authService: AuthService = inject(AuthService);
private databaseService: DatabaseService = inject(DatabaseService);
// private loaderService: LoaderService = inject(LoaderService); // private loaderService: LoaderService = inject(LoaderService);
constructor() {} constructor() {}
@@ -27,5 +29,18 @@ export class FooterComponent implements OnInit {
this.authService.isLoggedIn.subscribe((res) => { this.authService.isLoggedIn.subscribe((res) => {
this.userLoggedIn = res; this.userLoggedIn = res;
}); });
this.getApiVersion();
if (this.userLoggedIn) {
this.databaseService.getApiVersion();
}
}
getApiVersion(): void {
this.databaseService.apiVersion.subscribe({
next: (value) => {
this.versionApi = value;
},
});
} }
} }

View File

@@ -9,6 +9,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import { LoaderService } from '../loader/loader.service'; import { LoaderService } from '../loader/loader.service';
import { FormsService } from 'src/app/core/services/forms.service'; import { FormsService } from 'src/app/core/services/forms.service';
import { NotificationService } from 'src/app/core/services/notification.service'; import { NotificationService } from 'src/app/core/services/notification.service';
import { DatabaseService } from 'src/app/core/services/database.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@@ -29,6 +30,7 @@ export class LoginComponent implements OnInit {
private notificationService: NotificationService = private notificationService: NotificationService =
inject(NotificationService); inject(NotificationService);
private router: Router = inject(Router); private router: Router = inject(Router);
private dataBaseService: DatabaseService = inject(DatabaseService);
constructor() {} constructor() {}
@@ -65,6 +67,7 @@ export class LoginComponent implements OnInit {
resp.tokenValue.trim() !== '' resp.tokenValue.trim() !== ''
) { ) {
this.loginService.setSessionCurrentUser(resp); this.loginService.setSessionCurrentUser(resp);
this.dataBaseService.getApiVersion();
this.router.navigate(['/']); this.router.navigate(['/']);
} }
}, },

View File

@@ -4,7 +4,7 @@ import {
HttpErrorResponse, HttpErrorResponse,
HttpHeaders, HttpHeaders,
} from '@angular/common/http'; } from '@angular/common/http';
import { Observable, throwError } from 'rxjs'; import { BehaviorSubject, Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators'; import { catchError } from 'rxjs/operators';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Meter, MeterData } from '../dataModels/Meterdata'; import { Meter, MeterData } from '../dataModels/Meterdata';
@@ -15,7 +15,13 @@ import { Meter, MeterData } from '../dataModels/Meterdata';
export class DatabaseService { export class DatabaseService {
private baseUrl = environment.apiBaseUrl; private baseUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) {} private apiVersionSubject: BehaviorSubject<string> =
new BehaviorSubject<string>('');
public apiVersion: Observable<string>;
constructor(private http: HttpClient) {
this.apiVersion = this.apiVersionSubject.asObservable();
}
getMeterData(): Observable<MeterData[]> { getMeterData(): Observable<MeterData[]> {
const url = `${this.baseUrl}/meter-data`; const url = `${this.baseUrl}/meter-data`;
@@ -55,4 +61,16 @@ export class DatabaseService {
// Return an observable with a user-facing error message. // Return an observable with a user-facing error message.
return throwError(() => error); return throwError(() => error);
} }
public getApiVersion(): void {
const url = `${this.baseUrl}/version`;
this.http
.get<string>(url)
.pipe(catchError(this.handleError))
.subscribe({
next: (value) => {
this.apiVersionSubject.next(value);
},
});
}
} }

View File

@@ -2,5 +2,5 @@ export const environment = {
production: true, production: true,
env: 'prod', env: 'prod',
apiBaseUrl: 'http://192.168.178.21:8182/api', apiBaseUrl: 'http://192.168.178.21:8182/api',
version: 0.2, version: 0.3,
}; };

View File

@@ -6,7 +6,7 @@ export const environment = {
production: false, production: false,
env: 'local', env: 'local',
apiBaseUrl: 'http://localhost:8080', apiBaseUrl: 'http://localhost:8080',
version: 0.2, version: 0.4,
// apiBaseUrl: 'http://192.168.178.21:8182/api', // apiBaseUrl: 'http://192.168.178.21:8182/api',
}; };