Added Optional channel description name to channel creation, adjusted tests
This commit is contained in:
parent
51f5f1005a
commit
77cfe75043
@ -4,6 +4,7 @@ import (
|
|||||||
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
||||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||||
ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken"
|
ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken"
|
||||||
|
"blackforestbytes.com/simplecloudnotifier/db/impl/primary"
|
||||||
"blackforestbytes.com/simplecloudnotifier/models"
|
"blackforestbytes.com/simplecloudnotifier/models"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
@ -180,6 +181,8 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
|||||||
type body struct {
|
type body struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Subscribe *bool `json:"subscribe"`
|
Subscribe *bool `json:"subscribe"`
|
||||||
|
|
||||||
|
Description *string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var u uri
|
var u uri
|
||||||
@ -233,7 +236,15 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
|||||||
|
|
||||||
subscribeKey := h.app.GenerateRandomAuthKey()
|
subscribeKey := h.app.GenerateRandomAuthKey()
|
||||||
|
|
||||||
channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey)
|
cChannel := primary.CreateChanel{
|
||||||
|
UserId: u.UserID,
|
||||||
|
IntName: channelInternalName,
|
||||||
|
SubscribeKey: subscribeKey,
|
||||||
|
DisplayName: channelDisplayName,
|
||||||
|
Description: b.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
channel, err := h.database.CreateChannel(ctx, cChannel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err)
|
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,15 @@ func (db *Database) GetChannelByID(ctx db.TxContext, chanid models.ChannelID) (*
|
|||||||
return &channel, nil
|
return &channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispName string, intName string, subscribeKey string) (models.Channel, error) {
|
type CreateChanel struct {
|
||||||
|
UserId models.UserID
|
||||||
|
DisplayName string
|
||||||
|
IntName string
|
||||||
|
SubscribeKey string
|
||||||
|
Description *string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Database) CreateChannel(ctx db.TxContext, channel CreateChanel) (models.Channel, error) {
|
||||||
tx, err := ctx.GetOrCreateTransaction(db)
|
tx, err := ctx.GetOrCreateTransaction(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Channel{}, err
|
return models.Channel{}, err
|
||||||
@ -66,10 +74,11 @@ func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispNa
|
|||||||
|
|
||||||
entity := models.ChannelDB{
|
entity := models.ChannelDB{
|
||||||
ChannelID: models.NewChannelID(),
|
ChannelID: models.NewChannelID(),
|
||||||
OwnerUserID: userid,
|
OwnerUserID: channel.UserId,
|
||||||
DisplayName: dispName,
|
DisplayName: channel.DisplayName,
|
||||||
InternalName: intName,
|
InternalName: channel.IntName,
|
||||||
SubscribeKey: subscribeKey,
|
SubscribeKey: channel.SubscribeKey,
|
||||||
|
DescriptionName: channel.Description,
|
||||||
TimestampCreated: time2DB(time.Now()),
|
TimestampCreated: time2DB(time.Now()),
|
||||||
TimestampLastSent: nil,
|
TimestampLastSent: nil,
|
||||||
MessagesSent: 0,
|
MessagesSent: 0,
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
scn "blackforestbytes.com/simplecloudnotifier"
|
scn "blackforestbytes.com/simplecloudnotifier"
|
||||||
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
||||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||||
|
"blackforestbytes.com/simplecloudnotifier/db/impl/primary"
|
||||||
"blackforestbytes.com/simplecloudnotifier/db/simplectx"
|
"blackforestbytes.com/simplecloudnotifier/db/simplectx"
|
||||||
"blackforestbytes.com/simplecloudnotifier/google"
|
"blackforestbytes.com/simplecloudnotifier/google"
|
||||||
"blackforestbytes.com/simplecloudnotifier/models"
|
"blackforestbytes.com/simplecloudnotifier/models"
|
||||||
@ -331,7 +332,13 @@ func (app *Application) GetOrCreateChannel(ctx *AppContext, userid models.UserID
|
|||||||
|
|
||||||
subscribeKey := app.GenerateRandomAuthKey()
|
subscribeKey := app.GenerateRandomAuthKey()
|
||||||
|
|
||||||
newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey)
|
channel := primary.CreateChanel{
|
||||||
|
UserId: userid,
|
||||||
|
IntName: intChanName,
|
||||||
|
SubscribeKey: subscribeKey,
|
||||||
|
DisplayName: displayChanName,
|
||||||
|
}
|
||||||
|
newChan, err := app.Database.Primary.CreateChannel(ctx, channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Channel{}, err
|
return models.Channel{}, err
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,16 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "display_name")
|
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "display_name")
|
||||||
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "internal_name")
|
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "internal_name")
|
||||||
}
|
}
|
||||||
|
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", uid), gin.H{
|
||||||
|
"name": "withdesc",
|
||||||
|
"description": "desc",
|
||||||
|
})
|
||||||
|
|
||||||
|
{
|
||||||
|
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", uid))
|
||||||
|
tt.AssertEqual(t, "chan.len", 3, len(clist.Channels))
|
||||||
|
tt.AssertEqual(t, "description_name", "desc", clist.Channels[2]["description_name"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateChannelNameTooLong(t *testing.T) {
|
func TestCreateChannelNameTooLong(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user