-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: user language need store to persistent database
bugfix: interceptor not work when redirect user to login
- Loading branch information
1 parent
e12c0aa
commit eb244c1
Showing
24 changed files
with
271 additions
and
77 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
sep490-commons/api/src/main/java/green_buildings/commons/api/enums/UserLocale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package green_buildings.commons.api.enums; | ||
|
||
import green_buildings.commons.api.BaseEnum; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
public enum UserLocale implements BaseEnum { | ||
VI("vi-VN"), | ||
EN("en-US"), | ||
ZH("zh-CN"); | ||
|
||
private final String code; | ||
|
||
public static UserLocale fromCode(String code) { | ||
return Arrays.stream(values()) | ||
.filter(userLanguage -> userLanguage.getCode().equals(code)) | ||
.findFirst() | ||
.orElseThrow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
sep490-frontend/src/app/modules/shared/enums/user-language.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum UserLanguage { | ||
VI = 'vi-VN', | ||
EN = 'en-US', | ||
ZH = 'zh-CN' | ||
} |
25 changes: 0 additions & 25 deletions
25
sep490-frontend/src/app/modules/shared/interceptor/language.interceptor.ts
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
sep490-frontend/src/app/modules/shared/models/user-configs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {UserLanguage} from '../enums/user-language.enum'; | ||
|
||
export interface UserConfigs { | ||
language: UserLanguage; | ||
theme: keyof typeof Theme; | ||
} | ||
|
||
export enum Theme { | ||
DARK, | ||
LIGHT, | ||
SYSTEM | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {HttpClient} from '@angular/common/http'; | ||
import {Injectable} from '@angular/core'; | ||
import {Observable} from 'rxjs'; | ||
import {AppRoutingConstants} from '../app-routing.constant'; | ||
import {UserLanguage} from '../modules/shared/enums/user-language.enum'; | ||
import {UserConfigs} from '../modules/shared/models/user-configs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class UserService { | ||
constructor(private readonly httpClient: HttpClient) {} | ||
|
||
get userConfigs(): Observable<UserConfigs> { | ||
return this.httpClient.get<UserConfigs>( | ||
`${AppRoutingConstants.IDP_API_URL}/user/configs` | ||
); | ||
} | ||
|
||
changeLanguage(language: UserLanguage): Observable<void> { | ||
return this.httpClient.put<void>( | ||
`${AppRoutingConstants.IDP_API_URL}/user/language/${language}`, | ||
{} | ||
); | ||
} | ||
|
||
changeTheme(theme: string): Observable<void> { | ||
return this.httpClient.put<void>( | ||
`${AppRoutingConstants.IDP_API_URL}/user/theme/${theme}`, | ||
{} | ||
); | ||
} | ||
} |
Oops, something went wrong.