implement a multi-file template interpreter
This commit is contained in:
33
examples/react-app-generator/templates/api-client.tmpl
Normal file
33
examples/react-app-generator/templates/api-client.tmpl
Normal file
@ -0,0 +1,33 @@
|
||||
// API client for {{.Entity.Name}}
|
||||
import { apiRequest } from './client';
|
||||
|
||||
export interface {{.Entity.Name}} {
|
||||
{{range .Entity.Fields}} {{.Name}}: {{if eq .Type "string"}}string{{else if eq .Type "int"}}number{{else if eq .Type "boolean"}}boolean{{else if eq .Type "timestamp"}}Date{{else if eq .Type "text"}}string{{else}}any{{end}};
|
||||
{{end}}}
|
||||
|
||||
export const {{.Entity.Name | lower}}Api = {
|
||||
// Get all {{.Entity.Name | lower}}s
|
||||
getAll: async (): Promise<{{.Entity.Name}}[]> => {
|
||||
return apiRequest('GET', '/{{.Entity.Name | lower}}s');
|
||||
},
|
||||
|
||||
// Get {{.Entity.Name | lower}} by ID
|
||||
getById: async (id: string): Promise<{{.Entity.Name}}> => {
|
||||
return apiRequest('GET', `/{{.Entity.Name | lower}}s/${id}`);
|
||||
},
|
||||
|
||||
// Create new {{.Entity.Name | lower}}
|
||||
create: async (data: Omit<{{.Entity.Name}}, 'id' | 'created_at' | 'updated_at'>): Promise<{{.Entity.Name}}> => {
|
||||
return apiRequest('POST', '/{{.Entity.Name | lower}}s', data);
|
||||
},
|
||||
|
||||
// Update {{.Entity.Name | lower}}
|
||||
update: async (id: string, data: Partial<{{.Entity.Name}}>): Promise<{{.Entity.Name}}> => {
|
||||
return apiRequest('PUT', `/{{.Entity.Name | lower}}s/${id}`, data);
|
||||
},
|
||||
|
||||
// Delete {{.Entity.Name | lower}}
|
||||
delete: async (id: string): Promise<void> => {
|
||||
return apiRequest('DELETE', `/{{.Entity.Name | lower}}s/${id}`);
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user