yakworks.api.ResultTrait.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-messages Show documentation
Show all versions of api-messages Show documentation
Models and SPI for message service, api results and problems.
/*
* Copyright 2021 original authors
* SPDX-License-Identifier: Apache-2.0
*/
package yakworks.api
import groovy.transform.CompileStatic
import yakworks.message.Msg
import yakworks.message.MsgKey
/**
* Groovy Trait impl for Result, provides the simple builder methods
*
* @author Joshua Burnett (@basejump)
* @since 1
*/
@CompileStatic
trait ResultTrait implements GenericResult {
String defaultCode //= 'result.ok'
Boolean ok = true
ApiStatus status = HttpStatus.OK
/** backing field for the getMsg */
MsgKey msgKey
String title
Object payload
MsgKey getMsg() {
if(msgKey == null) msgKey = Msg.key(getDefaultCode())
return msgKey
}
void setMsg(MsgKey v) { msgKey = v }
@Override
String toString() {
return ResultUtils.resultToString(this)
}
}