diff --git a/api/src/main/java/com/rossa/api/controllers/AppContoller.java b/api/src/main/java/com/rossa/api/controllers/AppContoller.java index b1f6515..e454f84 100644 --- a/api/src/main/java/com/rossa/api/controllers/AppContoller.java +++ b/api/src/main/java/com/rossa/api/controllers/AppContoller.java @@ -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; -// } -// } \ No newline at end of file +@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; + } + +} \ No newline at end of file diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties index 394a391..cee1bf7 100644 --- a/api/src/main/resources/application.properties +++ b/api/src/main/resources/application.properties @@ -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 \ No newline at end of file +security.basic.enabled=false + +#api version +rossatech.api.version=0.2 \ No newline at end of file diff --git a/rossa-tech webpage.txt b/rossa-tech webpage.txt index 3d3f741..d92d5ce 100644 --- a/rossa-tech webpage.txt +++ b/rossa-tech webpage.txt @@ -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/ diff --git a/rossa-tech-cli/src/app/components/footer/footer.component.html b/rossa-tech-cli/src/app/components/footer/footer.component.html index d48fb98..660e7ee 100644 --- a/rossa-tech-cli/src/app/components/footer/footer.component.html +++ b/rossa-tech-cli/src/app/components/footer/footer.component.html @@ -1,8 +1,18 @@
\ No newline at end of file diff --git a/rossa-tech-cli/src/app/components/footer/footer.component.scss b/rossa-tech-cli/src/app/components/footer/footer.component.scss index 2d55ffa..bd74b8f 100644 --- a/rossa-tech-cli/src/app/components/footer/footer.component.scss +++ b/rossa-tech-cli/src/app/components/footer/footer.component.scss @@ -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; + } } diff --git a/rossa-tech-cli/src/app/components/footer/footer.component.ts b/rossa-tech-cli/src/app/components/footer/footer.component.ts index 5e3beaa..05a47df 100644 --- a/rossa-tech-cli/src/app/components/footer/footer.component.ts +++ b/rossa-tech-cli/src/app/components/footer/footer.component.ts @@ -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; + }, + }); } } diff --git a/rossa-tech-cli/src/app/components/loginPage/login.component.ts b/rossa-tech-cli/src/app/components/loginPage/login.component.ts index f27369b..a65c9c4 100644 --- a/rossa-tech-cli/src/app/components/loginPage/login.component.ts +++ b/rossa-tech-cli/src/app/components/loginPage/login.component.ts @@ -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(['/']); } }, diff --git a/rossa-tech-cli/src/app/core/services/database.service.ts b/rossa-tech-cli/src/app/core/services/database.service.ts index 3b2d9c7..92bb2d0 100644 --- a/rossa-tech-cli/src/app/core/services/database.service.ts +++ b/rossa-tech-cli/src/app/core/services/database.service.ts @@ -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