swirl/dao/mongo/stack.go

45 lines
1000 B
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package mongo
import (
2021-12-06 12:24:22 +00:00
"context"
2017-09-26 12:50:09 +00:00
2021-12-23 11:28:31 +00:00
"github.com/cuigh/swirl/dao"
2021-12-06 12:24:22 +00:00
"go.mongodb.org/mongo-driver/bson"
2017-09-26 12:50:09 +00:00
)
2021-12-06 12:24:22 +00:00
const Stack = "stack"
2021-12-23 11:28:31 +00:00
func (d *Dao) StackGetAll(ctx context.Context) (stacks []*dao.Stack, err error) {
stacks = []*dao.Stack{}
2021-12-06 12:24:22 +00:00
err = d.fetch(ctx, Stack, bson.M{}, &stacks)
2018-04-16 09:21:20 +00:00
return
}
2021-12-23 11:28:31 +00:00
func (d *Dao) StackCreate(ctx context.Context, stack *dao.Stack) (err error) {
2021-12-06 12:24:22 +00:00
return d.create(ctx, Stack, stack)
2018-04-16 09:21:20 +00:00
}
2021-12-23 11:28:31 +00:00
func (d *Dao) StackGet(ctx context.Context, name string) (stack *dao.Stack, err error) {
stack = &dao.Stack{}
2021-12-06 12:24:22 +00:00
found, err := d.find(ctx, Stack, name, stack)
if !found {
return nil, err
}
2018-04-16 09:21:20 +00:00
return
}
2021-12-23 11:28:31 +00:00
func (d *Dao) StackUpdate(ctx context.Context, stack *dao.Stack) (err error) {
2021-12-06 12:24:22 +00:00
update := bson.M{
"$set": bson.M{
"content": stack.Content,
"updated_by": stack.UpdatedBy,
2021-12-16 08:11:16 +00:00
"updated_at": stack.UpdatedAt,
2021-12-06 12:24:22 +00:00
},
}
return d.update(ctx, Stack, stack.Name, update)
2018-04-16 09:21:20 +00:00
}
2021-12-06 12:24:22 +00:00
func (d *Dao) StackDelete(ctx context.Context, name string) (err error) {
return d.delete(ctx, Stack, name)
2018-04-16 09:21:20 +00:00
}