Files
hatchet/pkg/repository/slack.go
Gabe Ruttner 2fdc47a6af feat: multiple slot types (#2927)
* feat: adds support for multiple slot types, primarily motivated by durable slots

---------

Co-authored-by: mrkaye97 <mrkaye97@gmail.com>
2026-02-17 05:43:47 -08:00

88 lines
2.1 KiB
Go

package repository
import (
"context"
"github.com/google/uuid"
"github.com/hatchet-dev/hatchet/pkg/repository/sqlcv1"
)
type UpsertSlackWebhookOpts struct {
TeamId string `validate:"required,min=1,max=255"`
TeamName string `validate:"required,min=1,max=255"`
ChannelId string `validate:"required,min=1,max=255"`
ChannelName string `validate:"required,min=1,max=255"`
WebhookURL []byte `validate:"required,min=1"`
}
type SlackRepository interface {
UpsertSlackWebhook(ctx context.Context, tenantId uuid.UUID, opts *UpsertSlackWebhookOpts) (*sqlcv1.SlackAppWebhook, error)
ListSlackWebhooks(ctx context.Context, tenantId uuid.UUID) ([]*sqlcv1.SlackAppWebhook, error)
GetSlackWebhookById(ctx context.Context, id uuid.UUID) (*sqlcv1.SlackAppWebhook, error)
DeleteSlackWebhook(ctx context.Context, tenantId uuid.UUID, id uuid.UUID) error
}
type slackRepository struct {
*sharedRepository
}
func newSlackRepository(shared *sharedRepository) SlackRepository {
return &slackRepository{
sharedRepository: shared,
}
}
func (r *slackRepository) UpsertSlackWebhook(ctx context.Context, tenantId uuid.UUID, opts *UpsertSlackWebhookOpts) (*sqlcv1.SlackAppWebhook, error) {
if err := r.v.Validate(opts); err != nil {
return nil, err
}
return r.queries.UpsertSlackWebhook(
ctx,
r.pool,
sqlcv1.UpsertSlackWebhookParams{
Tenantid: tenantId,
Teamid: opts.TeamId,
Teamname: opts.TeamName,
Channelid: opts.ChannelId,
Channelname: opts.ChannelName,
Webhookurl: opts.WebhookURL,
},
)
}
func (r *slackRepository) ListSlackWebhooks(ctx context.Context, tenantId uuid.UUID) ([]*sqlcv1.SlackAppWebhook, error) {
return r.queries.ListSlackWebhooks(
ctx,
r.pool,
tenantId,
)
}
func (r *slackRepository) GetSlackWebhookById(ctx context.Context, id uuid.UUID) (*sqlcv1.SlackAppWebhook, error) {
return r.queries.GetSlackWebhookById(
ctx,
r.pool,
id,
)
}
func (r *slackRepository) DeleteSlackWebhook(ctx context.Context, tenantId uuid.UUID, id uuid.UUID) error {
return r.queries.DeleteSlackWebhook(
ctx,
r.pool,
sqlcv1.DeleteSlackWebhookParams{
Tenantid: tenantId,
ID: id,
},
)
}