Skip to content

Commit 2fbef3a

Browse files
committed
working implementation of using language code in url
1 parent 7c86df8 commit 2fbef3a

File tree

13 files changed

+137
-109
lines changed

13 files changed

+137
-109
lines changed

api-contract/src/main/resources/api-contract.yaml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ tags:
1212
- name: government
1313

1414
paths:
15-
/api/admin/gov-representatives:
15+
/{languageShortName}/api/admin/gov-representatives:
1616
post:
1717
tags:
1818
- government-representative
1919
summary: Add a new Government Representative
2020
description: Add a new Government Representative to the database
2121
operationId: addNewRepresentative
22+
parameters:
23+
- name: languageShortName
24+
in: path
25+
description: short name of selected language
26+
required: true
27+
schema:
28+
type: string
2229
requestBody:
2330
description: Create a new Representative in the database
2431
content:
@@ -43,6 +50,13 @@ paths:
4350
description: Render all Government Representatives from the database
4451
operationId: renderAllRepresentatives
4552
x-interface-name: RepresentativeApi
53+
parameters:
54+
- name: languageShortName
55+
in: path
56+
description: short name of selected language
57+
required: true
58+
schema:
59+
type: string
4660
responses:
4761
'200':
4862
description: Successful operation
@@ -63,7 +77,7 @@ paths:
6377
'405':
6478
description: Validation exception
6579

66-
/api/admin/gov-representatives/government/{governmentId}:
80+
/{languageShortName}/api/admin/gov-representatives/government/{governmentId}:
6781
get:
6882
tags:
6983
- government-representative
@@ -80,6 +94,12 @@ paths:
8094
type: integer
8195
format: int64
8296
minimum: 1
97+
- name: languageShortName
98+
in: path
99+
description: short name of selected language
100+
required: true
101+
schema:
102+
type: string
83103
- name: page
84104
in: query
85105
description: The page number to retrieve
@@ -116,12 +136,20 @@ paths:
116136
description: Representative not found
117137
'405':
118138
description: Validation exception
139+
119140
/api/admin/gov-representatives/government:
120141
get:
121142
tags:
122143
- government
123144
summary: Get government data
124145
operationId: renderAllGovernments
146+
#parameters:
147+
#- name: languageShortName
148+
#in: path
149+
#description: short name of selected language
150+
#required: true
151+
#schema:
152+
#type: string
125153
responses:
126154
'200':
127155
description: OK
@@ -141,7 +169,6 @@ paths:
141169
schema:
142170
type: string
143171

144-
145172
components:
146173
schemas:
147174
RepresentativeAdminModel:
@@ -209,6 +236,8 @@ components:
209236
description: Any extra, useful information
210237
type: string
211238
example: 'Főosztály megnevezése: '
239+
lang:
240+
type: string
212241
availability:
213242
$ref: '#/components/schemas/Availability'
214243

@@ -266,4 +295,15 @@ components:
266295
enum:
267296
- AVAILABLE
268297
- ARCHIVE
269-
- DELETED
298+
- DELETED
299+
300+
Language:
301+
type: object
302+
properties:
303+
id:
304+
type: integer
305+
format: int64
306+
shortName:
307+
type: string
308+
name:
309+
type: string

frontend/src/app/app.component.html

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,16 @@
2323

2424
<nav class="lang-container mb-4 mt-4">
2525
<div class="row">
26-
<div class="col-10"></div>
27-
<div class="col-2"></div>
28-
<select class="custom-select">
29-
<option value="hu" data-icon="flag-icon flag-icon-hu">
30-
<i class="flag-icon flag-icon-hu"></i> Magyar
31-
</option>
32-
<option value="en" data-icon="flag-icon flag-icon-us">
33-
<i class="flag-icon flag-icon-us"></i> English
34-
</option>
35-
<option value="il" data-icon="flag-icon flag-icon-il">
36-
<i class="flag-icon flag-icon-il"></i> עברית
37-
</option>
38-
</select>
26+
<div class="col-3">
27+
<select class="custom-select" [(ngModel)]="selectedLanguage" (change)="changeLang(selectedLanguage)">
28+
<option value="hu">Magyar</option>
29+
<option value="en">English</option>
30+
<option value="il"> עברית</option>
31+
</select>
32+
</div>
3933
</div>
4034
</nav>
4135

42-
<!--<nav class="lang-container mb-4 mt-4">
43-
<div class="row">
44-
<div class="col-10"></div>
45-
<div class="col-2"></div>
46-
<select class="custom-select">
47-
<option value="hu" data-icon="flag-icon flag-icon-hu"><img src="../assets/images/flags/1x1/us.svg" class="flag-icon">Magyar</option>
48-
<option value="en" data-icon="flag-icon flag-icon-us"><img src="../assets/images/flags/1x1/us.svg" class="flag-icon">English</option>
49-
<option value="il" data-icon="flag-icon flag-icon-il"><img src="../assets/images/flags/1x1/il.svg" class="flag-icon">עברית</option>
50-
</select>
51-
</div>
52-
</nav>-->
5336
<!--<div class="cart-area d-n">
5437
<a href="shopping-detail.html">
5538
<div class="total">19.22 <span> 2</span> </div> <i class="fa fa-shopping-cart"

frontend/src/app/app.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
import { Component } from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
22

33
@Component({
44
selector: 'app-root',
55
templateUrl: './app.component.html',
66
styleUrls: ['./app.component.css']
77
})
8-
export class AppComponent {
8+
export class AppComponent implements OnInit {
99
title = 'frontend';
10+
selectedLanguage: string = '';
1011

12+
ngOnInit(): void {
13+
14+
}
15+
16+
constructor() {
17+
// this.router.navigate(['/hu/admin/gov-representatives/government', governmentId]);
18+
this.selectedLanguage = window.localStorage.getItem('lang') || 'hu';
19+
}
20+
21+
changeLang(lang: string): void {
22+
this.selectedLanguage = lang;
23+
}
1124
}
1225

frontend/src/app/app.module.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { ApiModule, GovernmentRepresentativeService } from "../../build/openapi/
77
import { RepresentativeListComponent } from './government-service/components/representative-list/representative-list.component';
88
import {RouterModule, Routes} from "@angular/router";
99
import { GovernmentListComponent } from "./government-service/components/government-list/government-list/government-list.component";
10+
import {FormsModule} from "@angular/forms";
1011

1112
const routes: Routes = [
12-
// first match wins top down!
13-
{path: 'api/admin/gov-representatives/government/:governmentId', component: RepresentativeListComponent },
14-
{path: 'api/admin/gov-representatives/government', component: RepresentativeListComponent },
15-
{path: 'api/admin/gov-representatives', component: RepresentativeListComponent },
16-
{path: 'api/admin/governments', component: GovernmentListComponent},
17-
{path: '', redirectTo: '/api/admin/gov-representatives', pathMatch: 'full' },
18-
{path: '**', redirectTo: '/api/admin/gov-representatives', pathMatch: 'full' }
13+
{path: ':languageShortName/api/admin/gov-representatives', component: RepresentativeListComponent },
14+
{path: ':languageShortName/api/admin/gov-representatives/government', component: RepresentativeListComponent },
15+
{path: ':languageShortName/api/admin/gov-representatives/government/:governmentId', component: RepresentativeListComponent },
16+
{path: 'api/admin/governments', component: GovernmentListComponent},
17+
{path: '', redirectTo: '/hu/api/admin/gov-representatives', pathMatch: 'full' },
18+
{path: '**', redirectTo: '/hu/api/admin/gov-representatives', pathMatch: 'full' }
1919
];
2020

2121
@NgModule({
@@ -24,12 +24,13 @@ const routes: Routes = [
2424
RepresentativeListComponent,
2525
GovernmentListComponent
2626
],
27-
imports: [
28-
RouterModule.forRoot(routes),
29-
BrowserModule,
30-
HttpClientModule,
31-
ApiModule
32-
],
27+
imports: [
28+
RouterModule.forRoot(routes),
29+
BrowserModule,
30+
HttpClientModule,
31+
ApiModule,
32+
FormsModule
33+
],
3334
exports: [RouterModule],
3435
providers: [GovernmentRepresentativeService],
3536
bootstrap: [AppComponent]

frontend/src/app/government-service/components/representative-list/representative-list.component.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
<div class="menu-sidebar-content js-scrollbar1">
88
<nav class="navbar-sidebar">
99
<ul class="list-unstyled navbar-list">
10-
<li>
11-
<a routerLink="/api/admin/gov-representatives"
12-
routerLinkActive="active-link"
13-
[routerLinkActiveOptions]="{exact: true}"
14-
[class.active]="isActive('/api/admin/gov-representatives')">
15-
Összes
16-
</a>
17-
</li>
18-
<ng-container *ngIf="(governments$ | async) as governments">
19-
<li *ngFor="let government of governments">
20-
<a routerLink="/api/admin/gov-representatives/government/{{ government.id }}"
10+
<ul>
11+
<li>
12+
<a [routerLink]="['/', currentLanguage, 'api', 'admin', 'gov-representatives']"
2113
routerLinkActive="active-link"
22-
[class.active]="isActive('/api/admin/gov-representatives/government/' + government.id)">
23-
{{ government.name }}
14+
[routerLinkActiveOptions]="{exact: true}">
15+
Összes
2416
</a>
2517
</li>
26-
</ng-container>
18+
<ng-container *ngIf="(governments$ | async) as governments">
19+
<li *ngFor="let government of governments">
20+
<a [routerLink]="['/', currentLanguage, 'api', 'admin', 'gov-representatives', 'government', government?.id]"
21+
routerLinkActive="active-link">
22+
{{ government.name }}
23+
</a>
24+
</li>
25+
</ng-container>
26+
</ul>
2727
</ul>
2828
</nav>
2929
</div>

frontend/src/app/government-service/components/representative-list/representative-list.component.ts

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
33
import {
4-
ActivatedRoute,
5-
PRIMARY_OUTLET,
6-
Router,
7-
UrlSegment,
8-
UrlSegmentGroup,
9-
UrlTree
4+
ActivatedRoute
105
} from '@angular/router';
116

127
import {
@@ -23,36 +18,35 @@ import {Observable, Subject} from "rxjs";
2318

2419
export class RepresentativeListComponent implements OnInit {
2520
representatives: SanitizedRepresentativeAdminModel[] = [];
21+
currentLanguage?: string = 'hu';
2622
governments$: Observable<GovernmentAdminModel[]> = this.governmentService.renderAllGovernments();
2723
currentGovernmentId?: number;
2824

29-
3025
constructor(
3126
private readonly representativeService: GovernmentRepresentativeService,
3227
private readonly governmentService: GovernmentService,
3328
private sanitizer: DomSanitizer,
34-
private route: ActivatedRoute,
35-
private router: Router
29+
private route: ActivatedRoute
3630
) {}
3731

3832
ngOnInit(): void {
39-
// this.governmentList();
4033
this.listRepresentatives();
4134
}
4235

4336
private listRepresentatives() {
4437
this.route.params.subscribe(params => {
4538
const governmentId = params['governmentId'];
4639
if (governmentId) {
47-
this.listRepresentativesByGovId(governmentId);
40+
this.currentGovernmentId = governmentId;
41+
this.listRepresentativesByGovId(this.currentLanguage!, this.currentGovernmentId!);
4842
} else {
4943
this.listAllRepresentatives();
5044
}
5145
});
5246
}
5347

5448
private listAllRepresentatives() {
55-
this.representativeService.renderAllRepresentatives().subscribe((data) => {
49+
this.representativeService.renderAllRepresentatives(this.currentLanguage!).subscribe((data) => {
5650
this.representatives = data.map((representative) => {
5751
console.log("Representatives: " + JSON.stringify(representative));
5852
const government = representative.government;
@@ -64,11 +58,25 @@ export class RepresentativeListComponent implements OnInit {
6458
});
6559
});
6660
}
61+
/*private listAllRepresentatives() {
62+
this.representativeService.renderAllRepresentatives(this.currentLanguage!).subscribe((data) => {
63+
this.representatives = data.map((representative) => {
64+
console.log("Representatives: " + JSON.stringify(representative));
65+
const government = representative.government;
66+
return {
67+
...representative,
68+
governmentName: government ? government.name : '',
69+
image: this.sanitizer.bypassSecurityTrustUrl(`data:image/png;base64,${representative.image}`),
70+
};
71+
});
72+
});
73+
}*/
6774

68-
private listRepresentativesByGovId(governmentId: number) {
75+
private listRepresentativesByGovId(currentLanguage: string, governmentId: number) {
6976
this.currentGovernmentId = governmentId;
77+
this.currentLanguage = currentLanguage;
7078
this.representativeService
71-
.findByGovernmentId(this.currentGovernmentId)
79+
.findByGovernmentId(this.currentGovernmentId, this.currentLanguage)
7280
.subscribe((data) => {
7381
this.representatives = data.map((representative) => {
7482
console.log("Representatives: " + JSON.stringify(representative));
@@ -81,29 +89,12 @@ export class RepresentativeListComponent implements OnInit {
8189
});
8290
});
8391
}
84-
85-
isActive(url: string): boolean {
86-
const currentUrlTree: UrlTree = this.router.parseUrl(this.router.url);
87-
const targetUrlTree: UrlTree = this.router.createUrlTree([url]);
88-
const currentUrlSegmentGroup: UrlSegmentGroup = currentUrlTree.root.children[PRIMARY_OUTLET];
89-
const targetUrlSegmentGroup: UrlSegmentGroup = targetUrlTree.root.children[PRIMARY_OUTLET];
90-
const currentSegments: UrlSegment[] = currentUrlSegmentGroup.segments;
91-
const targetSegments: UrlSegment[] = targetUrlSegmentGroup.segments;
92-
const length: number = Math.min(currentSegments.length, targetSegments.length);
93-
94-
for (let i = 0; i < length; i++) {
95-
if (currentSegments[i].path !== targetSegments[i].path) {
96-
return false;
97-
}
98-
}
99-
100-
return targetSegments.length <= currentSegments.length;
101-
}
10292
}
10393

104-
interface SanitizedRepresentativeAdminModel {
94+
interface SanitizedRepresentativeAdminModel {
10595
id?: string;
10696
name?: string;
97+
lang?: string;
10798
email?: string;
10899
phoneNumber?: string;
109100
address?: string;

frontend/src/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="icon" type="image/x-icon" href="favicon.ico?=v2">
9-
<link
10-
rel="stylesheet"
11-
href="https://cdn.jsdelivr.net/gh/lipis/flag-icons@6.6.6/css/flag-icons.min.css"
12-
/>
139
</head>
1410
<body>
1511
<app-root></app-root>

government-service/src/main/java/com/csaba79coder/bestprotocol/controller/GovernmentController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class GovernmentController implements GovernmentApi {
1717

1818
private final GovernmentService governmentService;
1919

20-
2120
@Override
2221
public ResponseEntity<List<GovernmentAdminModel>> renderAllGovernments() {
2322
return ResponseEntity.status(200).body(governmentService.findAllGovernments());

0 commit comments

Comments
 (0)