Some frontend improvements, versioned the backend API
This commit is contained in:
parent
46f911c075
commit
2bc6abf42c
@ -10,6 +10,7 @@ import {HttpClientModule} from "@angular/common/http";
|
|||||||
import {BroadcastComponent} from './broadcast/broadcast.component';
|
import {BroadcastComponent} from './broadcast/broadcast.component';
|
||||||
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
||||||
import {FlexLayoutModule} from "@angular/flex-layout";
|
import {FlexLayoutModule} from "@angular/flex-layout";
|
||||||
|
import {BackendService} from "./backend.service";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -28,7 +29,9 @@ import {FlexLayoutModule} from "@angular/flex-layout";
|
|||||||
MatExpansionModule,
|
MatExpansionModule,
|
||||||
MatButtonModule
|
MatButtonModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [
|
||||||
|
BackendService
|
||||||
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
15
frontend/src/app/backend.service.spec.ts
Normal file
15
frontend/src/app/backend.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { BackendService } from './backend.service';
|
||||||
|
|
||||||
|
describe('BackendService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [BackendService]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([BackendService], (service: BackendService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
38
frontend/src/app/backend.service.ts
Normal file
38
frontend/src/app/backend.service.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {Observable} from "rxjs/Observable";
|
||||||
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {map} from "rxjs/operators";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BackendService {
|
||||||
|
|
||||||
|
private baseUrl = "http://localhost:8080";
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
getStatus(): Observable<string> {
|
||||||
|
return this.http.get(`${this.baseUrl}/api/v1/status`).pipe(map(data => JSON.stringify(data, null, 2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
getBroadcasts(address: string): Observable<Broadcasts> {
|
||||||
|
return this.http.get<Broadcasts>(`${this.baseUrl}/api/v1/read/${address}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Sender {
|
||||||
|
address: String;
|
||||||
|
alias: String;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Message {
|
||||||
|
id: any;
|
||||||
|
received: number;
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Broadcasts {
|
||||||
|
sender: Sender;
|
||||||
|
messages: Message[]
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {ActivatedRoute} from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import {HttpClient} from "@angular/common/http";
|
|
||||||
import {Observable} from "rxjs/Observable";
|
import {Observable} from "rxjs/Observable";
|
||||||
|
import {BackendService, Broadcasts} from "../backend.service";
|
||||||
|
import {map, switchMap} from "rxjs/operators";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-broadcast',
|
selector: 'app-broadcast',
|
||||||
@ -12,29 +13,13 @@ export class BroadcastComponent implements OnInit {
|
|||||||
|
|
||||||
broadcasts$: Observable<Broadcasts>;
|
broadcasts$: Observable<Broadcasts>;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private http: HttpClient) {
|
constructor(private route: ActivatedRoute, private backend: BackendService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
let address = this.route.snapshot.params['address'];
|
this.broadcasts$ = this.route.params
|
||||||
this.broadcasts$ = this.http.get<Broadcasts>('http://localhost:8080/read/' + address)
|
.pipe(map(p => p['address']))
|
||||||
|
.pipe(switchMap(address => this.backend.getBroadcasts(address)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sender {
|
|
||||||
address: String;
|
|
||||||
alias: String;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Message {
|
|
||||||
id: any;
|
|
||||||
received: number;
|
|
||||||
subject: string;
|
|
||||||
body: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Broadcasts {
|
|
||||||
sender: Sender;
|
|
||||||
messages: Message[]
|
|
||||||
}
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<mat-card>
|
<mat-card>
|
||||||
<pre><code>{{status}}</code></pre>
|
<pre><code>{{status$ | async}}</code></pre>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {BackendService} from "../backend.service";
|
||||||
|
import {Observable} from "rxjs/Observable";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-status',
|
selector: 'app-status',
|
||||||
templateUrl: './status.component.html',
|
templateUrl: './status.component.html',
|
||||||
styleUrls: ['./status.component.scss']
|
styleUrls: ['./status.component.scss']
|
||||||
})
|
})
|
||||||
export class StatusComponent implements OnInit {
|
export class StatusComponent {
|
||||||
|
|
||||||
status: string;
|
status$: Observable<string>;
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(backend: BackendService) {
|
||||||
}
|
this.status$ = backend.getStatus();
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.http.get('http://localhost:8080/status').subscribe(data => {
|
|
||||||
this.status = JSON.stringify(data, null, 2);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ object Converter {
|
|||||||
|
|
||||||
fun message(plaintext: Plaintext) = Message().apply {
|
fun message(plaintext: Plaintext) = Message().apply {
|
||||||
id = plaintext.id
|
id = plaintext.id
|
||||||
received = plaintext.sent
|
received = plaintext.received
|
||||||
subject = plaintext.subject
|
subject = plaintext.subject
|
||||||
body = plaintext.text
|
body = plaintext.text
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RestController
|
@RestController
|
||||||
|
@RequestMapping("/api/v1")
|
||||||
class JabitServerController {
|
class JabitServerController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -55,7 +56,6 @@ class JabitServerController {
|
|||||||
"uri": "${Utils.getURL(identity, true)}"
|
"uri": "${Utils.getURL(identity, true)}"
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = ["status"], method = [GET], produces = ["application/json"])
|
@RequestMapping(value = ["status"], method = [GET], produces = ["application/json"])
|
||||||
fun status() = "{${ctx.status()}}"
|
fun status() = "{${ctx.status()}}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user