Merge branch 'main' of https://github.com/Poomipat-Ch/taobin_recipe_manager
This commit is contained in:
commit
8568004d36
9 changed files with 79 additions and 8 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
26
client/src/app/core/services/department.service.ts
Normal file
26
client/src/app/core/services/department.service.ts
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
client/src/assets/departments/logo/alpha-3.png
Normal file
BIN
client/src/assets/departments/logo/alpha-3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
BIN
client/src/assets/departments/logo/aus_plate.png
Normal file
BIN
client/src/assets/departments/logo/aus_plate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
BIN
client/src/assets/departments/logo/mys_plate.png
Normal file
BIN
client/src/assets/departments/logo/mys_plate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
BIN
client/src/assets/departments/logo/tha_plate.png
Normal file
BIN
client/src/assets/departments/logo/tha_plate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
|
|
@ -4,3 +4,7 @@ type ResponseDefault struct {
|
|||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type Response[T any] struct {
|
||||
Result T `json:"result"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue