-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6985fab
commit 4859307
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package template | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/assert" | ||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/servererror" | ||
) | ||
|
||
type Template interface { | ||
CreateEmailTemplate(ctx context.Context, req api.EmailTemplateCreateReq, editors ...api.RequestEditorFn) (*api.EmailTemplateCreateRsp, error) | ||
CreateSMSTemplate(ctx context.Context, req api.SmsTemplateCreateReq, editors ...api.RequestEditorFn) (*api.SmsTemplateCreateRsp, error) | ||
} | ||
|
||
type Impl struct { | ||
client *api.ClientWithResponses | ||
} | ||
|
||
var _ Template = &Impl{} | ||
|
||
// New returns new templates client | ||
func New(client *api.ClientWithResponses) (*Impl, error) { | ||
if err := assert.NotNil(client); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Impl{ | ||
client: client, | ||
}, nil | ||
} | ||
|
||
// CreateEmailTemplate creates a new email template | ||
func (i *Impl) CreateEmailTemplate(ctx context.Context, req api.EmailTemplateCreateReq, editors ...api.RequestEditorFn) (*api.EmailTemplateCreateRsp, error) { | ||
res, err := i.client.EmailTemplateCreateWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// CreateSMSTemplate creates a new SMS template | ||
func (i *Impl) CreateSMSTemplate(ctx context.Context, req api.SmsTemplateCreateReq, editors ...api.RequestEditorFn) (*api.SmsTemplateCreateRsp, error) { | ||
res, err := i.client.SmsTemplateCreateWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters