Merge branch 'master' into flutter_app

This commit is contained in:
Mike Schwörer 2024-05-26 19:33:44 +02:00
commit 38e1c1133d
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
7 changed files with 31 additions and 5 deletions

View File

@ -180,6 +180,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 +235,7 @@ 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) channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey, b.Description)
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)
} }

View File

@ -395,8 +395,8 @@ var configProd = func() Config {
EnableLogger: true, EnableLogger: true,
}, },
RequestTimeout: 16 * time.Second, RequestTimeout: 16 * time.Second,
RequestMaxRetry: 8, RequestMaxRetry: 32,
RequestRetrySleep: 100 * time.Millisecond, RequestRetrySleep: 32 * time.Millisecond,
ReturnRawErrors: false, ReturnRawErrors: false,
DummyFirebase: false, DummyFirebase: false,
FirebaseTokenURI: "https://oauth2.googleapis.com/token", FirebaseTokenURI: "https://oauth2.googleapis.com/token",

View File

@ -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, userid models.UserID, dispName string, intName string, subscribeKey string, description *string) (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
@ -70,6 +78,7 @@ func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispNa
DisplayName: dispName, DisplayName: dispName,
InternalName: intName, InternalName: intName,
SubscribeKey: subscribeKey, SubscribeKey: subscribeKey,
DescriptionName: description,
TimestampCreated: time2DB(time.Now()), TimestampCreated: time2DB(time.Now()),
TimestampLastSent: nil, TimestampLastSent: nil,
MessagesSent: 0, MessagesSent: 0,

View File

@ -331,7 +331,7 @@ 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) newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey, nil)
if err != nil { if err != nil {
return models.Channel{}, err return models.Channel{}, err
} }

View File

@ -3047,6 +3047,9 @@
"handler.CreateChannel.body": { "handler.CreateChannel.body": {
"type": "object", "type": "object",
"properties": { "properties": {
"description": {
"type": "string"
},
"name": { "name": {
"type": "string" "type": "string"
}, },

View File

@ -139,6 +139,8 @@ definitions:
type: object type: object
handler.CreateChannel.body: handler.CreateChannel.body:
properties: properties:
description:
type: string
name: name:
type: string type: string
subscribe: subscribe:

View File

@ -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) {