OOPhoto - No More Validation In The Controller

<!--- Param FORM fields. --->
<cfparam
	name="ARGUMENTS.Data.Form.photo_id"
	type="numeric"
	default="0"
	/>
 
<cfparam
	name="ARGUMENTS.Data.Form.comment"
	type="string"
	default=""
	/>
 
 
<!--- Create a new comment object. --->
<cfset LOCAL.Comment = ARGUMENTS.Data.Cache.Factory
	.Get( "CommentService" )
	.New()
	/>
 
<!---
	Load the form data into the comment object. Be careful
	about loading the photo - an invalid ID will cause an
	exception to be thrown.
--->
<cfset LOCAL.Comment.SetComment( ARGUMENTS.Data.Form.comment ) />
 
<!--- Try to load the photo. --->
<cftry>
	<cfset LOCAL.Comment.SetPhoto(
		ARGUMENTS.Data.Cache.Factory
			.Get( "PhotoService" )
			.Load( ARGUMENTS.Data.Form.photo_id )
		) />
 
	<cfcatch>
		<!--- Photo was not valid, leave empty. --->
	</cfcatch>
</cftry>
 
 
<!--- Validate the comment. --->
<cfset LOCAL.ValidationErrors = LOCAL.Comment.Validate() />
 
 
<!--- Check to see if we have any errors. --->
<cfif StructCount( LOCAL.ValidationErrors )>
 
	<!---
		There were object validation errors. Since this is an
		API call, we need to translate the object validation
		errors into user-friendly errors.
	--->
	<cfif StructKeyExists( LOCAL.ValidationErrors, "Photo" )>
 
		<cfset ArrayAppend(
			ARGUMENTS.Data.APIResult.Errors,
			"The selected photo could not be found"
			) />
 
	</cfif>
 
	<cfif StructKeyExists( LOCAL.ValidationErrors, "Comment" )>
 
		<cfset ArrayAppend(
			ARGUMENTS.Data.APIResult.Errors,
			"Please enter your comment"
			) />
 
	</cfif>
 
 
	<!--- There were errors. Flag API request at unsuccessful. --->
	<cfset ARGUMENTS.Data.APIResult.Success = false />
 
<cfelse>
 
	<!--- Save comment. --->
	<cfset ARGUMENTS.Data.Cache.Factory
		.Get( "CommentService" )
		.SaveWithTransaction( LOCAL.Comment )
		/>
 
	<!--- Return the new ID as the data. --->
	<cfset ARGUMENTS.Data.APIResult.Data = LOCAL.Comment.GetID() />
 
</cfif>

For Cut-and-Paste