commit
530c24b019
35 changed files with 3601 additions and 0 deletions
src/konfa
44
src/konfa/channel.go
Normal file
44
src/konfa/channel.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package konfa
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/royalcat/konfa-server/pkg/uuid"
|
||||
"github.com/royalcat/konfa-server/src/store"
|
||||
)
|
||||
|
||||
func (c *Service) CreateChannel(ctx context.Context, serverID uuid.UUID, name string) (uuid.UUID, error) {
|
||||
channel := store.TextChannel{
|
||||
ID: uuid.New(),
|
||||
ServerID: serverID,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
var idrow store.IDRow
|
||||
_, err := c.db.NewInsert().Model(&channel).Returning("id").Exec(ctx, &idrow)
|
||||
if err != nil {
|
||||
return idrow.ID, err
|
||||
}
|
||||
|
||||
return idrow.ID, nil
|
||||
}
|
||||
|
||||
func (c *Service) GetChannel(ctx context.Context, serverID uuid.UUID, channelID uuid.UUID) (store.TextChannel, error) {
|
||||
var channel store.TextChannel
|
||||
err := c.db.NewSelect().
|
||||
Model(&channel).
|
||||
// Where("server_id = ?", serverID).
|
||||
Where("id = ?", channelID).
|
||||
Scan(ctx)
|
||||
|
||||
return channel, err
|
||||
}
|
||||
|
||||
func (c *Service) ListChannelsOnServer(ctx context.Context, serverID uuid.UUID) ([]store.TextChannel, error) {
|
||||
var channels []store.TextChannel
|
||||
err := c.db.NewSelect().
|
||||
Model(&channels).
|
||||
Where("server_id = ?", serverID).
|
||||
Scan(ctx)
|
||||
return channels, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue