update recipe now can select recipe file
This commit is contained in:
parent
b25c836f0c
commit
b5cb469a30
11 changed files with 209 additions and 236173 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "server/cofffeemachineConfig"]
|
||||||
|
path = server/cofffeemachineConfig
|
||||||
|
url = ssh://poomipat@kong/1TBHDD/ikong/repo/cofffeemachineConfig
|
||||||
|
|
@ -145,7 +145,7 @@
|
||||||
|
|
||||||
<div class="pt-10 sm:ml-64">
|
<div class="pt-10 sm:ml-64">
|
||||||
<div class="p-2 sm:mt-5 md:mt-12">
|
<div class="p-2 sm:mt-5 md:mt-12">
|
||||||
<div class="grid grid-cols-1 gap-2 mb-2">
|
<div class="mb-2">
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { Recipe, Recipe01 } from '../models/recipe.model';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
interface RecipeParams {
|
interface RecipeParams {
|
||||||
|
version: string;
|
||||||
offset: number;
|
offset: number;
|
||||||
take: number;
|
take: number;
|
||||||
search: string;
|
search: string;
|
||||||
|
|
@ -15,12 +16,19 @@ export class RecipeService {
|
||||||
constructor(private _httpClient: HttpClient) {}
|
constructor(private _httpClient: HttpClient) {}
|
||||||
|
|
||||||
getRecipes(
|
getRecipes(
|
||||||
params: RecipeParams = { take: 10, offset: 0, search: '' }
|
params: RecipeParams = {
|
||||||
|
take: 10,
|
||||||
|
offset: 0,
|
||||||
|
search: '',
|
||||||
|
version: 'coffeethai02_580.json',
|
||||||
|
}
|
||||||
): Observable<{
|
): Observable<{
|
||||||
|
fileName: string;
|
||||||
recipes: Recipe;
|
recipes: Recipe;
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
}> {
|
}> {
|
||||||
return this._httpClient.get<{
|
return this._httpClient.get<{
|
||||||
|
fileName: string;
|
||||||
recipes: Recipe;
|
recipes: Recipe;
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
}>(environment.api + '/recipes', {
|
}>(environment.api + '/recipes', {
|
||||||
|
|
@ -28,6 +36,7 @@ export class RecipeService {
|
||||||
offset: params.offset,
|
offset: params.offset,
|
||||||
take: params.take,
|
take: params.take,
|
||||||
search: params.search,
|
search: params.search,
|
||||||
|
version: params.version,
|
||||||
},
|
},
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
|
|
@ -40,4 +49,11 @@ export class RecipeService {
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRecipeVersions(): Observable<string[]> {
|
||||||
|
return this._httpClient.get<string[]>(
|
||||||
|
environment.api + '/recipes/versions',
|
||||||
|
{ withCredentials: true, responseType: 'json' }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,34 +11,28 @@ import { WebsocketService } from 'src/app/shared/services/websocket.service';
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './changelog.component.html',
|
templateUrl: './changelog.component.html',
|
||||||
styleUrls: ['./changelog.component.css'],
|
styleUrls: ['./changelog.component.css'],
|
||||||
imports: [CommonModule,MergeComponent]
|
imports: [CommonModule, MergeComponent],
|
||||||
})
|
})
|
||||||
export class ChangelogComponent {
|
export class ChangelogComponent {
|
||||||
|
|
||||||
public displayableLogs: string[] = [];
|
public displayableLogs: string[] = [];
|
||||||
public displayableMergeJson: string[] = [];
|
public displayableMergeJson: string[] = [];
|
||||||
showLogModal:boolean = false;
|
showLogModal: boolean = false;
|
||||||
showMergeModal:boolean = false;
|
showMergeModal: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(private httpClient: HttpClient, private wss: WebsocketService) {
|
||||||
private httpClient: HttpClient,
|
|
||||||
private wss: WebsocketService
|
|
||||||
){
|
|
||||||
this.fetchLoglist();
|
this.fetchLoglist();
|
||||||
// this.translateLogDirToString();
|
// this.translateLogDirToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fetchLoglist(): string[] {
|
||||||
public fetchLoglist(): string[]{
|
|
||||||
// TODO: Fetch changelog.html
|
// TODO: Fetch changelog.html
|
||||||
// fetch("/changelog")
|
// fetch("/changelog")
|
||||||
let dirlist: any[] = []
|
let dirlist: any[] = [];
|
||||||
|
|
||||||
|
this.wss.connect(environment.wsapi + '/listFileInDir');
|
||||||
this.wss.connect(environment.wsapi+"/listFileInDir");
|
|
||||||
this.wss.send({
|
this.wss.send({
|
||||||
"topic": "changelog",
|
topic: 'changelog',
|
||||||
})
|
});
|
||||||
|
|
||||||
let response = this.wss.data;
|
let response = this.wss.data;
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
@ -83,10 +77,9 @@ export class ChangelogComponent {
|
||||||
return dirlist;
|
return dirlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public translateLogDirToString() {
|
||||||
public translateLogDirToString(){
|
console.log('LogDirList: ', this.displayableLogs);
|
||||||
console.log("LogDirList: ", this.displayableLogs)
|
let dirSelector = document.getElementById('log-dir-list');
|
||||||
let dirSelector = document.getElementById("log-dir-list")
|
|
||||||
// for(let dir of this.displayableLogs){
|
// for(let dir of this.displayableLogs){
|
||||||
// console.log(dir)
|
// console.log(dir)
|
||||||
// const p = document.createElement('p');
|
// const p = document.createElement('p');
|
||||||
|
|
@ -96,27 +89,27 @@ export class ChangelogComponent {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshLogList(){
|
refreshLogList() {
|
||||||
this.fetchLoglist();
|
this.fetchLoglist();
|
||||||
this.translateLogDirToString();
|
this.translateLogDirToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
viewLog(name:string){
|
viewLog(name: string) {
|
||||||
let cli = new FetchLogService(this.httpClient);
|
let cli = new FetchLogService(this.httpClient);
|
||||||
this.showLogModal = !this.showLogModal;
|
this.showLogModal = !this.showLogModal;
|
||||||
cli.fetchLogsToDisplay("changelog", true, false, name);
|
cli.fetchLogsToDisplay('changelog', true, false, name);
|
||||||
cli.fetchLogsToDisplay("changelog", false, false, name);
|
cli.fetchLogsToDisplay('changelog', false, false, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
viewJson(name:string){
|
viewJson(name: string) {
|
||||||
let cli = new FetchLogService(this.httpClient);
|
let cli = new FetchLogService(this.httpClient);
|
||||||
this.showMergeModal = !this.showMergeModal;
|
this.showMergeModal = !this.showMergeModal;
|
||||||
cli.fetchLogsToDisplay("merge", false, true, name);
|
cli.fetchLogsToDisplay('merge', false, true, name);
|
||||||
// cli.fetchLogsToDisplay("", false, false, name);
|
// cli.fetchLogsToDisplay("", false, false, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleLogModal(target:string){
|
toggleLogModal(target: string) {
|
||||||
if(target == "merge"){
|
if (target == 'merge') {
|
||||||
this.showMergeModal = !this.showMergeModal;
|
this.showMergeModal = !this.showMergeModal;
|
||||||
} else {
|
} else {
|
||||||
this.showLogModal = !this.showLogModal;
|
this.showLogModal = !this.showLogModal;
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,37 @@
|
||||||
<table *ngIf="isLoaded" class="table">
|
<table *ngIf="isLoaded" class="table">
|
||||||
<caption class="p-5 text-lg font-semibold text-left text-gray-900">
|
<caption class="p-5 text-lg font-semibold text-left text-gray-900">
|
||||||
<div class="divide-y divide-solid divide-gray-400">
|
<div class="divide-y divide-solid divide-gray-400">
|
||||||
<div class="flex flex-row py-3">
|
<div class="flex flex-row py-3 justify-between">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span
|
<span
|
||||||
>Recipe Version {{ recipes?.MachineSetting?.configNumber }} |
|
>Recipe Version {{ recipes?.MachineSetting?.configNumber }} |
|
||||||
{{"{{File name}}"}}</span
|
{{ fileName }}</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col ml-5">
|
||||||
|
<div class="dropdown dropdown-end">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
tabindex="0"
|
||||||
|
placeholder="เลือก Recipe File"
|
||||||
|
class="input input-bordered input-sm w-full max-w-xs"
|
||||||
|
(input)="setRecipeVersion($event)"
|
||||||
|
(focus)="getRecipeVersions()"
|
||||||
|
/>
|
||||||
|
<div class="dropdown-content z-[1] max-h-[500px] overflow-y-auto">
|
||||||
|
<ul
|
||||||
|
tabindex="0"
|
||||||
|
class="menu p-2 shadow bg-base-100 rounded-box w-auto"
|
||||||
|
>
|
||||||
|
<li *ngFor="let recipeVersion of recipeVersions">
|
||||||
|
<a (click)="loadRecipe(recipeVersion)">{{
|
||||||
|
recipeVersion
|
||||||
|
}}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex flex-col ml-auto">
|
<div class="flex flex-col ml-auto">
|
||||||
<span class=""
|
<span class=""
|
||||||
>Last Updated:
|
>Last Updated:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import { Recipe, Recipe01 } from 'src/app/core/models/recipe.model';
|
||||||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { RecipeModalComponent } from 'src/app/shared/modal/recipe-modal.component';
|
import { RecipeModalComponent } from 'src/app/shared/modal/recipe-modal.component';
|
||||||
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import * as lodash from 'lodash';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
|
|
@ -17,6 +19,8 @@ export class DashboardComponent implements OnInit {
|
||||||
userInfo: User | null = null;
|
userInfo: User | null = null;
|
||||||
recipes: Recipe | null = null;
|
recipes: Recipe | null = null;
|
||||||
recipes01: Recipe01[] | null = null;
|
recipes01: Recipe01[] | null = null;
|
||||||
|
recipeVersions: string[] = [];
|
||||||
|
fileName: string = '';
|
||||||
|
|
||||||
tableHeads: string[] = [
|
tableHeads: string[] = [
|
||||||
'Product Code',
|
'Product Code',
|
||||||
|
|
@ -27,6 +31,11 @@ export class DashboardComponent implements OnInit {
|
||||||
];
|
];
|
||||||
private offset = 0;
|
private offset = 0;
|
||||||
private take = 10;
|
private take = 10;
|
||||||
|
private recipeVersionData: string[] = [];
|
||||||
|
private currentRecipeVersion: string = 'coffeethai02_580.json';
|
||||||
|
|
||||||
|
recipeVersion: BehaviorSubject<string> = new BehaviorSubject<string>('');
|
||||||
|
recipeVersion$ = this.recipeVersion.asObservable();
|
||||||
|
|
||||||
isLoaded: boolean = false;
|
isLoaded: boolean = false;
|
||||||
isLoadMore: boolean = false;
|
isLoadMore: boolean = false;
|
||||||
|
|
@ -52,8 +61,9 @@ export class DashboardComponent implements OnInit {
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
take: this.take,
|
take: this.take,
|
||||||
search: this.oldSearchStr,
|
search: this.oldSearchStr,
|
||||||
|
version: this.currentRecipeVersion,
|
||||||
})
|
})
|
||||||
.subscribe(({ recipes, hasMore }) => {
|
.subscribe(({ recipes, hasMore, fileName }) => {
|
||||||
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
||||||
if (this.recipes01 && this.isHasMore) {
|
if (this.recipes01 && this.isHasMore) {
|
||||||
this.recipes01 = [...this.recipes01, ...Recipe01];
|
this.recipes01 = [...this.recipes01, ...Recipe01];
|
||||||
|
|
@ -64,6 +74,7 @@ export class DashboardComponent implements OnInit {
|
||||||
...recipesWithoutRecipe01,
|
...recipesWithoutRecipe01,
|
||||||
Recipe01: [],
|
Recipe01: [],
|
||||||
};
|
};
|
||||||
|
this.fileName = fileName;
|
||||||
this.offset += 10;
|
this.offset += 10;
|
||||||
this.isLoadMore = false;
|
this.isLoadMore = false;
|
||||||
this.isHasMore = hasMore;
|
this.isHasMore = hasMore;
|
||||||
|
|
@ -89,8 +100,9 @@ export class DashboardComponent implements OnInit {
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
take: this.take,
|
take: this.take,
|
||||||
search: this.oldSearchStr,
|
search: this.oldSearchStr,
|
||||||
|
version: this.currentRecipeVersion,
|
||||||
})
|
})
|
||||||
.subscribe(({ recipes, hasMore }) => {
|
.subscribe(({ recipes, hasMore, fileName }) => {
|
||||||
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
||||||
if (this.recipes01 && this.isHasMore) {
|
if (this.recipes01 && this.isHasMore) {
|
||||||
this.recipes01 = [...this.recipes01, ...Recipe01];
|
this.recipes01 = [...this.recipes01, ...Recipe01];
|
||||||
|
|
@ -101,10 +113,18 @@ export class DashboardComponent implements OnInit {
|
||||||
...recipesWithoutRecipe01,
|
...recipesWithoutRecipe01,
|
||||||
Recipe01: [],
|
Recipe01: [],
|
||||||
};
|
};
|
||||||
|
this.fileName = fileName;
|
||||||
this.offset += 10;
|
this.offset += 10;
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
this.isHasMore = hasMore;
|
this.isHasMore = hasMore;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.recipeVersion$.subscribe((version) => {
|
||||||
|
if (version)
|
||||||
|
this.recipeVersions = lodash.filter(this.recipeVersionData, (v) =>
|
||||||
|
v.includes(version)
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setSearch(event: Event) {
|
setSearch(event: Event) {
|
||||||
|
|
@ -119,8 +139,9 @@ export class DashboardComponent implements OnInit {
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
take: this.take,
|
take: this.take,
|
||||||
search: this.searchStr,
|
search: this.searchStr,
|
||||||
|
version: this.currentRecipeVersion,
|
||||||
})
|
})
|
||||||
.subscribe(({ recipes, hasMore }) => {
|
.subscribe(({ recipes, hasMore, fileName }) => {
|
||||||
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
||||||
this.recipes01 = Recipe01;
|
this.recipes01 = Recipe01;
|
||||||
|
|
||||||
|
|
@ -128,13 +149,65 @@ export class DashboardComponent implements OnInit {
|
||||||
...recipesWithoutRecipe01,
|
...recipesWithoutRecipe01,
|
||||||
Recipe01: [],
|
Recipe01: [],
|
||||||
};
|
};
|
||||||
|
this.fileName = fileName;
|
||||||
this.offset += 10;
|
this.offset += 10;
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
this.isHasMore = hasMore;
|
this.isHasMore = hasMore;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadRecipe(recipeVersion: string) {
|
||||||
|
// clear all recipes
|
||||||
|
this.recipes = null;
|
||||||
|
this.recipes01 = null;
|
||||||
|
this.offset = 0;
|
||||||
|
this.isLoaded = false;
|
||||||
|
this.isHasMore = true;
|
||||||
|
this.isLoadMore = false;
|
||||||
|
this.oldSearchStr = '';
|
||||||
|
this.currentRecipeVersion = recipeVersion;
|
||||||
|
|
||||||
|
this._recipeService
|
||||||
|
.getRecipes({
|
||||||
|
offset: this.offset,
|
||||||
|
take: this.take,
|
||||||
|
search: this.oldSearchStr,
|
||||||
|
version: recipeVersion,
|
||||||
|
})
|
||||||
|
.subscribe(({ recipes, hasMore, fileName }) => {
|
||||||
|
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
|
||||||
|
if (this.recipes01 && this.isHasMore) {
|
||||||
|
this.recipes01 = [...this.recipes01, ...Recipe01];
|
||||||
|
} else {
|
||||||
|
this.recipes01 = Recipe01;
|
||||||
|
}
|
||||||
|
this.recipes = {
|
||||||
|
...recipesWithoutRecipe01,
|
||||||
|
Recipe01: [],
|
||||||
|
};
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.offset += 10;
|
||||||
|
this.isLoaded = true;
|
||||||
|
this.isHasMore = hasMore;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setRecipeVersion(event: Event) {
|
||||||
|
this.recipeVersion.next((event.target as HTMLInputElement).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
getRecipeVersions() {
|
||||||
|
if (this.recipeVersionData.length > 0) return;
|
||||||
|
this._recipeService.getRecipeVersions().subscribe((versions) => {
|
||||||
|
this.recipeVersionData = versions;
|
||||||
|
this.recipeVersions = versions;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
openJsonTab() {
|
openJsonTab() {
|
||||||
window.open(environment.api + '/recipes/json', '_blank');
|
window.open(
|
||||||
|
environment.api + `/recipes/${this.currentRecipeVersion}/json`,
|
||||||
|
'_blank'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
server/.gitignore
vendored
2
server/.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
/cofffeemachineConfig
|
/cofffeemachineConfig/*
|
||||||
**/*.log
|
**/*.log
|
||||||
token.json
|
token.json
|
||||||
client_secret.json
|
client_secret.json
|
||||||
|
|
|
||||||
1
server/cofffeemachineConfig
Submodule
1
server/cofffeemachineConfig
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 9d6f2eb9c961e256c97b81ca9829eb57e5d890a9
|
||||||
|
|
@ -4,11 +4,14 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"recipe-manager/models"
|
"recipe-manager/models"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readFile() *models.Recipe {
|
func readFile(version string) *models.Recipe {
|
||||||
file, err := os.Open("data/data.json")
|
path := filepath.Join("cofffeemachineConfig", version)
|
||||||
|
file, err := os.Open(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error when open file: %s", err)
|
log.Fatalf("Error when open file: %s", err)
|
||||||
|
|
@ -30,16 +33,56 @@ func readFile() *models.Recipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
recipe *models.Recipe
|
CurrentVersion string
|
||||||
|
AllVersions []string
|
||||||
|
recipe *models.Recipe
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewData() *Data {
|
func NewData() *Data {
|
||||||
|
|
||||||
|
files, err := filepath.Glob("cofffeemachineConfig/coffeethai02_*.json")
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Error when scan recipe files:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(files, func(i, j int) bool {
|
||||||
|
file1, err := os.Stat(files[i])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Error when get file info:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file2, err := os.Stat(files[j])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Error when get file info:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return file1.ModTime().After(file2.ModTime())
|
||||||
|
})
|
||||||
|
|
||||||
|
for i := 0; i < len(files); i++ {
|
||||||
|
files[i] = filepath.Base(files[i])
|
||||||
|
}
|
||||||
|
|
||||||
return &Data{
|
return &Data{
|
||||||
recipe: readFile(),
|
CurrentVersion: "coffeethai02_580.json",
|
||||||
|
AllVersions: files,
|
||||||
|
recipe: readFile("coffeethai02_580.json"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) GetRecipe() models.Recipe {
|
func (d *Data) GetRecipe(version string) models.Recipe {
|
||||||
|
|
||||||
|
if version == "" || version == d.CurrentVersion {
|
||||||
|
return *d.recipe
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Change recipe to version:", version)
|
||||||
|
|
||||||
|
// change current version and read new recipe
|
||||||
|
d.CurrentVersion = version
|
||||||
|
d.recipe = readFile(version)
|
||||||
return *d.recipe
|
return *d.recipe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
236126
server/data/data.json
236126
server/data/data.json
File diff suppressed because one or more lines are too long
|
|
@ -35,7 +35,9 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
take = newTake
|
take = newTake
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe := rr.data.GetRecipe()
|
version := r.URL.Query().Get("version")
|
||||||
|
|
||||||
|
recipe := rr.data.GetRecipe(version)
|
||||||
searchQuery := r.URL.Query().Get("search")
|
searchQuery := r.URL.Query().Get("search")
|
||||||
|
|
||||||
if searchQuery != "" {
|
if searchQuery != "" {
|
||||||
|
|
@ -62,8 +64,9 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
"recipes": recipe,
|
"fileName": rr.data.CurrentVersion,
|
||||||
"hasMore": isHasMore,
|
"recipes": recipe,
|
||||||
|
"hasMore": isHasMore,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -86,9 +89,15 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
http.Error(w, "Recipe not found", http.StatusNotFound)
|
http.Error(w, "Recipe not found", http.StatusNotFound)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/json", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/{version}/json", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
version := chi.URLParam(r, "version")
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(rr.data.GetRecipe())
|
json.NewEncoder(w).Encode(rr.data.GetRecipe(version))
|
||||||
|
})
|
||||||
|
|
||||||
|
r.Get("/versions", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
json.NewEncoder(w).Encode(rr.data.AllVersions)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue