From da248134ed98f8bb3dbaa95cbebb37a4cf0cc788 Mon Sep 17 00:00:00 2001 From: David Lojudice Sobrinho Date: Mon, 14 Aug 2023 15:04:17 -0300 Subject: [PATCH] feat(rest): new Herbs2REST interface --- src/templates/infra/api/rest/index.ejs | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/templates/infra/api/rest/index.ejs b/src/templates/infra/api/rest/index.ejs index 58daa24..60fed45 100644 --- a/src/templates/infra/api/rest/index.ejs +++ b/src/templates/infra/api/rest/index.ejs @@ -1,5 +1,5 @@ const express = require('express') -const { populateMetadata, generateEndpoints } = require('@herbsjs/herbs2rest') +const { endpoints, routes } = require('@herbsjs/herbs2rest') const { herbarium } = require('@herbsjs/herbarium') const controller = require('./controller') @@ -14,27 +14,29 @@ async function rest(app, config) { async function herbs2rest({ server, config }) { - // Herbs2REST will populate the Express endpoints + // Herbs2REST will create Express endpoints // based on your use cases and entities. - // 1. Prepare your use cases metadata if needed - // Ex: - // herbarium.usecases.get('SearchUser').metadata({ - // REST: [{ - // version: 'v1', - // method: 'GET', - // path: '/v1/search/', - // parameters: { query: { id: String } }, - // }] - // }) - - // 2. Populate the metadata - // Each use case will be populated with the metadata: - // version, resource, method, path, parameters, parametersHandler, controller - populateMetadata({ herbarium, controller, version: 'v1' }) - - // 3. Generate the endpoints based on the metadata - generateEndpoints({ herbarium, server }) + // 1. Create endpoints + endpoints({ herbarium, controller }, { + 'v1': (endpoints) => { + // endpoints.ignore('FindUser') + + // endpoints.for('SearchUser').use({ + // method: 'GET', + // path: '/v1/search/', + // parameters: { query: { id: String } }, + // }) + + endpoints.build() + }, + // 'v2': (endpoints) => { + // endpoints.build() + // } + }) + + // 2. Attach the endpoints to Express + routes({ herbarium, server }).attach() }