-
Notifications
You must be signed in to change notification settings - Fork 126
/
slack.go
68 lines (58 loc) · 2.06 KB
/
slack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package prisma
import (
"context"
"github.com/hatchet-dev/hatchet/internal/repository"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
"github.com/hatchet-dev/hatchet/internal/validator"
)
type slackRepository struct {
client *db.PrismaClient
v validator.Validator
}
func NewSlackRepository(client *db.PrismaClient, v validator.Validator) repository.SlackRepository {
return &slackRepository{
client: client,
v: v,
}
}
func (r *slackRepository) UpsertSlackWebhook(tenantId string, opts *repository.UpsertSlackWebhookOpts) (*db.SlackAppWebhookModel, error) {
if err := r.v.Validate(opts); err != nil {
return nil, err
}
return r.client.SlackAppWebhook.UpsertOne(
db.SlackAppWebhook.TenantIDTeamIDChannelID(
db.SlackAppWebhook.TenantID.Equals(tenantId),
db.SlackAppWebhook.TeamID.Equals(opts.TeamId),
db.SlackAppWebhook.ChannelID.Equals(opts.ChannelId),
),
).Create(
db.SlackAppWebhook.Tenant.Link(
db.Tenant.ID.Equals(tenantId),
),
db.SlackAppWebhook.TeamID.Set(opts.TeamId),
db.SlackAppWebhook.TeamName.Set(opts.TeamName),
db.SlackAppWebhook.ChannelID.Set(opts.ChannelId),
db.SlackAppWebhook.ChannelName.Set(opts.ChannelName),
db.SlackAppWebhook.WebhookURL.Set(opts.WebhookURL),
).Update(
db.SlackAppWebhook.TeamName.Set(opts.TeamName),
db.SlackAppWebhook.ChannelName.Set(opts.ChannelName),
db.SlackAppWebhook.WebhookURL.Set(opts.WebhookURL),
).Exec(context.Background())
}
func (r *slackRepository) ListSlackWebhooks(tenantId string) ([]db.SlackAppWebhookModel, error) {
return r.client.SlackAppWebhook.FindMany(
db.SlackAppWebhook.TenantID.Equals(tenantId),
).Exec(context.Background())
}
func (r *slackRepository) GetSlackWebhookById(id string) (*db.SlackAppWebhookModel, error) {
return r.client.SlackAppWebhook.FindUnique(
db.SlackAppWebhook.ID.Equals(id),
).Exec(context.Background())
}
func (r *slackRepository) DeleteSlackWebhook(tenantId string, id string) error {
_, err := r.client.SlackAppWebhook.FindUnique(
db.SlackAppWebhook.ID.Equals(id),
).Delete().Exec(context.Background())
return err
}