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