This commit is contained in:
pakintada@gmail.com 2023-12-29 16:11:14 +07:00
commit 8568004d36
9 changed files with 79 additions and 8 deletions

View file

@ -24,7 +24,10 @@
></path>
</svg>
</button>
<a routerLink="/{{ current_department }}/recipes" class="flex ml-14 max-sm:hidden">
<a
routerLink="/{{ current_department }}/recipes"
class="flex ml-14 max-sm:hidden"
>
<img
src="assets/logo.svg"
class="h-10 md:h-20 px-4"

View file

@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { DatePipe, NgFor, NgIf } from '@angular/common';
import { DatePipe, NgFor, NgIf, NgOptimizedImage } from '@angular/common';
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
import { UserService } from '../services/user.service';
import { User } from '../models/user.model';
@ -16,22 +16,28 @@ interface MenuItem {
selector: 'app-layout',
templateUrl: './layout.component.html',
standalone: true,
imports: [RouterModule, NgFor, NgIf, GoogleButtonComponent, DatePipe],
imports: [
RouterModule,
NgFor,
NgIf,
GoogleButtonComponent,
DatePipe,
NgOptimizedImage,
],
})
export class LayoutComponent implements OnInit, OnDestroy {
current_department = this._router.snapshot.paramMap.get('department')!;
menuItems: MenuItem[] = [
{
name: 'Recipe',
icon_url: 'assets/icons/recipes.svg',
link: '/'+this.current_department+'/recipes',
link: '/' + this.current_department + '/recipes',
},
{
name: 'Log',
icon_url: 'assets/icons/logs.svg',
link: '/'+this.current_department+'/log',
link: '/' + this.current_department + '/log',
},
];
date = new Date();
@ -40,8 +46,6 @@ export class LayoutComponent implements OnInit, OnDestroy {
user: User | null = null;
exit$ = new Subject<void>();
constructor(
private _userService: UserService,
private _router: ActivatedRoute

View file

@ -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<string | null>(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<string[]> {
return lastValueFrom(this._getDepartment()).then(({result}) => result).catch(err => {throw err})
}
get currentDepartment(): string | null {
return this.departmentSubject.value
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View file

@ -4,3 +4,7 @@ type ResponseDefault struct {
Status string `json:"status"`
Message string `json:"message"`
}
type Response[T any] struct {
Result T `json:"result"`
}

View file

@ -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