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

View File

@ -2003,7 +2003,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.Reaction"
"$ref": "#/definitions/api.SendReactionRequest"
}
},
{
@ -2048,7 +2048,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"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": {
"type": "object",
"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": {
"type": "object",
"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": {
"type": "object",
"required": [

View File

@ -2000,7 +2000,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.Reaction"
"$ref": "#/definitions/api.SendReactionRequest"
}
},
{
@ -2045,7 +2045,7 @@
"in": "body",
"required": true,
"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": {
"type": "object",
"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": {
"type": "object",
"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": {
"type": "object",
"required": [

View File

@ -170,22 +170,6 @@ definitions:
- captcha
- challenge_token
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:
properties:
receipt_type:
@ -226,6 +210,21 @@ definitions:
required:
- timestamp
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:
properties:
number:
@ -331,6 +330,22 @@ definitions:
- number
- recipients
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:
properties:
pin:
@ -2068,7 +2083,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/api.Reaction'
$ref: '#/definitions/api.RemoveReactionRequest'
- description: Registered phone number
in: path
name: number
@ -2098,7 +2113,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/api.Reaction'
$ref: '#/definitions/api.SendReactionRequest'
- description: Registered phone number
in: path
name: number