initial
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
component
|
||||
extends="taffy.core.resource"
|
||||
taffy_uri="/authenticate" {
|
||||
|
||||
public function post(username, password, deviceId) {
|
||||
|
||||
//implementation of verifying the username/password are up to you...
|
||||
var authSuccess = authenticate(username, password);
|
||||
|
||||
if (!authSuccess){
|
||||
return noData().withStatus(401, "Not Authorized");
|
||||
}
|
||||
|
||||
//create a new device token:
|
||||
var deviceToken = createUUID();
|
||||
|
||||
//saving the device token to the database is up to you...
|
||||
saveDeviceToken(username, deviceId, deviceToken);
|
||||
|
||||
//tell the device auth was successful and give it the device token
|
||||
return representationOf({ token: deviceToken }).withStatus(200, "OK");
|
||||
|
||||
}
|
||||
|
||||
private function authenticate(username, password){ return true; }
|
||||
private function saveDeviceToken(username, deviceId, deviceToken){}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<cfcomponent extends="taffy.core.resource" taffy_uri="/maints/{maintId}">
|
||||
|
||||
<cfimport prefix="m" taglib="../lib"/>
|
||||
<cfset helper=CreateObject("component","lib.rest_api_helper")/>
|
||||
|
||||
|
||||
<cffunction name="get">
|
||||
<cfargument name="maintId" type="numeric" required=true/>
|
||||
<!---<cfthrow type="custom" message="test traces"/>--->
|
||||
<cfset var out={}/>
|
||||
|
||||
<cfquery name="local.qRead">
|
||||
select
|
||||
<m:field_set titleMapOut="local.titleMap" lengthOut="fieldCount">
|
||||
<m:field>m.maint_id</m:field>
|
||||
<m:field container="equipment">m.equipment_id</m:field>
|
||||
<m:field container="equipment">e.equipment</m:field>
|
||||
<m:field container="maintProgram">m.maint_program_id</m:field>
|
||||
<m:field container="maintProgram">p.maint_program</m:field>
|
||||
<m:field container="maintSchedule">m.maint_schedule_id</m:field>
|
||||
<m:field container="maintSchedule">h.maint_schedule</m:field>
|
||||
<m:field>m.maint</m:field>
|
||||
<m:field>m.ok</m:field>
|
||||
<m:field>m.issue_number</m:field>
|
||||
<m:field>convert(varchar(25), m.dt_maint, 120) as dt_maint</m:field>
|
||||
<m:field container="serviceContract">m.service_contract_id</m:field>
|
||||
<m:field container="serviceContract">c.service_contract</m:field>
|
||||
<m:field container="serviceContract">convert(varchar(25), c.dt_contract, 120) as dt_contract</m:field>
|
||||
<m:field>m.creator_id</m:field>
|
||||
<m:field>m.modifier_id</m:field>
|
||||
<m:field>convert(varchar(25), m.dt_created, 120) as dt_created</m:field>
|
||||
<m:field>convert(varchar(25), m.dt_modified, 120) as dt_modified</m:field>
|
||||
<m:field>m.descr</m:field>
|
||||
<m:field container="contractor">m.contractor_id</m:field>
|
||||
<m:field container="contractor">v.vendor as contractor</m:field>
|
||||
<m:field>convert(varchar(25), m.dt_appeared, 120) as dt_appeared</m:field>
|
||||
<m:field container="engineer">m.engineer_id</m:field>
|
||||
<m:field container="engineer">n.contact as engineer</m:field>
|
||||
<m:field container="workOrder">m.work_order_id</m:field>
|
||||
<m:field container="workOrder">w.work_order</m:field>
|
||||
</m:field_set>
|
||||
from maint m
|
||||
left outer join maint_schedule h on (m.maint_schedule_id=h.maint_schedule_id)
|
||||
left outer join equipment e on (isnull(m.equipment_id,h.equipment_id)=e.equipment_id)
|
||||
left outer join maint_program p on (isnull(m.maint_program_id,h.maint_program_id)=p.maint_program_id)
|
||||
left outer join contact n on (m.engineer_id=n.contact_id)
|
||||
left outer join service_contract c on (m.service_contract_id=c.service_contract_id)
|
||||
left outer join vendor v on (isnull(m.contractor_id,c.vendor_id)=v.vendor_id)
|
||||
left outer join work_order w on (m.work_order_id=w.work_order_id)
|
||||
where maint_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.maintId#" />
|
||||
</cfquery>
|
||||
|
||||
<cfif local.qRead.recordCount EQ 0>
|
||||
<cfreturn noData().withStatus(404, "Record Not Found") />
|
||||
</cfif>
|
||||
|
||||
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
||||
|
||||
<cfset var rec={}/>
|
||||
<cfset helper.appendRecord(rec, "", local.titleMap, local.qRead, helper.snake2camel)/>
|
||||
<cfset "out.maint"=rec/>
|
||||
|
||||
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
|
||||
<cfreturn representationOf(out) />
|
||||
</cffunction>
|
||||
|
||||
|
||||
<cffunction name="patch">
|
||||
<cfargument name="maintId" type="numeric" required=true/>
|
||||
<cfargument name="ok" type="boolean" required=true/>
|
||||
|
||||
<!--- <cfquery name="local.qRead">
|
||||
select count(*) as cnt
|
||||
from maint
|
||||
where maint_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.maintId#" />
|
||||
</cfquery>
|
||||
<cfif local.qRead.cnt EQ 0>
|
||||
<cfreturn noData().withStatus(404, "Record Not Found") />
|
||||
</cfif>--->
|
||||
|
||||
<cfquery name="local.qRead">
|
||||
update maint
|
||||
set ok=<cfqueryparam cfsqltype="cf_sql_bit" value="#arguments.ok#" />
|
||||
where maint_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.maintId#" />;
|
||||
select @@rowcount as cnt;
|
||||
</cfquery>
|
||||
|
||||
<cfif local.qRead.cnt EQ 0>
|
||||
<cfreturn noData().withStatus(404, "Record Not Found") />
|
||||
</cfif>
|
||||
|
||||
<cfreturn noData().withStatus(204, "No Content") /><!---*** или быть проще и вернуть 200 ОК?--->
|
||||
</cffunction>
|
||||
|
||||
|
||||
<cffunction name="delete">
|
||||
<cfargument name="maintId" type="numeric" required=true/>
|
||||
<cfreturn noData().withStatus(405, "Method Not Allowed") />
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,61 @@
|
||||
<!---https://medium.com/analytics-vidhya/building-an-awesome-restful-apis-with-coldfusion-86422f6b2b6f--->
|
||||
<cfcomponent extends="taffy.core.resource" <!---taffy_uri="/user/"---> hint="User specific functions" displayname="user">
|
||||
|
||||
<!--- User Login --->
|
||||
<cffunction name="loginUser" access="public" output="false" hint="Login User" returntype="struct">
|
||||
|
||||
<cfargument name="structform" required="true" type="any" />
|
||||
|
||||
<cfset var resObj = {}>
|
||||
|
||||
<!--- <cfquery> to check user credentials --->
|
||||
|
||||
<cfif 1 eq 1> <!--- if user credentials are valid --->
|
||||
<cfset expdt = dateAdd("n",30,now())>
|
||||
<cfset utcDate = dateDiff('s', dateConvert('utc2Local', createDateTime(1970, 1, 1, 0, 0, 0)), expdt) />
|
||||
|
||||
<cfset jwt = new jwt(Application.jwtkey)>
|
||||
<cfset payload = {"iss" = "restdemo", "exp" = utcDate, "sub": "JWT Token"}>
|
||||
<cfset token = jwt.encode(payload)>
|
||||
|
||||
<cfset resObj["success"] = true>
|
||||
<cfset resObj["message"] = "Login Successful">
|
||||
<cfset resObj["token"] = token>
|
||||
<cfelse> <!--- if user credentials are invalid --->
|
||||
<cfset resObj["success"] = false>
|
||||
<cfset resObj["message"] = "Incorrect login credentials.">
|
||||
</cfif>
|
||||
|
||||
<cfreturn resObj>
|
||||
|
||||
</cffunction>
|
||||
|
||||
|
||||
<!--- User Details --->
|
||||
<cffunction name="userDetails" access="public" output="false" hint="Get user details" returntype="struct">
|
||||
|
||||
<cfargument name="userid" required="true" type="numeric" />
|
||||
<cfset var resObj = {}>
|
||||
<cfset returnArray = ArrayNew(1) />
|
||||
|
||||
<!--- <cfquery> to get user details --->
|
||||
|
||||
<cfif 1 neq 1> <!--- if user not found --->
|
||||
<cfset resObj["success"] = false>
|
||||
<cfset resObj["message"] = "Incorrect user id provided.">
|
||||
<cfelse> <!--- if user found --->
|
||||
<cfset userStruct = StructNew() />
|
||||
<cfset userStruct["firstname"] = "John" />
|
||||
<cfset userStruct["lastname"] = "Doe" />
|
||||
<cfset userStruct["email"] = "johndoe@fakemail.com" />
|
||||
<cfset ArrayAppend(returnArray,userStruct) />
|
||||
|
||||
<cfset resObj["success"] = true>
|
||||
<cfset resObj["data"] = SerializeJSON(returnArray)>
|
||||
|
||||
</cfif>
|
||||
|
||||
<cfreturn resObj>
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
Reference in New Issue
Block a user