Files
svc-api-x/v1/resources/svc.cfc
T
2025-02-05 22:08:29 +03:00

74 lines
2.8 KiB
Plaintext

<cfcomponent extends="taffy.core.resource" taffy:uri="/services/{svcId}">
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/>
</cfsilent>
<cffunction name="get" hint="Сервис"><!--- *** TODO проверка принадлежности тенанту --->
<cfargument name="svcId" type="string" required=true hint="type:integer"/>
<cftry>
<cfset this.helper.validateField(arguments, "svcId", "integer")/>
<cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch>
</cftry>
<!--- <cfdump var=#arguments#/> <cfabort/> --->
<cfquery name="local.qSvc" result="local.result">
select
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
<m:field title="ID" cfSqlType="CF_SQL_INTEGER">s.svc_id</m:field>
<m:field>s.svc</m:field>
<m:field>s.svc_short</m:field>
<m:field>s.code</m:field>
<m:field>(select url from svc_operation so where so.operation='create' AND so.svc_id=s.svc_id limit 1) as create_url</m:field>
<m:field formatter=#request.castToBool#>s.is_production_ready</m:field>
<m:field>s.descr</m:field>
<m:field>s.man</m:field>
</m:field_set>
from svc s
where svc_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcId#" null=#!isValid('integer',arguments.svcId)#/>
</cfquery>
<cfquery name="local.qSvcOperation" result="local.result">
select
<m:field_set titleMapOut="local.operationsMap" lengthOut="local.fieldCount">
<m:field>j.svc_operation_id</m:field>
<m:field>j.operation</m:field>
<m:field>j.url</m:field>
<m:field>j.descr</m:field>
<m:field>j.man</m:field>
</m:field_set>
from svc_operation j
where j.svc_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcId#" null=#!isValid('integer',arguments.svcId)#/>
</cfquery>
<cfif local.qSvc.recordCount EQ 0>
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
</cfif>
<cfset var out=structNew("linked")/>
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
<!--- <cfset var rec={}/>
<cfset this.helper.appendRecord(rec, "", local.titleMap, local.qSvc, this.helper.snake2camel)/>
<cfset "out.svc"=rec/> --->
<cfset "out.svc" = this.helper.appendRecord(
structNew("linked"), "", local.titleMap, local.qSvc, this.helper.snake2camel
)/>
<cfset "out.svc.operations"=[]/>
<cfloop query=#local.qSvcOperation#>
<cfset arrayAppend(out.svc.operations, this.helper.appendRecord(structNew("linked"), "", local.operationsMap, local.qSvcOperation, this.helper.snake2camel))/>
</cfloop>
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
<cfreturn representationOf(out) />
</cffunction>
</cfcomponent>