refactor: split Reaction in two classes to mark the Reaction field as optional

This commit is contained in:
Era Dorta 2026-04-06 17:05:45 +02:00
parent 4e541848e2
commit 87ab2bb398
4 changed files with 139 additions and 73 deletions

View File

@ -97,13 +97,20 @@ type VerifyNumberSettings struct {
Pin string `json:"pin,omitempty"` Pin string `json:"pin,omitempty"`
} }
type Reaction struct { type SendReactionRequest struct {
Recipient string `json:"recipient"` Recipient string `json:"recipient"`
Reaction string `json:"reaction"` Reaction string `json:"reaction"`
TargetAuthor string `json:"target_author"` TargetAuthor string `json:"target_author"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
} }
type RemoveReactionRequest struct {
Recipient string `json:"recipient"`
Reaction string `json:"reaction,omitempty"`
TargetAuthor string `json:"target_author"`
Timestamp int64 `json:"timestamp"`
}
type Receipt struct { type Receipt struct {
Recipient string `json:"recipient"` Recipient string `json:"recipient"`
ReceiptType string `json:"receipt_type" enums:"read,viewed"` ReceiptType string `json:"receipt_type" enums:"read,viewed"`
@ -1847,11 +1854,11 @@ func (a *Api) UpdateGroup(c *gin.Context) {
// @Produce json // @Produce json
// @Success 204 {string} OK // @Success 204 {string} OK
// @Failure 400 {object} Error // @Failure 400 {object} Error
// @Param data body Reaction true "Reaction" // @Param data body SendReactionRequest true "Reaction"
// @Param number path string true "Registered phone number" // @Param number path string true "Registered phone number"
// @Router /v1/reactions/{number} [post] // @Router /v1/reactions/{number} [post]
func (a *Api) SendReaction(c *gin.Context) { func (a *Api) SendReaction(c *gin.Context) {
var req Reaction var req SendReactionRequest
err := c.BindJSON(&req) err := c.BindJSON(&req)
if err != nil { if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"}) c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
@ -1900,11 +1907,11 @@ func (a *Api) SendReaction(c *gin.Context) {
// @Produce json // @Produce json
// @Success 204 {string} OK // @Success 204 {string} OK
// @Failure 400 {object} Error // @Failure 400 {object} Error
// @Param data body Reaction true "Reaction" // @Param data body RemoveReactionRequest true "Reaction"
// @Param number path string true "Registered phone number" // @Param number path string true "Registered phone number"
// @Router /v1/reactions/{number} [delete] // @Router /v1/reactions/{number} [delete]
func (a *Api) RemoveReaction(c *gin.Context) { func (a *Api) RemoveReaction(c *gin.Context) {
var req Reaction var req RemoveReactionRequest
err := c.BindJSON(&req) err := c.BindJSON(&req)
if err != nil { if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"}) c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})

View File

@ -2003,7 +2003,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/api.Reaction" "$ref": "#/definitions/api.SendReactionRequest"
} }
}, },
{ {
@ -2048,7 +2048,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/api.Reaction" "$ref": "#/definitions/api.RemoveReactionRequest"
} }
}, },
{ {
@ -2956,29 +2956,6 @@ const docTemplate = `{
} }
} }
}, },
"api.Reaction": {
"type": "object",
"required": [
"reaction",
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.Receipt": { "api.Receipt": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3039,6 +3016,28 @@ const docTemplate = `{
} }
} }
}, },
"api.RemoveReactionRequest": {
"type": "object",
"required": [
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.SearchResponse": { "api.SearchResponse": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3191,6 +3190,29 @@ const docTemplate = `{
} }
} }
}, },
"api.SendReactionRequest": {
"type": "object",
"required": [
"reaction",
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.SetPinRequest": { "api.SetPinRequest": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -2000,7 +2000,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/api.Reaction" "$ref": "#/definitions/api.SendReactionRequest"
} }
}, },
{ {
@ -2045,7 +2045,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/api.Reaction" "$ref": "#/definitions/api.RemoveReactionRequest"
} }
}, },
{ {
@ -2953,29 +2953,6 @@
} }
} }
}, },
"api.Reaction": {
"type": "object",
"required": [
"reaction",
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.Receipt": { "api.Receipt": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3036,6 +3013,28 @@
} }
} }
}, },
"api.RemoveReactionRequest": {
"type": "object",
"required": [
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.SearchResponse": { "api.SearchResponse": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3188,6 +3187,29 @@
} }
} }
}, },
"api.SendReactionRequest": {
"type": "object",
"required": [
"reaction",
"recipient",
"target_author",
"timestamp"
],
"properties": {
"reaction": {
"type": "string"
},
"recipient": {
"type": "string"
},
"target_author": {
"type": "string"
},
"timestamp": {
"type": "integer"
}
}
},
"api.SetPinRequest": { "api.SetPinRequest": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -170,22 +170,6 @@ definitions:
- captcha - captcha
- challenge_token - challenge_token
type: object type: object
api.Reaction:
properties:
reaction:
type: string
recipient:
type: string
target_author:
type: string
timestamp:
type: integer
required:
- reaction
- recipient
- target_author
- timestamp
type: object
api.Receipt: api.Receipt:
properties: properties:
receipt_type: receipt_type:
@ -226,6 +210,21 @@ definitions:
required: required:
- timestamp - timestamp
type: object type: object
api.RemoveReactionRequest:
properties:
reaction:
type: string
recipient:
type: string
target_author:
type: string
timestamp:
type: integer
required:
- recipient
- target_author
- timestamp
type: object
api.SearchResponse: api.SearchResponse:
properties: properties:
number: number:
@ -331,6 +330,22 @@ definitions:
- number - number
- recipients - recipients
type: object type: object
api.SendReactionRequest:
properties:
reaction:
type: string
recipient:
type: string
target_author:
type: string
timestamp:
type: integer
required:
- reaction
- recipient
- target_author
- timestamp
type: object
api.SetPinRequest: api.SetPinRequest:
properties: properties:
pin: pin:
@ -2068,7 +2083,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/api.Reaction' $ref: '#/definitions/api.RemoveReactionRequest'
- description: Registered phone number - description: Registered phone number
in: path in: path
name: number name: number
@ -2098,7 +2113,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/api.Reaction' $ref: '#/definitions/api.SendReactionRequest'
- description: Registered phone number - description: Registered phone number
in: path in: path
name: number name: number