├── .vscode ├── launch.json └── settings.json └── src ├── Adapters └── CategoryAdapter.tlpp ├── Controllers ├── BaseController.tlpp └── CategoriesController.tlpp ├── Filter ├── AuthFilter.tlpp ├── StartFilter.tlpp └── StopFilter.tlpp ├── Models └── Category.prw └── Services └── CategoryService.tlpp /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "totvs_tdsreplay_debug", 6 | "request": "launch", 7 | "name": "${1:%tds.package.tdsreplay.debug%}", 8 | "cwb": "${workspaceFolder}", 9 | "tdsReplayFile": "", 10 | "ignoreFiles": false, 11 | "password": "", 12 | "includeSources": "*", 13 | "excludeSources": "" 14 | }, 15 | { 16 | "type": "totvs_language_debug", 17 | "request": "launch", 18 | "name": "TOTVS Language Debug", 19 | "program": "${command:AskForProgramName}", 20 | "cwb": "${workspaceFolder}", 21 | "smartclientBin": "D:\\TOTVS_2Easy\\Protheus\\Protheus\\bin\\smartclient\\smartclient.exe", 22 | "isMultiSession": true, 23 | "enableMultiThread": true, 24 | "enableTableSync": true 25 | } 26 | ], 27 | "lastPrograms": [ 28 | { 29 | "label": "u_xxx" 30 | }, 31 | { 32 | "label": "u_CheckZ01" 33 | }, 34 | { 35 | "label": "u_ch" 36 | } 37 | ], 38 | "lastProgramExecuted": "u_CheckZ01" 39 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "totvsLanguageServer.welcomePage": false 3 | } -------------------------------------------------------------------------------- /src/Adapters/CategoryAdapter.tlpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielAlbuquerque/tlpp-rest-api-boilerplate/ee0837d25f85bd8df660dd51e18cf4c7e9834927/src/Adapters/CategoryAdapter.tlpp -------------------------------------------------------------------------------- /src/Controllers/BaseController.tlpp: -------------------------------------------------------------------------------- 1 | #include 'tlpp-core.th' 2 | #include 'tlpp-rest.th' 3 | 4 | Namespace ErpServ.Api.Controllers 5 | 6 | Class BaseController 7 | Public Method New() Constructor 8 | EndClass 9 | 10 | Method New() Class BaseController 11 | Return 12 | -------------------------------------------------------------------------------- /src/Controllers/CategoriesController.tlpp: -------------------------------------------------------------------------------- 1 | #include 'tlpp-core.th' 2 | #include 'tlpp-rest.th' 3 | 4 | Namespace ErpServ.Api.Controllers 5 | 6 | Using Namespace ErpServ.Api.Services 7 | 8 | Class CategoriesController From BaseController 9 | Private Data _service 10 | 11 | Public Method New() Constructor 12 | 13 | @Get("/api/v1/categories") 14 | Public Method Get() 15 | 16 | @Post("/api/v1/categories") 17 | Public Method Post() 18 | EndClass 19 | 20 | Method New() Class CategoriesController 21 | _Super:New() 22 | Self:_service := CategoryService():New() 23 | return self 24 | 25 | Method Get() Class CategoriesController 26 | Local jData := Self:_service:GetData() 27 | 28 | If !( jData['success'] ) 29 | oRest:SetStatusCode( jData['errorCode'] ) 30 | oRest:SetFault( jData['errorMessage'] ) 31 | EndIf 32 | 33 | oRest:SetResponse(jData['payload']) 34 | return .T. 35 | 36 | Method Post() Class CategoriesController 37 | Local jBody := JsonObject():New() 38 | 39 | jBody:FromJson( oRest:GetBodyRequest() ) 40 | 41 | Self:_service:Save( jBody ) 42 | 43 | oRest:setResponse(jBody:ToJson()) 44 | return .T. 45 | -------------------------------------------------------------------------------- /src/Filter/AuthFilter.tlpp: -------------------------------------------------------------------------------- 1 | #Include 'protheus.ch' 2 | 3 | Namespace ErpServ.Api.Filters 4 | 5 | /*/{Protheus.doc} AuthFilter 6 | Validate se o usuario pode acessar a API 7 | @type function 8 | @version 1.0 9 | @author daniel.albuquerque 10 | @since 11/01/2022 11 | @param cUser, character, usuario 12 | @param cPass, character, senha 13 | @return logical, continua 14 | /*/ 15 | User Function AuthFilter( cUser As Character, cPass As Character ) As Logical 16 | Return cUser == 'test_user' .and. cPass == 'test_pass' 17 | -------------------------------------------------------------------------------- /src/Filter/StartFilter.tlpp: -------------------------------------------------------------------------------- 1 | #Include 'protheus.ch' 2 | 3 | Namespace ErpServ.Api.Filters 4 | 5 | User Function StartFilter() As Logical 6 | Conout("Iniciando o ambiente") 7 | RpcSetType(3) 8 | RpcSetEnv("99", "01") 9 | return .T. 10 | -------------------------------------------------------------------------------- /src/Filter/StopFilter.tlpp: -------------------------------------------------------------------------------- 1 | #Include 'protheus.ch' 2 | 3 | Namespace ErpServ.Api.Filters 4 | 5 | User Function StopFilter() As Logical 6 | Conout("Fechando o ambiente") 7 | RpcClearEnv() 8 | return .T. 9 | -------------------------------------------------------------------------------- /src/Models/Category.prw: -------------------------------------------------------------------------------- 1 | #Include 'protheus.ch' 2 | 3 | User Function Category() 4 | Return 5 | 6 | Static Function ModelDef() 7 | Local oModel := MPFormModel():New("MCATEGORY") 8 | oModel:SetDescription("Categories") 9 | oModel:AddFields('MASTERZ01',,FWFormStruct(1,"Z01")) 10 | oModel:SetPrimaryKey({}) 11 | oModel:GetModel('MASTERZ01'):SetDescription('Categories') 12 | Return oModel 13 | -------------------------------------------------------------------------------- /src/Services/CategoryService.tlpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielAlbuquerque/tlpp-rest-api-boilerplate/ee0837d25f85bd8df660dd51e18cf4c7e9834927/src/Services/CategoryService.tlpp --------------------------------------------------------------------------------