diff --git a/scnserver/api/handler/apiChannel.go b/scnserver/api/handler/apiChannel.go index 8692485..479b1be 100644 --- a/scnserver/api/handler/apiChannel.go +++ b/scnserver/api/handler/apiChannel.go @@ -180,6 +180,8 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse { type body struct { Name string `json:"name"` Subscribe *bool `json:"subscribe"` + + Description *string `json:"description"` } var u uri @@ -233,7 +235,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse { subscribeKey := h.app.GenerateRandomAuthKey() - channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey) + channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey, b.Description) if err != nil { return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err) } diff --git a/scnserver/config.go b/scnserver/config.go index d2df089..1ebe8f6 100644 --- a/scnserver/config.go +++ b/scnserver/config.go @@ -395,8 +395,8 @@ var configProd = func() Config { EnableLogger: true, }, RequestTimeout: 16 * time.Second, - RequestMaxRetry: 8, - RequestRetrySleep: 100 * time.Millisecond, + RequestMaxRetry: 32, + RequestRetrySleep: 32 * time.Millisecond, ReturnRawErrors: false, DummyFirebase: false, FirebaseTokenURI: "https://oauth2.googleapis.com/token", diff --git a/scnserver/db/impl/primary/channels.go b/scnserver/db/impl/primary/channels.go index 4afe6e8..a5c44b2 100644 --- a/scnserver/db/impl/primary/channels.go +++ b/scnserver/db/impl/primary/channels.go @@ -58,7 +58,15 @@ func (db *Database) GetChannelByID(ctx db.TxContext, chanid models.ChannelID) (* 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, userid models.UserID, dispName string, intName string, subscribeKey string, description *string) (models.Channel, error) { tx, err := ctx.GetOrCreateTransaction(db) if err != nil { return models.Channel{}, err @@ -70,6 +78,7 @@ func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispNa DisplayName: dispName, InternalName: intName, SubscribeKey: subscribeKey, + DescriptionName: description, TimestampCreated: time2DB(time.Now()), TimestampLastSent: nil, MessagesSent: 0, diff --git a/scnserver/logic/application.go b/scnserver/logic/application.go index ce631c4..cd386d1 100644 --- a/scnserver/logic/application.go +++ b/scnserver/logic/application.go @@ -331,7 +331,7 @@ func (app *Application) GetOrCreateChannel(ctx *AppContext, userid models.UserID subscribeKey := app.GenerateRandomAuthKey() - newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey) + newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey, nil) if err != nil { return models.Channel{}, err } diff --git a/scnserver/swagger/swagger.json b/scnserver/swagger/swagger.json index f20f397..dd5fb8b 100644 --- a/scnserver/swagger/swagger.json +++ b/scnserver/swagger/swagger.json @@ -3047,6 +3047,9 @@ "handler.CreateChannel.body": { "type": "object", "properties": { + "description": { + "type": "string" + }, "name": { "type": "string" }, diff --git a/scnserver/swagger/swagger.yaml b/scnserver/swagger/swagger.yaml index aaff2c3..4325685 100644 --- a/scnserver/swagger/swagger.yaml +++ b/scnserver/swagger/swagger.yaml @@ -139,6 +139,8 @@ definitions: type: object handler.CreateChannel.body: properties: + description: + type: string name: type: string subscribe: diff --git a/scnserver/test/channel_test.go b/scnserver/test/channel_test.go index 9f78901..48c9f03 100644 --- a/scnserver/test/channel_test.go +++ b/scnserver/test/channel_test.go @@ -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, "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) {