PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/api/resources/artistMember.cfc

http://github.com/atuttle/Taffy
ColdFusion CFScript | 84 lines | 79 code | 5 blank | 0 comment | 0 complexity | 9f94fd102f7fdbd0459d64c7f405885c MD5 | raw file
 1<cfcomponent extends="taffy.core.resource" taffy:uri="/artist/{id}" hint="some hint about this resource">
 2
 3	<cffunction name="get" access="public" output="false">
 4		<cfargument name="id" type="numeric" required="true" />
 5		<cfset var q = ""/>
 6		<cfset var col = "" />
 7		<cfset var rtn = StructNew() />
 8		<cfquery name="q" datasource="cfartgallery">
 9			select * from artists where artistId = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.id#" />
10		</cfquery>
11		<cfif q.recordCount gt 0>
12			<cfloop list="#q.ColumnList#" index="col">
13				<cfset rtn[col] = q[col][1] />
14			</cfloop>
15			<cfreturn representationOf(rtn).withStatus(200) />
16		<cfelse>
17			<cfreturn noData().withStatus(404) />
18		</cfif>
19	</cffunction>
20
21	<cffunction name="put" access="public" output="false">
22		<cfargument name="id" type="numeric" required="true" />
23		<cfargument name="firstname" type="string" required="false" default="" />
24		<cfargument name="lastname" type="string" required="false" default="" />
25		<cfargument name="address" type="string" required="false" default="" hint="some hint about this parameter" />
26		<cfargument name="city" type="string" required="false" default="" />
27		<cfargument name="state" type="string" required="false" default="" />
28		<cfargument name="postalcode" type="string" required="false" default="" />
29		<cfargument name="email" type="string" required="false" default="" />
30		<cfargument name="phone" type="string" required="false" default="" />
31		<cfargument name="fax" type="string" required="false" default="" />
32		<cfargument name="thepassword" type="string" required="false" default="" />
33		<cfset var q = "" />
34		<cfquery name="q" datasource="cfartgallery">
35			update artists
36			set artistid=artistid
37				<cfif len(arguments.firstname)>
38					,firstname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstname#" />
39				</cfif>
40				<cfif len(arguments.lastname)>
41					,lastname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastname#" />
42				</cfif>
43				<cfif len(arguments.address)>
44					,address = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.address#" />
45				</cfif>
46				<cfif len(arguments.city)>
47					,city = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.city#" />
48				</cfif>
49				<cfif len(arguments.state)>
50					,state = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.state#" />
51				</cfif>
52				<cfif len(arguments.postalcode)>
53					,postalcode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.postalcode#" />
54				</cfif>
55				<cfif len(arguments.email)>
56					,email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.email#" />
57				</cfif>
58				<cfif len(arguments.phone)>
59					,phone = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.phone#" />
60				</cfif>
61				<cfif len(arguments.fax)>
62					,fax = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.fax#" />
63				</cfif>
64				<cfif len(arguments.thepassword)>
65					,thepassword = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.thepassword#" />
66				</cfif>
67				where artistid = <cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.id#" />
68		</cfquery>
69		<cfreturn noData().withStatus(200) />
70	</cffunction>
71
72	<cffunction name="delete" access="public" output="false">
73		<cfargument name="id" type="numeric" required="true" />
74		<cfset var q = "" />
75		<cfquery name="q" datasource="cfartgallery">
76			delete from artists where artistid = <cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.id#" />
77		</cfquery>
78		<cfreturn noData().withStatus(200) />
79	</cffunction>
80
81	<cffunction name="someInternalMethod" hint="you should not see this documentation...">
82	</cffunction>
83
84</cfcomponent>