Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (a *MessageAPI) DeleteMessage(ctx *gin.Context) {
// description: the message to add
// required: true
// schema:
// $ref: "#/definitions/Message"
// $ref: "#/definitions/CreateMessage"
// responses:
// 200:
// description: Ok
Expand All @@ -364,7 +364,7 @@ func (a *MessageAPI) DeleteMessage(ctx *gin.Context) {
// schema:
// $ref: "#/definitions/Error"
func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
message := model.MessageExternal{}
message := model.CreateMessage{}
if err := ctx.Bind(&message); err != nil {
return
}
Expand Down Expand Up @@ -395,8 +395,6 @@ func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
message.Priority = &app.DefaultPriority
}

message.Date = timeNow()
message.ID = 0
msgInternal := toInternalMessage(&message)
if success := successOrAbort(ctx, 500, a.DB.CreateMessage(msgInternal)); !success {
return
Expand All @@ -405,13 +403,12 @@ func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
ctx.JSON(200, toExternalMessage(msgInternal))
}

func toInternalMessage(msg *model.MessageExternal) *model.Message {
func toInternalMessage(msg *model.CreateMessage) *model.Message {
res := &model.Message{
ID: msg.ID,
ApplicationID: msg.ApplicationID,
Message: msg.Message,
Title: msg.Title,
Date: msg.Date,
Date: timeNow(),
}
if msg.Priority != nil {
res.Priority = *msg.Priority
Expand Down
53 changes: 52 additions & 1 deletion docs/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Message"
"$ref": "#/definitions/CreateMessage"
}
}
],
Expand Down Expand Up @@ -2746,6 +2746,57 @@
},
"x-go-package": "github.com/gotify/server/v2/api"
},
"CreateMessage": {
"description": "The CreateMessage holds information about a message that will be sent.",
"type": "object",
"title": "CreateMessage Model",
"required": [
"message"
],
"properties": {
"appid": {
"description": "The application id that send this message. Always set when returned via the API.",
"type": "integer",
"format": "int64",
"x-go-name": "ApplicationID",
"example": 5
},
"extras": {
"description": "The extra data sent along the message.\n\nThe extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type.\n\nThe keys should be in the following format: \u0026lt;top-namespace\u0026gt;::[\u0026lt;sub-namespace\u0026gt;::]\u0026lt;action\u0026gt;\n\nThese namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes.",
"type": "object",
"additionalProperties": {},
"x-go-name": "Extras",
"example": {
"home::appliances::lighting::on": {
"brightness": 15
},
"home::appliances::thermostat::change_temperature": {
"temperature": 23
}
}
},
"message": {
"description": "The message. Markdown (excluding html) is allowed.",
"type": "string",
"x-go-name": "Message",
"example": "**Backup** was successfully finished."
},
"priority": {
"description": "The priority of the message. If unset, then the default priority of the\napplication will be used.",
"type": "integer",
"format": "int64",
"x-go-name": "Priority",
"example": 2
},
"title": {
"description": "The title of the message.",
"type": "string",
"x-go-name": "Title",
"example": "Backup"
}
},
"x-go-package": "github.com/gotify/server/v2/model"
},
"CreateUserExternal": {
"description": "Used for user creation.",
"type": "object",
Expand Down
36 changes: 36 additions & 0 deletions model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,39 @@ type MessageExternal struct {
// example: 2018-02-27T19:36:10.5045044+01:00
Date time.Time `json:"date"`
}

// CreateMessage Model
//
// The CreateMessage holds information about a message that will be sent.
//
// swagger:model CreateMessage
type CreateMessage struct {
// The application id that send this message. Always set when returned via the API.
//
// example: 5
ApplicationID uint `json:"appid"`
// The message. Markdown (excluding html) is allowed.
//
// required: true
// example: **Backup** was successfully finished.
Message string `form:"message" query:"message" json:"message" binding:"required"`
// The title of the message.
//
// example: Backup
Title string `form:"title" query:"title" json:"title"`
// The priority of the message. If unset, then the default priority of the
// application will be used.
//
// example: 2
Priority *int `form:"priority" query:"priority" json:"priority"`
// The extra data sent along the message.
//
// The extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type.
//
// The keys should be in the following format: <top-namespace>::[<sub-namespace>::]<action>
//
// These namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes.
//
// example: {"home::appliances::thermostat::change_temperature":{"temperature":23},"home::appliances::lighting::on":{"brightness":15}}
Extras map[string]any `form:"-" query:"-" json:"extras,omitempty"`
}
Loading