2022-12-22 16:46:08 +00:00
|
|
|
package operations
|
|
|
|
|
|
|
|
import (
|
2023-04-21 06:49:17 +00:00
|
|
|
. "github.com/reiver/greatape/components/api/protobuf"
|
|
|
|
. "github.com/reiver/greatape/components/api/services"
|
2023-06-26 07:50:54 +00:00
|
|
|
. "github.com/reiver/greatape/components/constants"
|
2023-04-21 06:49:17 +00:00
|
|
|
. "github.com/reiver/greatape/components/contracts"
|
2022-12-22 16:46:08 +00:00
|
|
|
. "github.com/xeronith/diamante/contracts/operation"
|
|
|
|
. "github.com/xeronith/diamante/contracts/service"
|
|
|
|
. "github.com/xeronith/diamante/contracts/system"
|
|
|
|
. "github.com/xeronith/diamante/operation"
|
|
|
|
)
|
|
|
|
|
2023-06-26 07:50:54 +00:00
|
|
|
type (
|
|
|
|
PostToInboxRunner func(IContext, *PostToInboxRequest) (*PostToInboxResult, error)
|
|
|
|
PostToInboxRunners []PostToInboxRunner
|
2022-12-22 16:46:08 +00:00
|
|
|
|
2023-06-26 07:50:54 +00:00
|
|
|
postToInboxOperation struct {
|
|
|
|
Operation
|
|
|
|
|
|
|
|
runners PostToInboxRunners
|
|
|
|
}
|
|
|
|
)
|
2022-12-22 16:46:08 +00:00
|
|
|
|
|
|
|
func PostToInboxOperation() IOperation {
|
|
|
|
return &postToInboxOperation{
|
2023-06-26 07:50:54 +00:00
|
|
|
runners: PostToInboxRunners{
|
|
|
|
PostToInboxService,
|
|
|
|
},
|
2022-12-22 16:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 07:50:54 +00:00
|
|
|
func (operation *postToInboxOperation) Tag() string {
|
|
|
|
return "POST_TO_INBOX"
|
|
|
|
}
|
|
|
|
|
2022-12-22 16:46:08 +00:00
|
|
|
func (operation *postToInboxOperation) Id() (ID, ID) {
|
|
|
|
return POST_TO_INBOX_REQUEST, POST_TO_INBOX_RESULT
|
|
|
|
}
|
|
|
|
|
|
|
|
func (operation *postToInboxOperation) InputContainer() Pointer {
|
|
|
|
return new(PostToInboxRequest)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (operation *postToInboxOperation) OutputContainer() Pointer {
|
|
|
|
return new(PostToInboxResult)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (operation *postToInboxOperation) Execute(context IContext, payload Pointer) (Pointer, error) {
|
2023-06-26 07:50:54 +00:00
|
|
|
if len(operation.runners) <= int(operation.ActiveRunner()) {
|
|
|
|
return nil, ERROR_OPERATION_RUNNER_NOT_AVAILABLE
|
|
|
|
}
|
|
|
|
|
|
|
|
service := operation.runners[operation.ActiveRunner()]
|
|
|
|
if input, valid := payload.(*PostToInboxRequest); valid {
|
|
|
|
return service(context, input)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, ERROR_OPERATION_PAYLOAD_NOT_SUPPORTED
|
2022-12-22 16:46:08 +00:00
|
|
|
}
|