Compare commits

..

No commits in common. "9237369e5a762028edeaf20760a1d93fd90fd1a6" and "877a6a9619d4f9d92c1cc08f67324affd6e57356" have entirely different histories.

9 changed files with 501 additions and 919 deletions

View File

@ -225,13 +225,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -277,13 +277,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -333,13 +333,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -347,11 +347,6 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/{ID}": { "/v1/discord/webhooks/{ID}": {
"delete": { "delete": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -375,13 +370,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -417,13 +412,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -449,26 +444,7 @@ const docTemplate = `{
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
}
}
} }
}, },
"/v1/discord/webhooks/{id}": { "/v1/discord/webhooks/{id}": {
@ -504,13 +480,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -548,7 +524,7 @@ const docTemplate = `{
"400": { "400": {
"description": "Unable to reach SQL or Data problems", "description": "Unable to reach SQL or Data problems",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -593,13 +569,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -694,13 +670,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -743,13 +719,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -775,26 +751,7 @@ const docTemplate = `{
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
}
}
} }
}, },
"/v1/sources/new/youtube": { "/v1/sources/new/youtube": {
@ -824,26 +781,7 @@ const docTemplate = `{
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
}
}
} }
}, },
"/v1/sources/{id}": { "/v1/sources/{id}": {
@ -879,13 +817,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -919,13 +857,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -961,13 +899,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -1003,13 +941,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -1046,13 +984,13 @@ const docTemplate = `{
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.LoginResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.LoginResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -1163,8 +1101,8 @@ const docTemplate = `{
} }
], ],
"responses": { "responses": {
"201": { "200": {
"description": "Created", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/domain.BaseResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
@ -1300,9 +1238,6 @@ const docTemplate = `{
"domain.ArticleDetailedResponse": { "domain.ArticleDetailedResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1352,9 +1287,6 @@ const docTemplate = `{
"domain.ArticleResponse": { "domain.ArticleResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1369,9 +1301,6 @@ const docTemplate = `{
"domain.BaseResponse": { "domain.BaseResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
} }
@ -1401,9 +1330,6 @@ const docTemplate = `{
"domain.DiscordWebhookResponse": { "domain.DiscordWebhookResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1418,9 +1344,6 @@ const docTemplate = `{
"domain.LoginResponse": { "domain.LoginResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1472,9 +1395,6 @@ const docTemplate = `{
"domain.SourcesResponse": { "domain.SourcesResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },

View File

@ -216,13 +216,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -268,13 +268,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -324,13 +324,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -338,11 +338,6 @@
}, },
"/v1/discord/webhooks/{ID}": { "/v1/discord/webhooks/{ID}": {
"delete": { "delete": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -366,13 +361,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -408,13 +403,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -440,26 +435,7 @@
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse"
}
}
}
} }
}, },
"/v1/discord/webhooks/{id}": { "/v1/discord/webhooks/{id}": {
@ -495,13 +471,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.DiscordWebhookResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -539,7 +515,7 @@
"400": { "400": {
"description": "Unable to reach SQL or Data problems", "description": "Unable to reach SQL or Data problems",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -584,13 +560,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -685,13 +661,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -734,13 +710,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -766,26 +742,7 @@
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
}
}
} }
}, },
"/v1/sources/new/youtube": { "/v1/sources/new/youtube": {
@ -815,26 +772,7 @@
"required": true "required": true
} }
], ],
"responses": { "responses": {}
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
}
}
} }
}, },
"/v1/sources/{id}": { "/v1/sources/{id}": {
@ -870,13 +808,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -910,13 +848,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -952,13 +890,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -994,13 +932,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.SourcesResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -1037,13 +975,13 @@
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
"schema": { "schema": {
"$ref": "#/definitions/domain.LoginResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
}, },
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
"$ref": "#/definitions/domain.LoginResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
} }
} }
@ -1154,8 +1092,8 @@
} }
], ],
"responses": { "responses": {
"201": { "200": {
"description": "Created", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/domain.BaseResponse" "$ref": "#/definitions/domain.BaseResponse"
} }
@ -1291,9 +1229,6 @@
"domain.ArticleDetailedResponse": { "domain.ArticleDetailedResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1343,9 +1278,6 @@
"domain.ArticleResponse": { "domain.ArticleResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1360,9 +1292,6 @@
"domain.BaseResponse": { "domain.BaseResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
} }
@ -1392,9 +1321,6 @@
"domain.DiscordWebhookResponse": { "domain.DiscordWebhookResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1409,9 +1335,6 @@
"domain.LoginResponse": { "domain.LoginResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },
@ -1463,9 +1386,6 @@
"domain.SourcesResponse": { "domain.SourcesResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"isError": {
"type": "boolean"
},
"message": { "message": {
"type": "string" "type": "string"
}, },

View File

@ -9,8 +9,6 @@ definitions:
type: object type: object
domain.ArticleDetailedResponse: domain.ArticleDetailedResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
payload: payload:
@ -43,8 +41,6 @@ definitions:
type: object type: object
domain.ArticleResponse: domain.ArticleResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
payload: payload:
@ -54,8 +50,6 @@ definitions:
type: object type: object
domain.BaseResponse: domain.BaseResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
type: object type: object
@ -77,8 +71,6 @@ definitions:
type: object type: object
domain.DiscordWebhookResponse: domain.DiscordWebhookResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
payload: payload:
@ -88,8 +80,6 @@ definitions:
type: object type: object
domain.LoginResponse: domain.LoginResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
refreshToken: refreshToken:
@ -123,8 +113,6 @@ definitions:
type: object type: object
domain.SourcesResponse: domain.SourcesResponse:
properties: properties:
isError:
type: boolean
message: message:
type: string type: string
payload: payload:
@ -276,11 +264,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Returns the top 100 summary: Returns the top 100
@ -302,13 +290,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Deletes a record by ID. summary: Deletes a record by ID.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -328,11 +314,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Disables a Webhook from being used. summary: Disables a Webhook from being used.
@ -346,19 +332,7 @@ paths:
name: id name: id
required: true required: true
type: integer type: integer
responses: responses: {}
"200":
description: OK
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Enables a source to continue processing. summary: Enables a source to continue processing.
@ -382,11 +356,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Returns the top 100 entries from the queue to be processed. summary: Returns the top 100 entries from the queue to be processed.
@ -415,11 +389,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Returns all the known web hooks based on the Server and Channel given. summary: Returns all the known web hooks based on the Server and Channel given.
@ -451,11 +425,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.DiscordWebhookResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Creates a new record for a discord web hook to post data to. summary: Creates a new record for a discord web hook to post data to.
@ -478,7 +452,7 @@ paths:
"400": "400":
description: Unable to reach SQL or Data problems description: Unable to reach SQL or Data problems
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Lists the top 50 records summary: Lists the top 50 records
@ -502,11 +476,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Returns a single entity by ID summary: Returns a single entity by ID
@ -527,11 +501,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Marks a source as deleted based on its ID value. summary: Marks a source as deleted based on its ID value.
@ -553,11 +527,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Disables a source from processing. summary: Disables a source from processing.
@ -579,11 +553,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Enables a source to continue processing. summary: Enables a source to continue processing.
@ -611,11 +585,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: 'Lists the top 50 records based on the name given. Example: reddit' summary: 'Lists the top 50 records based on the name given. Example: reddit'
@ -675,11 +649,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Creates a new reddit source to monitor. summary: Creates a new reddit source to monitor.
@ -706,11 +680,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.SourcesResponse' $ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Creates a new rss source to monitor. summary: Creates a new rss source to monitor.
@ -724,19 +698,7 @@ paths:
name: name name: name
required: true required: true
type: string type: string
responses: responses: {}
"200":
description: ok
schema:
$ref: '#/definitions/domain.SourcesResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.SourcesResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.SourcesResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Creates a new twitch source to monitor. summary: Creates a new twitch source to monitor.
@ -755,19 +717,7 @@ paths:
name: url name: url
required: true required: true
type: string type: string
responses: responses: {}
"200":
description: ok
schema:
$ref: '#/definitions/domain.SourcesResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.SourcesResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.SourcesResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Creates a new youtube source to monitor. summary: Creates a new youtube source to monitor.
@ -792,11 +742,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.LoginResponse' $ref: '#/definitions/domain.BaseResponse'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.LoginResponse' $ref: '#/definitions/domain.BaseResponse'
summary: Logs into the API and returns a bearer token if successful summary: Logs into the API and returns a bearer token if successful
tags: tags:
- Users - Users
@ -863,8 +813,8 @@ paths:
produces: produces:
- application/json - application/json
responses: responses:
"201": "200":
description: Created description: OK
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
"400": "400":

View File

@ -2,7 +2,6 @@ package domain
type BaseResponse struct { type BaseResponse struct {
Message string `json:"message"` Message string `json:"message"`
IsError bool `json:"isError"`
} }
type LoginResponse struct { type LoginResponse struct {

View File

@ -20,18 +20,17 @@ import (
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) listArticles(c echo.Context) error { func (s *Handler) listArticles(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
resp := domain.ArticleResponse{ resp := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, resp)
}
page, err := strconv.Atoi(c.QueryParam("page")) page, err := strconv.Atoi(c.QueryParam("page"))
if err != nil { if err != nil {
page = 0 page = 0
@ -39,11 +38,10 @@ func (s *Handler) listArticles(c echo.Context) error {
res, err := s.repo.Articles.ListByPage(c.Request().Context(), page, 25) res, err := s.repo.Articles.ListByPage(c.Request().Context(), page, 25)
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, resp) return s.WriteError(c, err, http.StatusInternalServerError)
} }
resp.Payload = dtoconv.ArticlesToDto(res) resp.Payload = dtoconv.ArticlesToDto(res)
resp.BaseResponse.IsError = false
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -58,34 +56,32 @@ func (s *Handler) listArticles(c echo.Context) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getArticle(c echo.Context) error { func (s *Handler) getArticle(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.ArticleResponse{ p := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, p)
}
id := c.Param("ID") id := c.Param("ID")
idNumber, err := strconv.Atoi(id) idNumber, err := strconv.Atoi(id)
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusBadRequest)
} }
item, err := s.repo.Articles.GetById(c.Request().Context(), int64(idNumber)) item, err := s.repo.Articles.GetById(c.Request().Context(), int64(idNumber))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return c.JSON(http.StatusInternalServerError, err)
} }
var dtos []domain.ArticleDto var dtos []domain.ArticleDto
dtos = append(dtos, dtoconv.ArticleToDto(item)) dtos = append(dtos, dtoconv.ArticleToDto(item))
p.Payload = dtos p.Payload = dtos
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -100,37 +96,36 @@ func (s *Handler) getArticle(c echo.Context) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getArticleDetails(c echo.Context) error { func (s *Handler) getArticleDetails(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.ArticleDetailedResponse{ p := domain.ArticleDetailedResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
Payload: domain.ArticleAndSourceModel{}, Payload: domain.ArticleAndSourceModel{},
} }
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, p)
}
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusBadRequest)
} }
article, err := s.repo.Articles.GetById(c.Request().Context(), int64(id)) article, err := s.repo.Articles.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusInternalServerError)
} }
source, err := s.repo.Sources.GetById(c.Request().Context(), article.SourceID) source, err := s.repo.Sources.GetById(c.Request().Context(), article.SourceID)
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusInternalServerError)
} }
p.Payload.Article = dtoconv.ArticleToDto(article) p.Payload.Article = dtoconv.ArticleToDto(article)
p.Payload.Source = dtoconv.SourceToDto(source) p.Payload.Source = dtoconv.SourceToDto(source)
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -146,21 +141,20 @@ func (s *Handler) getArticleDetails(c echo.Context) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) ListArticlesBySourceId(c echo.Context) error { func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.ArticleResponse{ p := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, p)
}
id, err := strconv.Atoi(c.QueryParam("id")) id, err := strconv.Atoi(c.QueryParam("id"))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusBadRequest)
} }
// if the page number is missing, default to 0 // if the page number is missing, default to 0
@ -171,11 +165,9 @@ func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
items, err := s.repo.Articles.ListBySource(c.Request().Context(), _page, 25, id, "") items, err := s.repo.Articles.ListBySource(c.Request().Context(), _page, 25, id, "")
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = dtoconv.ArticlesToDto(items) p.Payload = dtoconv.ArticlesToDto(items)
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }

View File

@ -16,29 +16,26 @@ import (
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks [get] // @Router /v1/discord/webhooks [get]
// @Success 200 {object} domain.DiscordWebhookResponse // @Success 200 {object} domain.DiscordWebhookResponse
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) ListDiscordWebHooks(c echo.Context) error { func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, p)
}
res, err := s.repo.DiscordWebHooks.ListByServerName(c.Request().Context(), "") res, err := s.repo.DiscordWebHooks.ListByServerName(c.Request().Context(), "")
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, p) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = dtoconv.DiscordWebhooksToDto(res) p.Payload = dtoconv.DiscordWebhooksToDto(res)
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -49,36 +46,33 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{id} [get] // @Router /v1/discord/webhooks/{id} [get]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetDiscordWebHooksById(c echo.Context) error { func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
return c.JSON(http.StatusUnauthorized, p)
}
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, p) return s.WriteError(c, err, http.StatusBadRequest)
} }
res, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) res, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, p) return s.WriteError(c, err, http.StatusInternalServerError)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(res)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(res))
p.Payload = dtos p.Payload = dtos
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -90,43 +84,37 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/by/serverAndChannel [get] // @Router /v1/discord/webhooks/by/serverAndChannel [get]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error { func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
IsError: true,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebhookRead)
if err != nil {
p.BaseResponse.Message = err.Error()
return c.JSON(http.StatusUnauthorized, p)
}
_server := c.QueryParam("server") _server := c.QueryParam("server")
if _server == "" { if _server == "" {
p.BaseResponse.Message = "server was not defined" return s.WriteMessage(c, "server was not defined", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
_channel := c.QueryParam("channel") _channel := c.QueryParam("channel")
if _channel == "" { if _channel == "" {
p.BaseResponse.Message = "channel was not defined" return s.WriteMessage(c, "channel was not defined", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
res, err := s.repo.DiscordWebHooks.ListByServerAndChannel(c.Request().Context(), _server, _channel) res, err := s.repo.DiscordWebHooks.ListByServerAndChannel(c.Request().Context(), _server, _channel)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
p.Payload = dtoconv.DiscordWebhooksToDto(res) p.Payload = dtoconv.DiscordWebhooksToDto(res)
p.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -138,21 +126,13 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/new [post] // @Router /v1/discord/webhooks/new [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) NewDiscordWebHook(c echo.Context) error { func (s *Handler) NewDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
token, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) token, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
_url := c.QueryParam("url") _url := c.QueryParam("url")
@ -160,51 +140,54 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
_channel := c.QueryParam("channel") _channel := c.QueryParam("channel")
if _url == "" { if _url == "" {
p.Message = "url is missing a value" return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: "url is missing a value",
})
} }
if !strings.Contains(_url, "discord.com/api/webhooks") { if !strings.Contains(_url, "discord.com/api/webhooks") {
p.Message = "invalid url" return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: "invalid url",
})
} }
if _server == "" { if _server == "" {
p.Message = "server is missing" return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: "server is missing",
})
} }
if _channel == "" { if _channel == "" {
p.Message = "channel is missing" return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: "channel is missing",
})
} }
user, err := s.repo.Users.GetUser(c.Request().Context(), token.UserName) user, err := s.repo.Users.GetUser(c.Request().Context(), token.UserName)
if err != nil { if err != nil {
p.Message = err.Error() return s.WriteMessage(c, ErrUserUnknown, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
rows, err := s.repo.DiscordWebHooks.Create(c.Request().Context(), user.ID, _url, _server, _channel, true) rows, err := s.repo.DiscordWebHooks.Create(c.Request().Context(), user.ID, _url, _server, _channel, true)
if err != nil { if err != nil {
p.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if rows != 1 { if rows != 1 {
p.Message = "data was not written to database" return s.WriteMessage(c, "data was not written to database", http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.DiscordWebHooks.GetByUrl(c.Request().Context(), _url) item, err := s.repo.DiscordWebHooks.GetByUrl(c.Request().Context(), _url)
if err != nil { if err != nil {
p.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
p.Payload = dtos return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
p.IsError = false BaseResponse: domain.BaseResponse{
return c.JSON(http.StatusOK, p) Message: ResponseMessageSuccess,
},
Payload: dtos,
})
} }
// DisableDiscordWebHooks // DisableDiscordWebHooks
@ -213,66 +196,56 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID}/disable [post] // @Router /v1/discord/webhooks/{ID}/disable [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) disableDiscordWebHook(c echo.Context) error { func (s *Handler) disableDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) _, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: err.Error(),
})
} }
// Check to make sure we can find the record // Check to make sure we can find the record
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if record.UserID != s.GetUserIdFromJwtToken(c) { if record.UserID != s.GetUserIdFromJwtToken(c) {
p.BaseResponse.Message = ErrYouDontOwnTheRecord return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// flip the it // flip the it
updated, err := s.repo.DiscordWebHooks.Disable(c.Request().Context(), int64(id)) updated, err := s.repo.DiscordWebHooks.Disable(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
// make sure we got a row updated // make sure we got a row updated
if updated != 1 { if updated != 1 {
p.BaseResponse.Message = "unexpected number of updates found" return s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
p.Payload = dtos BaseResponse: domain.BaseResponse{
p.IsError = false Message: ResponseMessageSuccess,
return c.JSON(http.StatusOK, p) },
Payload: dtos,
})
} }
// EnableDiscordWebHook // EnableDiscordWebHook
@ -280,132 +253,104 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
// @Param id path int true "id" // @Param id path int true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID}/enable [post] // @Router /v1/discord/webhooks/{ID}/enable [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) enableDiscordWebHook(c echo.Context) error { func (s *Handler) enableDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) _, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// Check to make sure we can find the record // Check to make sure we can find the record
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
if record.UserID != s.GetUserIdFromJwtToken(c) { if record.UserID != s.GetUserIdFromJwtToken(c) {
p.BaseResponse.Message = ErrYouDontOwnTheRecord return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
updated, err := s.repo.DiscordWebHooks.Enable(c.Request().Context(), int64(id)) updated, err := s.repo.DiscordWebHooks.Enable(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if updated != 1 { if updated != 1 {
p.BaseResponse.Message = ErrFailedToUpdateRecord return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
p.Payload = dtos BaseResponse: domain.BaseResponse{
p.IsError = false Message: ResponseMessageSuccess,
return c.JSON(http.StatusOK, p) },
Payload: dtos,
})
} }
// DeleteDiscordWebHook // DeleteDiscordWebHook
// @Summary Deletes a record by ID. // @Summary Deletes a record by ID.
// @Param id path string true "id" // @Param id path string true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID} [delete] // @Router /v1/discord/webhooks/{ID} [delete]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer
func (s *Handler) deleteDiscordWebHook(c echo.Context) error { func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) _, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, err.Error())
return c.JSON(http.StatusBadRequest, p)
} }
// Check to make sure we can find the record // Check to make sure we can find the record
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, err.Error())
return c.JSON(http.StatusBadRequest, p)
} }
if record.UserID != s.GetUserIdFromJwtToken(c) { if record.UserID != s.GetUserIdFromJwtToken(c) {
p.BaseResponse.Message = ErrYouDontOwnTheRecord return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// Soft delete the record // Soft delete the record
updated, err := s.repo.DiscordWebHooks.SoftDelete(c.Request().Context(), int64(id)) updated, err := s.repo.DiscordWebHooks.SoftDelete(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
if updated != 1 { if updated != 1 {
p.BaseResponse.Message = ErrFailedToUpdateRecord return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id)) item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
p.Payload = dtos BaseResponse: domain.BaseResponse{
p.BaseResponse.IsError = false Message: ResponseMessageSuccess,
return c.JSON(http.StatusOK, p) },
Payload: dtos,
})
} }
// UpdateDiscordWebHook // UpdateDiscordWebHook

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"net/http"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
echojwt "github.com/labstack/echo-jwt/v4" echojwt "github.com/labstack/echo-jwt/v4"
@ -12,6 +13,7 @@ import (
swagger "github.com/swaggo/echo-swagger" swagger "github.com/swaggo/echo-swagger"
_ "git.jamestombleson.com/jtom38/newsbot-api/docs" _ "git.jamestombleson.com/jtom38/newsbot-api/docs"
"git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
) )
@ -46,6 +48,8 @@ var (
func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Handler { func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Handler {
s := &Handler{ s := &Handler{
//Db: db,
//dto: dto.NewDtoClient(db),
config: configs, config: configs,
repo: services.NewRepositoryService(conn), repo: services.NewRepositoryService(conn),
} }
@ -122,30 +126,29 @@ func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Han
// *ApiStatusModel // *ApiStatusModel
//} //}
//func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error { func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error {
// return c.JSON(HttpStatusCode, domain.BaseResponse{ return c.JSON(HttpStatusCode, domain.BaseResponse{
// Message: errMessage.Error(), Message: errMessage.Error(),
// IsError: true, })
// }) }
//}
//func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error { func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error {
// return c.JSON(HttpStatusCode, domain.BaseResponse{ return c.JSON(HttpStatusCode, domain.BaseResponse{
// Message: msg, Message: msg,
// }) })
//} }
//func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error { func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error {
// return c.JSON(http.StatusInternalServerError, domain.BaseResponse{ return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
// Message: msg, Message: msg,
// }) })
//} }
//func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error { func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
// return c.JSON(http.StatusUnauthorized, domain.BaseResponse{ return c.JSON(http.StatusUnauthorized, domain.BaseResponse{
// Message: msg, Message: msg,
// }) })
//} }
// If the token is not valid then an json error will be returned. // If the token is not valid then an json error will be returned.
// If the token has the wrong scope, a json error will be returned. // If the token has the wrong scope, a json error will be returned.
@ -153,7 +156,7 @@ func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Han
func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtToken, error) { func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtToken, error) {
token, err := s.getJwtTokenFromContext(c) token, err := s.getJwtTokenFromContext(c)
if err != nil { if err != nil {
return JwtToken{}, errors.New(ErrJwtMissing) s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
} }
err = token.hasExpired() err = token.hasExpired()
@ -170,11 +173,6 @@ func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtTok
return JwtToken{}, errors.New(ErrJwtInvalidIssuer) return JwtToken{}, errors.New(ErrJwtInvalidIssuer)
} }
// If you are the built in admin account, skip the username and session token check
if token.UserName == "admin" {
return token, nil
}
user, err := s.repo.Users.GetUser(c.Request().Context(), token.UserName) user, err := s.repo.Users.GetUser(c.Request().Context(), token.UserName)
if err != nil { if err != nil {
return JwtToken{}, errors.New("user record not found") return JwtToken{}, errors.New("user record not found")
@ -190,7 +188,7 @@ func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtTok
func (s *Handler) GetUserIdFromJwtToken(c echo.Context) int64 { func (s *Handler) GetUserIdFromJwtToken(c echo.Context) int64 {
token, err := s.getJwtTokenFromContext(c) token, err := s.getJwtTokenFromContext(c)
if err != nil { if err != nil {
return -1 s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
} }
return token.GetUserId() return token.GetUserId()

View File

@ -18,20 +18,18 @@ import (
// @Tags Source // @Tags Source
// @Router /v1/sources [get] // @Router /v1/sources [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems" // @Failure 400 {object} domain.BaseResponse "Unable to reach SQL or Data problems"
// @Security Bearer // @Security Bearer
func (s *Handler) listSources(c echo.Context) error { func (s *Handler) listSources(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead) _, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
page, err := strconv.Atoi(c.QueryParam("page")) page, err := strconv.Atoi(c.QueryParam("page"))
@ -42,13 +40,11 @@ func (s *Handler) listSources(c echo.Context) error {
// Default way of showing all sources // Default way of showing all sources
items, err := s.repo.Sources.List(c.Request().Context(), page, 25) items, err := s.repo.Sources.List(c.Request().Context(), page, 25)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
p.Payload = dtoconv.SourcesToDto(items) resp.Payload = dtoconv.SourcesToDto(items)
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// ListSourcesBySource // ListSourcesBySource
@ -59,27 +55,24 @@ func (s *Handler) listSources(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/by/source [get] // @Router /v1/sources/by/source [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) listSourcesBySource(c echo.Context) error { func (s *Handler) listSourcesBySource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead) _, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
source := c.QueryParam("source") source := c.QueryParam("source")
if source == "" { if source == "" {
p.BaseResponse.Message = fmt.Sprintf("%s source", ErrParameterMissing) return s.WriteMessage(c, fmt.Sprintf("%s source", ErrParameterMissing), http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
page, err := strconv.Atoi(c.QueryParam("page")) page, err := strconv.Atoi(c.QueryParam("page"))
@ -90,13 +83,13 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
// Shows the list by Sources.source // Shows the list by Sources.source
items, err := s.repo.Sources.ListBySource(c.Request().Context(), page, 25, source) items, err := s.repo.Sources.ListBySource(c.Request().Context(), page, 25, source)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
return c.JSON(http.StatusInternalServerError, p) Message: err.Error(),
})
} }
p.Payload = dtoconv.SourcesToDto(items) resp.Payload = dtoconv.SourcesToDto(items)
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// GetSource // GetSource
@ -106,39 +99,37 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/{id} [get] // @Router /v1/sources/{id} [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getSource(c echo.Context) error { func (s *Handler) getSource(c echo.Context) error {
p := domain.SourcesResponse{ _, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
if err != nil {
return s.WriteError(c, err, http.StatusBadRequest)
}
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
}, },
} }
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
if err != nil {
p.BaseResponse.Message = err.Error()
return c.JSON(http.StatusUnauthorized, p)
}
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: ErrUnableToParseId,
})
} }
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id)) item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// GetSourceByNameAndSource // GetSourceByNameAndSource
@ -153,37 +144,34 @@ func (s *Handler) getSource(c echo.Context) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error { func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead) _, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
var param domain.GetSourceBySourceAndNameParamRequest var param domain.GetSourceBySourceAndNameParamRequest
err = c.Bind(&param) err = c.Bind(&param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: err.Error(),
})
} }
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), param.Source, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), param.Source, param.Name)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// NewRedditSource // NewRedditSource
@ -193,71 +181,52 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/new/reddit [post] // @Router /v1/sources/new/reddit [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newRedditSource(c echo.Context) error { func (s *Handler) newRedditSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate) _, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
var param domain.NewSourceParamRequest var param domain.NewSourceParamRequest
err = c.Bind(&param) err = c.Bind(&param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
if param.Url == "" { if param.Url == "" {
p.BaseResponse.Message = "url is missing" return s.WriteMessage(c, "url is missing", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
if !strings.Contains(param.Url, "reddit.com") { if !strings.Contains(param.Url, "reddit.com") {
p.BaseResponse.Message = "invalid url" return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
}
// Check to see if we already have this record, if we do, return it.
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorReddit, param.Name)
if err == nil {
var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p)
} }
tags := fmt.Sprintf("twitch, %v, %s", param.Name, param.Tags) tags := fmt.Sprintf("twitch, %v, %s", param.Name, param.Tags)
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorReddit, param.Name, param.Url, tags, true) rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorReddit, param.Name, param.Url, tags, true)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if rows != 1 { if rows != 1 {
p.BaseResponse.Message = ErrFailedToCreateRecord return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorReddit, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorReddit, param.Name)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// NewYoutubeSource // NewYoutubeSource
@ -266,71 +235,59 @@ func (s *Handler) newRedditSource(c echo.Context) error {
// @Param url query string true "url" // @Param url query string true "url"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/youtube [post] // @Router /v1/sources/new/youtube [post]
// @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newYoutubeSource(c echo.Context) error { func (s *Handler) newYoutubeSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
}
// Validate the jwt // Validate the jwt
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate) _, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
var param domain.NewSourceParamRequest var param domain.NewSourceParamRequest
err = c.Bind(&param) err = c.Bind(&param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
if param.Url == "" { if param.Url == "" {
p.BaseResponse.Message = "url is missing a value" return s.WriteMessage(c, "url is missing a value", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
if !strings.Contains(param.Url, "youtube.com") { if !strings.Contains(param.Url, "youtube.com") {
p.BaseResponse.Message = "invalid url" return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
tags := fmt.Sprintf("twitch, %v", param.Name) tags := fmt.Sprintf("twitch, %v", param.Name)
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorYoutube, param.Name, param.Url, tags, true) rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorYoutube, param.Name, param.Url, tags, true)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
if rows != 1 { if rows != 1 {
p.BaseResponse.Message = ErrFailedToCreateRecord return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err != nil { if err == nil {
p.BaseResponse.Message = err.Error() var dto []domain.SourceDto
return c.JSON(http.StatusInternalServerError, p) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto
return c.JSON(http.StatusOK, resp)
} }
var dto []domain.SourceDto return c.JSON(http.StatusOK, resp)
dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p)
} }
// NewTwitchSource // NewTwitchSource
@ -338,29 +295,25 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
// @Param name query string true "name" // @Param name query string true "name"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/twitch [post] // @Router /v1/sources/new/twitch [post]
// @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newTwitchSource(c echo.Context) error { func (s *Handler) newTwitchSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate) _, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
var param domain.NewSourceParamRequest var param domain.NewSourceParamRequest
err = c.Bind(&param) err = c.Bind(&param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: err.Error(),
})
}
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
tags := fmt.Sprintf("twitch, %v", param.Name) tags := fmt.Sprintf("twitch, %v", param.Name)
@ -371,28 +324,27 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorTwitch, param.Name, url, tags, true) rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorTwitch, param.Name, url, tags, true)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
return c.JSON(http.StatusInternalServerError, p) Message: err.Error(),
})
} }
if rows != 1 { if rows != 1 {
p.BaseResponse.Message = ErrFailedToCreateRecord return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name) item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, resp)
} }
// NewRssSource // NewRssSource
@ -402,68 +354,54 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/new/rss [post] // @Router /v1/sources/new/rss [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newRssSource(c echo.Context) error { func (s *Handler) newRssSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate) _, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p) }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
} }
var param domain.NewSourceParamRequest var param domain.NewSourceParamRequest
err = c.Bind(&param) err = c.Bind(&param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: err.Error(),
})
} }
if param.Url == "" { if param.Url == "" {
p.BaseResponse.Message = err.Error() return c.JSON(http.StatusBadRequest, domain.BaseResponse{
return c.JSON(http.StatusBadRequest, p) Message: "Url is missing a value",
} })
// Check if the record already exists
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name)
if err == nil {
var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto
p.BaseResponse.IsError = false
return c.JSON(http.StatusOK, p)
} }
tags := fmt.Sprintf("rss, %v, %s", param.Name, param.Tags) tags := fmt.Sprintf("rss, %v, %s", param.Name, param.Tags)
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorRss, param.Name, param.Url, tags, true) rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorRss, param.Name, param.Url, tags, true)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if rows != 1 { if rows != 1 {
p.BaseResponse.Message = ErrFailedToCreateRecord return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// DeleteSource // DeleteSource
@ -472,58 +410,50 @@ func (s *Handler) newRssSource(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/{id} [POST] // @Router /v1/sources/{id} [POST]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) deleteSources(c echo.Context) error { func (s *Handler) deleteSources(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeAll) _, err := s.ValidateJwtToken(c, domain.ScopeAll)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// Check to make sure we can find the record // Check to make sure we can find the record
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id)) _, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
// Delete the record // Delete the record
rows, err := s.repo.Sources.SoftDelete(c.Request().Context(), int64(id)) rows, err := s.repo.Sources.SoftDelete(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
if rows != 1 { if rows != 1 {
p.BaseResponse.Message = ErrFailedToUpdateRecord return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
// pull the record with its updated value // pull the record with its updated value
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id)) item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var items []domain.SourceDto var items []domain.SourceDto
items = append(items, dtoconv.SourceToDto(item)) items = append(items, dtoconv.SourceToDto(item))
p.Payload = items
p.IsError = false return c.JSON(http.StatusOK, domain.SourcesResponse{
return c.JSON(http.StatusOK, p) BaseResponse: domain.BaseResponse{
Message: "OK",
},
Payload: items,
})
} }
// DisableSource // DisableSource
@ -532,53 +462,46 @@ func (s *Handler) deleteSources(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/{id}/disable [post] // @Router /v1/sources/{id}/disable [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) disableSource(c echo.Context) error { func (s *Handler) disableSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeAll) _, err := s.ValidateJwtToken(c, domain.ScopeAll)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
}
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// Check to make sure we can find the record // Check to make sure we can find the record
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id)) _, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
_, err = s.repo.Sources.Disable(c.Request().Context(), int64(id)) _, err = s.repo.Sources.Disable(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id)) item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }
// EnableSource // EnableSource
@ -587,51 +510,44 @@ func (s *Handler) disableSource(c echo.Context) error {
// @Tags Source // @Tags Source
// @Router /v1/sources/{id}/enable [post] // @Router /v1/sources/{id}/enable [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) enableSource(c echo.Context) error { func (s *Handler) enableSource(c echo.Context) error {
p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
}
_, err := s.ValidateJwtToken(c, domain.ScopeAll) _, err := s.ValidateJwtToken(c, domain.ScopeAll)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
resp := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
},
}
id, err := strconv.Atoi(c.Param("ID")) id, err := strconv.Atoi(c.Param("ID"))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
// Check to make sure we can find the record // Check to make sure we can find the record
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id)) _, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
_, err = s.repo.Sources.Enable(c.Request().Context(), int64(id)) _, err = s.repo.Sources.Enable(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id)) item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return s.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto resp.Payload = dto
p.BaseResponse.IsError = false return c.JSON(http.StatusOK, resp)
return c.JSON(http.StatusOK, p)
} }

View File

@ -23,15 +23,10 @@ const (
// @Accepts x-www-form-urlencoded // @Accepts x-www-form-urlencoded
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 201 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
func (h *Handler) AuthRegister(c echo.Context) error { func (h *Handler) AuthRegister(c echo.Context) error {
p := domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
}
username := c.FormValue("username") username := c.FormValue("username")
password := c.FormValue("password") password := c.FormValue("password")
@ -41,29 +36,27 @@ func (h *Handler) AuthRegister(c echo.Context) error {
// if we have an err, validate that if its not user not found. // if we have an err, validate that if its not user not found.
// if the user is not found, we can use that name // if the user is not found, we can use that name
if err.Error() != repository.ErrUserNotFound { if err.Error() != repository.ErrUserNotFound {
p.Message = err.Error() return h.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
} }
if exists.Username == username { if exists.Username == username {
p.Message = ErrUsernameAlreadyExists return h.InternalServerErrorResponse(c, ErrUsernameAlreadyExists)
return c.JSON(http.StatusInternalServerError, p)
} }
//password := c.QueryParam("password") //password := c.QueryParam("password")
err = h.repo.Users.CheckPasswordForRequirements(password) err = h.repo.Users.CheckPasswordForRequirements(password)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
_, err = h.repo.Users.Create(c.Request().Context(), username, password, domain.ScopeArticleRead) _, err = h.repo.Users.Create(c.Request().Context(), username, password, domain.ScopeArticleRead)
if err != nil { if err != nil {
p.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
return c.JSON(http.StatusCreated, p) return c.JSON(http.StatusCreated, domain.BaseResponse{
Message: "OK",
})
} }
// @Summary Logs into the API and returns a bearer token if successful // @Summary Logs into the API and returns a bearer token if successful
@ -73,19 +66,9 @@ func (h *Handler) AuthRegister(c echo.Context) error {
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 200 {object} domain.LoginResponse // @Success 200 {object} domain.LoginResponse
// @Failure 400 {object} domain.LoginResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.LoginResponse // @Failure 500 {object} domain.BaseResponse
func (h *Handler) AuthLogin(c echo.Context) error { func (h *Handler) AuthLogin(c echo.Context) error {
p := domain.LoginResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
//Token: jwt,
Type: "Bearer",
//RefreshToken: refresh,
}
username := c.FormValue("username") username := c.FormValue("username")
password := c.FormValue("password") password := c.FormValue("password")
@ -97,15 +80,13 @@ func (h *Handler) AuthLogin(c echo.Context) error {
// check if the user exists // check if the user exists
user, err := h.repo.Users.GetUser(c.Request().Context(), username) user, err := h.repo.Users.GetUser(c.Request().Context(), username)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
// make sure the hash matches // make sure the hash matches
err = h.repo.Users.DoesPasswordMatchHash(c.Request().Context(), username, password) err = h.repo.Users.DoesPasswordMatchHash(c.Request().Context(), username, password)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
// TODO think about moving this down some? // TODO think about moving this down some?
@ -114,60 +95,53 @@ func (h *Handler) AuthLogin(c echo.Context) error {
jwt, err := h.generateJwtWithExp(username, h.config.ServerAddress, user.SessionToken, userScopes, user.ID, expiresAt) jwt, err := h.generateJwtWithExp(username, h.config.ServerAddress, user.SessionToken, userScopes, user.ID, expiresAt)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
refresh, err := h.repo.RefreshTokens.Create(c.Request().Context(), username) refresh, err := h.repo.RefreshTokens.Create(c.Request().Context(), username)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
p.Token = jwt return c.JSON(http.StatusOK, domain.LoginResponse{
p.RefreshToken = refresh BaseResponse: domain.BaseResponse{
p.BaseResponse.IsError = false Message: "OK",
return c.JSON(http.StatusOK, p) },
Token: jwt,
Type: "Bearer",
RefreshToken: refresh,
})
} }
func (h *Handler) createAdminToken(c echo.Context, password string) error { func (h *Handler) createAdminToken(c echo.Context, password string) error {
p := domain.LoginResponse{
BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
},
//Token: token,
Type: "Bearer",
}
// if the admin token is blank, then the admin wanted this disabled. // if the admin token is blank, then the admin wanted this disabled.
// this will fail right away and not progress. // this will fail right away and not progress.
if h.config.AdminSecret == "" { if h.config.AdminSecret == "" {
p.BaseResponse.Message = ErrUserNotFound return h.InternalServerErrorResponse(c, ErrUserNotFound)
return c.JSON(http.StatusBadRequest, p)
} }
if h.config.AdminSecret != password { if h.config.AdminSecret != password {
p.BaseResponse.Message = ErrUserNotFound return h.UnauthorizedResponse(c, ErrUserNotFound)
return c.JSON(http.StatusBadRequest, p)
} }
var userScopes []string var userScopes []string
userScopes = append(userScopes, domain.ScopeAll) userScopes = append(userScopes, domain.ScopeAll)
sessionToken, err := uuid.NewV7() sessionToken, err := uuid.NewV7()
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
token, err := h.generateJwt("admin", h.config.ServerAddress, sessionToken.String(), userScopes, -1) token, err := h.generateJwt("admin", h.config.ServerAddress, sessionToken.String(), userScopes, -1)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
p.Token = token return c.JSON(http.StatusOK, domain.LoginResponse{
p.BaseResponse.IsError = false BaseResponse: domain.BaseResponse{
return c.JSON(http.StatusOK, p) Message: "OK",
},
Token: token,
Type: "Bearer",
})
} }
// This will take collect some information about the requested refresh, validate and then return a new jwt token if approved. // This will take collect some information about the requested refresh, validate and then return a new jwt token if approved.
@ -181,58 +155,47 @@ func (h *Handler) createAdminToken(c echo.Context, password string) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) RefreshJwtToken(c echo.Context) error { func (h *Handler) RefreshJwtToken(c echo.Context) error {
p := domain.LoginResponse{
BaseResponse: domain.BaseResponse{
Message: "OK",
},
//Token: jwt,
Type: "Bearer",
//RefreshToken: newRefreshToken,
}
_, err := h.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) _, err := h.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
// Check the context for the refresh token // Check the context for the refresh token
var request domain.RefreshTokenRequest var request domain.RefreshTokenRequest
err = (&echo.DefaultBinder{}).BindBody(c, &request) err = (&echo.DefaultBinder{}).BindBody(c, &request)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
err = h.repo.RefreshTokens.IsRequestValid(c.Request().Context(), request.Username, request.RefreshToken) err = h.repo.RefreshTokens.IsRequestValid(c.Request().Context(), request.Username, request.RefreshToken)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
user, err := h.repo.Users.GetUser(c.Request().Context(), request.Username) user, err := h.repo.Users.GetUser(c.Request().Context(), request.Username)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
userScopes := strings.Split(user.Scopes, ",") userScopes := strings.Split(user.Scopes, ",")
jwt, err := h.generateJwtWithExp(request.Username, h.config.ServerAddress, user.SessionToken, userScopes, user.ID, time.Now().Add(time.Hour*48)) jwt, err := h.generateJwtWithExp(request.Username, h.config.ServerAddress, user.SessionToken, userScopes, user.ID, time.Now().Add(time.Hour*48))
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
newRefreshToken, err := h.repo.RefreshTokens.Create(c.Request().Context(), request.Username) newRefreshToken, err := h.repo.RefreshTokens.Create(c.Request().Context(), request.Username)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
p.Token = jwt return c.JSON(http.StatusOK, domain.LoginResponse{
p.RefreshToken = newRefreshToken BaseResponse: domain.BaseResponse{
p.BaseResponse.IsError = false Message: "OK",
return c.JSON(http.StatusOK, p) },
Token: jwt,
Type: "Bearer",
RefreshToken: newRefreshToken,
})
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
@ -246,32 +209,25 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error {
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) AddScopes(c echo.Context) error { func (h *Handler) AddScopes(c echo.Context) error {
p := domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
}
_, err := h.ValidateJwtToken(c, domain.ScopeAll) _, err := h.ValidateJwtToken(c, domain.ScopeAll)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusUnauthorized, p)
} }
request := domain.UpdateScopesRequest{} request := domain.UpdateScopesRequest{}
err = (&echo.DefaultBinder{}).BindBody(c, &request) err = (&echo.DefaultBinder{}).BindBody(c, &request)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
err = h.repo.Users.AddScopes(c.Request().Context(), request.Username, request.Scopes) err = h.repo.Users.AddScopes(c.Request().Context(), request.Username, request.Scopes)
if err != nil { if err != nil {
p.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
p.IsError = false return c.JSON(http.StatusOK, domain.BaseResponse{
return c.JSON(http.StatusOK, p) Message: "OK",
})
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
@ -281,42 +237,34 @@ func (h *Handler) AddScopes(c echo.Context) error {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) RemoveScopes(c echo.Context) error { func (h *Handler) RemoveScopes(c echo.Context) error {
p := domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
}
token, err := h.getJwtTokenFromContext(c) token, err := h.getJwtTokenFromContext(c)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusUnauthorized)
return c.JSON(http.StatusUnauthorized, p)
} }
err = token.IsValid(domain.ScopeAll) err = token.IsValid(domain.ScopeAll)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusUnauthorized)
return c.JSON(http.StatusBadRequest, p)
} }
request := domain.UpdateScopesRequest{} request := domain.UpdateScopesRequest{}
err = (&echo.DefaultBinder{}).BindBody(c, &request) err = (&echo.DefaultBinder{}).BindBody(c, &request)
if err != nil { if err != nil {
p.Message = err.Error() h.WriteError(c, err, http.StatusBadRequest)
return c.JSON(http.StatusBadRequest, p)
} }
err = h.repo.Users.RemoveScopes(c.Request().Context(), request.Username, request.Scopes) err = h.repo.Users.RemoveScopes(c.Request().Context(), request.Username, request.Scopes)
if err != nil { if err != nil {
p.Message = err.Error() return h.InternalServerErrorResponse(c, err.Error())
return c.JSON(http.StatusInternalServerError, p)
} }
p.IsError = false return c.JSON(http.StatusOK, domain.BaseResponse{
return c.JSON(http.StatusOK, p) Message: "OK",
})
} }
// @Summary Revokes the current session token and replaces it with a new one. // @Summary Revokes the current session token and replaces it with a new one.
@ -324,28 +272,22 @@ func (h *Handler) RemoveScopes(c echo.Context) error {
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) NewSessionToken(c echo.Context) error { func (h *Handler) NewSessionToken(c echo.Context) error {
p := domain.BaseResponse{
Message: ResponseMessageSuccess,
IsError: true,
}
token, err := h.getJwtTokenFromContext(c) token, err := h.getJwtTokenFromContext(c)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusUnauthorized)
return c.JSON(http.StatusUnauthorized, p)
} }
_, err = h.repo.Users.NewSessionToken(c.Request().Context(), token.UserName) _, err = h.repo.Users.NewSessionToken(c.Request().Context(), token.UserName)
if err != nil { if err != nil {
p.Message = err.Error() return h.WriteError(c, err, http.StatusInternalServerError)
return c.JSON(http.StatusInternalServerError, p)
} }
p.IsError = false return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
return c.JSON(http.StatusInternalServerError, p) Message: "OK",
})
} }