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.RequestMethod;
// import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
// @Controller
// public class AppContoller {
// @RequestMapping(value = "/public/index", method = RequestMethod.GET)
// public ModelAndView index() {
// ModelAndView retVal = new ModelAndView();
// retVal.setViewName("indexPage");
// return retVal;
// }
// }
@RestController
@PreAuthorize("isAuthenticated()")
public class AppContoller {
@Value("${rossatech.api.version}")
private String apiVersion;
@RequestMapping(value = "/version", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public String getApiVersion() {
return apiVersion;
}
}

View File

@@ -18,4 +18,7 @@ spring.jackson.serialization.fail-on-empty-beans=false
# spring.security.user.name=pezi
# 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)
? - https://www.bezkoder.com/angular-12-jwt-auth/
? - https://martinelli.ch/angular-15-spring-boot-3-and-jwt/

View File

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

View File

@@ -5,4 +5,17 @@ div.footer-wrapper {
justify-content: flex-end;
padding-right: 16px;
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 { environment } from 'src/environments/environment';
import { AuthService } from 'src/app/auth/auth.service';
import { DatabaseService } from 'src/app/core/services/database.service';
@Component({
selector: 'app-footer',
@@ -14,11 +15,12 @@ import { AuthService } from 'src/app/auth/auth.service';
})
export class FooterComponent implements OnInit {
versionWeb: number | undefined = environment.version;
versionApi: number | undefined;
versionApi: string | undefined;
userLoggedIn: Boolean = false;
//injects
private authService: AuthService = inject(AuthService);
private databaseService: DatabaseService = inject(DatabaseService);
// private loaderService: LoaderService = inject(LoaderService);
constructor() {}
@@ -27,5 +29,18 @@ export class FooterComponent implements OnInit {
this.authService.isLoggedIn.subscribe((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 { FormsService } from 'src/app/core/services/forms.service';
import { NotificationService } from 'src/app/core/services/notification.service';
import { DatabaseService } from 'src/app/core/services/database.service';
@Component({
selector: 'app-root',
@@ -29,6 +30,7 @@ export class LoginComponent implements OnInit {
private notificationService: NotificationService =
inject(NotificationService);
private router: Router = inject(Router);
private dataBaseService: DatabaseService = inject(DatabaseService);
constructor() {}
@@ -65,6 +67,7 @@ export class LoginComponent implements OnInit {
resp.tokenValue.trim() !== ''
) {
this.loginService.setSessionCurrentUser(resp);
this.dataBaseService.getApiVersion();
this.router.navigate(['/']);
}
},

View File

@@ -4,7 +4,7 @@ import {
HttpErrorResponse,
HttpHeaders,
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { BehaviorSubject, Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Meter, MeterData } from '../dataModels/Meterdata';
@@ -15,7 +15,13 @@ import { Meter, MeterData } from '../dataModels/Meterdata';
export class DatabaseService {
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[]> {
const url = `${this.baseUrl}/meter-data`;
@@ -55,4 +61,16 @@ export class DatabaseService {
// Return an observable with a user-facing error message.
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,
env: 'prod',
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,
env: 'local',
apiBaseUrl: 'http://localhost:8080',
version: 0.2,
version: 0.4,
// apiBaseUrl: 'http://192.168.178.21:8182/api',
};