diff --git a/client/src/app/core/layout/layout.component.html b/client/src/app/core/layout/layout.component.html index 90fa845..ba0c638 100644 --- a/client/src/app/core/layout/layout.component.html +++ b/client/src/app/core/layout/layout.component.html @@ -24,7 +24,10 @@ > - + (); - - constructor( private _userService: UserService, private _router: ActivatedRoute diff --git a/client/src/app/core/services/department.service.ts b/client/src/app/core/services/department.service.ts new file mode 100644 index 0000000..2287293 --- /dev/null +++ b/client/src/app/core/services/department.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { + BehaviorSubject, lastValueFrom, Observable, +} from 'rxjs'; +import {environment} from "../../../environments/environment"; +@Injectable({ providedIn: 'root' }) +export class DepartmentService { + private departmentSubject = new BehaviorSubject(null); + + constructor(private readonly http: HttpClient) {} + + private _getDepartment(): Observable<{result: string[]}> { + return this.http.get<{result: string[]}>(environment.api + "/departments", { + withCredentials: true, + }) + } + + async fetchDepartment() : Promise { + return lastValueFrom(this._getDepartment()).then(({result}) => result).catch(err => {throw err}) + } + + get currentDepartment(): string | null { + return this.departmentSubject.value + } +} diff --git a/client/src/assets/departments/logo/alpha-3.png b/client/src/assets/departments/logo/alpha-3.png new file mode 100644 index 0000000..1f7c6fe Binary files /dev/null and b/client/src/assets/departments/logo/alpha-3.png differ diff --git a/client/src/assets/departments/logo/aus_plate.png b/client/src/assets/departments/logo/aus_plate.png new file mode 100644 index 0000000..507217f Binary files /dev/null and b/client/src/assets/departments/logo/aus_plate.png differ diff --git a/client/src/assets/departments/logo/mys_plate.png b/client/src/assets/departments/logo/mys_plate.png new file mode 100644 index 0000000..7b7a8cc Binary files /dev/null and b/client/src/assets/departments/logo/mys_plate.png differ diff --git a/client/src/assets/departments/logo/tha_plate.png b/client/src/assets/departments/logo/tha_plate.png new file mode 100644 index 0000000..95540a8 Binary files /dev/null and b/client/src/assets/departments/logo/tha_plate.png differ diff --git a/server/contracts/common.go b/server/contracts/common.go index a774462..bb65d7c 100644 --- a/server/contracts/common.go +++ b/server/contracts/common.go @@ -4,3 +4,7 @@ type ResponseDefault struct { Status string `json:"status"` Message string `json:"message"` } + +type Response[T any] struct { + Result T `json:"result"` +} diff --git a/server/routers/recipe.go b/server/routers/recipe.go index a202465..172b32a 100644 --- a/server/routers/recipe.go +++ b/server/routers/recipe.go @@ -8,6 +8,7 @@ import ( "path" "recipe-manager/contracts" "recipe-manager/data" + "recipe-manager/enums/permissions" "recipe-manager/helpers" "recipe-manager/models" "recipe-manager/services/logger" @@ -61,6 +62,39 @@ func (rr *RecipeRouter) Route(r chi.Router) { r.Get("/saved/{country}/{filename_version_only}", rr.getSavedRecipes) + r.Get("/departments", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + + // return departments that user can access + + u := r.Context().Value("user").(*models.User) + var result []string + + if u.Permissions.IsHavePermission(permissions.ThaiPermission) { + result = append(result, "tha") + } + + if u.Permissions.IsHavePermission(permissions.MalayPermission) { + result = append(result, "mys") + } + + if u.Permissions.IsHavePermission(permissions.AusPermission) { + result = append(result, "aus") + } + + if u.Permissions.IsHavePermission(permissions.Alpha3Permission) { + result = append(result, "alpha") + } + + if err := json.NewEncoder(w).Encode(&contracts.Response[[]string]{ + Result: result, + }); err != nil { + rr.taoLogger.Log.Error("RecipeRouter.GetDepartments", zap.Error(err)) + http.Error(w, "Internal Error", http.StatusInternalServerError) + return + } + }) + r.Get("/countries", func(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "application/json") // get key from map