updated handlers to define if the response was an error #10
148
docs/docs.go
148
docs/docs.go
@ -225,13 +225,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,13 +277,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,13 +333,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,6 +347,11 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"/v1/discord/webhooks/{ID}": {
|
"/v1/discord/webhooks/{ID}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"DiscordWebhook"
|
"DiscordWebhook"
|
||||||
],
|
],
|
||||||
@ -370,13 +375,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,13 +417,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,7 +449,26 @@ 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}": {
|
||||||
@ -480,13 +504,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,7 +548,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.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,13 +593,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -670,13 +694,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -719,13 +743,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -751,7 +775,26 @@ 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": {
|
||||||
@ -781,7 +824,26 @@ 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}": {
|
||||||
@ -817,13 +879,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -857,13 +919,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -899,13 +961,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -941,13 +1003,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -984,13 +1046,13 @@ const docTemplate = `{
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.LoginResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.LoginResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1101,8 +1163,8 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"201": {
|
||||||
"description": "OK",
|
"description": "Created",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.BaseResponse"
|
||||||
}
|
}
|
||||||
@ -1238,6 +1300,9 @@ const docTemplate = `{
|
|||||||
"domain.ArticleDetailedResponse": {
|
"domain.ArticleDetailedResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1287,6 +1352,9 @@ const docTemplate = `{
|
|||||||
"domain.ArticleResponse": {
|
"domain.ArticleResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1301,6 +1369,9 @@ const docTemplate = `{
|
|||||||
"domain.BaseResponse": {
|
"domain.BaseResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@ -1330,6 +1401,9 @@ const docTemplate = `{
|
|||||||
"domain.DiscordWebhookResponse": {
|
"domain.DiscordWebhookResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1344,6 +1418,9 @@ const docTemplate = `{
|
|||||||
"domain.LoginResponse": {
|
"domain.LoginResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1395,6 +1472,9 @@ const docTemplate = `{
|
|||||||
"domain.SourcesResponse": {
|
"domain.SourcesResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
@ -216,13 +216,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,13 +268,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,13 +324,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,6 +338,11 @@
|
|||||||
},
|
},
|
||||||
"/v1/discord/webhooks/{ID}": {
|
"/v1/discord/webhooks/{ID}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"DiscordWebhook"
|
"DiscordWebhook"
|
||||||
],
|
],
|
||||||
@ -361,13 +366,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,13 +408,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,7 +440,26 @@
|
|||||||
"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}": {
|
||||||
@ -471,13 +495,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,7 +539,7 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Unable to reach SQL or Data problems",
|
"description": "Unable to reach SQL or Data problems",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,13 +584,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -661,13 +685,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -710,13 +734,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -742,7 +766,26 @@
|
|||||||
"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": {
|
||||||
@ -772,7 +815,26 @@
|
|||||||
"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}": {
|
||||||
@ -808,13 +870,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -848,13 +910,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -890,13 +952,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -932,13 +994,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.SourcesResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -975,13 +1037,13 @@
|
|||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Bad Request",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.LoginResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Internal Server Error",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.LoginResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1092,8 +1154,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"201": {
|
||||||
"description": "OK",
|
"description": "Created",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/domain.BaseResponse"
|
"$ref": "#/definitions/domain.BaseResponse"
|
||||||
}
|
}
|
||||||
@ -1229,6 +1291,9 @@
|
|||||||
"domain.ArticleDetailedResponse": {
|
"domain.ArticleDetailedResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1278,6 +1343,9 @@
|
|||||||
"domain.ArticleResponse": {
|
"domain.ArticleResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1292,6 +1360,9 @@
|
|||||||
"domain.BaseResponse": {
|
"domain.BaseResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@ -1321,6 +1392,9 @@
|
|||||||
"domain.DiscordWebhookResponse": {
|
"domain.DiscordWebhookResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1335,6 +1409,9 @@
|
|||||||
"domain.LoginResponse": {
|
"domain.LoginResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1386,6 +1463,9 @@
|
|||||||
"domain.SourcesResponse": {
|
"domain.SourcesResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"isError": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.ArticleDetailedResponse:
|
domain.ArticleDetailedResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
payload:
|
payload:
|
||||||
@ -41,6 +43,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.ArticleResponse:
|
domain.ArticleResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
payload:
|
payload:
|
||||||
@ -50,6 +54,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.BaseResponse:
|
domain.BaseResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
@ -71,6 +77,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.DiscordWebhookResponse:
|
domain.DiscordWebhookResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
payload:
|
payload:
|
||||||
@ -80,6 +88,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.LoginResponse:
|
domain.LoginResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
refreshToken:
|
refreshToken:
|
||||||
@ -113,6 +123,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
domain.SourcesResponse:
|
domain.SourcesResponse:
|
||||||
properties:
|
properties:
|
||||||
|
isError:
|
||||||
|
type: boolean
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
payload:
|
payload:
|
||||||
@ -264,11 +276,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Returns the top 100
|
summary: Returns the top 100
|
||||||
@ -290,11 +302,13 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
summary: Deletes a record by ID.
|
summary: Deletes a record by ID.
|
||||||
tags:
|
tags:
|
||||||
- DiscordWebhook
|
- DiscordWebhook
|
||||||
@ -314,11 +328,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Disables a Webhook from being used.
|
summary: Disables a Webhook from being used.
|
||||||
@ -332,7 +346,19 @@ 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.
|
||||||
@ -356,11 +382,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
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.
|
||||||
@ -389,11 +415,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
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.
|
||||||
@ -425,11 +451,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||||
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.
|
||||||
@ -452,7 +478,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.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Lists the top 50 records
|
summary: Lists the top 50 records
|
||||||
@ -476,11 +502,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Returns a single entity by ID
|
summary: Returns a single entity by ID
|
||||||
@ -501,11 +527,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
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.
|
||||||
@ -527,11 +553,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Disables a source from processing.
|
summary: Disables a source from processing.
|
||||||
@ -553,11 +579,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Enables a source to continue processing.
|
summary: Enables a source to continue processing.
|
||||||
@ -585,11 +611,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
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'
|
||||||
@ -649,11 +675,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Creates a new reddit source to monitor.
|
summary: Creates a new reddit source to monitor.
|
||||||
@ -680,11 +706,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.SourcesResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Creates a new rss source to monitor.
|
summary: Creates a new rss source to monitor.
|
||||||
@ -698,7 +724,19 @@ 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.
|
||||||
@ -717,7 +755,19 @@ 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.
|
||||||
@ -742,11 +792,11 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.LoginResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.LoginResponse'
|
||||||
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
|
||||||
@ -813,8 +863,8 @@ paths:
|
|||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"201":
|
||||||
description: OK
|
description: Created
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/domain.BaseResponse'
|
||||||
"400":
|
"400":
|
||||||
|
@ -2,6 +2,7 @@ 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 {
|
||||||
|
@ -20,17 +20,18 @@ 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
|
||||||
@ -38,10 +39,11 @@ 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 s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,32 +58,34 @@ 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 s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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.StatusInternalServerError, err)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,36 +100,37 @@ 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 s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,20 +146,21 @@ 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 s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the page number is missing, default to 0
|
// if the page number is missing, default to 0
|
||||||
@ -165,9 +171,11 @@ 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.StatusInternalServerError, err)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -16,26 +16,29 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
// @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, err)
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,33 +49,36 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
// @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 s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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(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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,37 +90,43 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
// @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 == "" {
|
||||||
return s.WriteMessage(c, "server was not defined", http.StatusBadRequest)
|
p.BaseResponse.Message = "server was not defined"
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
_channel := c.QueryParam("channel")
|
_channel := c.QueryParam("channel")
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
return s.WriteMessage(c, "channel was not defined", http.StatusBadRequest)
|
p.BaseResponse.Message = "channel was not defined"
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,13 +138,21 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
// @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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
_url := c.QueryParam("url")
|
_url := c.QueryParam("url")
|
||||||
@ -140,54 +160,51 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
|||||||
_channel := c.QueryParam("channel")
|
_channel := c.QueryParam("channel")
|
||||||
|
|
||||||
if _url == "" {
|
if _url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.Message = "url is missing a value"
|
||||||
Message: "url is missing a value",
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if !strings.Contains(_url, "discord.com/api/webhooks") {
|
if !strings.Contains(_url, "discord.com/api/webhooks") {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.Message = "invalid url"
|
||||||
Message: "invalid url",
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.Message = "server is missing"
|
||||||
Message: "server is missing",
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.Message = "channel is missing"
|
||||||
Message: "channel is missing",
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 s.WriteMessage(c, ErrUserUnknown, http.StatusBadRequest)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, "data was not written to database", http.StatusInternalServerError)
|
p.Message = "data was not written to database"
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.Message = err.Error()
|
||||||
|
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableDiscordWebHooks
|
// DisableDiscordWebHooks
|
||||||
@ -196,56 +213,66 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
// @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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
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 {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: 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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
|
p.BaseResponse.Message = "unexpected number of updates found"
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
p.Payload = dtos
|
||||||
Message: ResponseMessageSuccess,
|
p.IsError = false
|
||||||
},
|
return c.JSON(http.StatusOK, p)
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableDiscordWebHook
|
// EnableDiscordWebHook
|
||||||
@ -253,50 +280,65 @@ 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated != 1 {
|
if updated != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
p.Payload = dtos
|
||||||
Message: ResponseMessageSuccess,
|
p.IsError = false
|
||||||
},
|
return c.JSON(http.StatusOK, p)
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteDiscordWebHook
|
// DeleteDiscordWebHook
|
||||||
@ -305,52 +347,65 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
|||||||
// @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.BaseResponse
|
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||||
|
// @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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
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 {
|
||||||
return c.JSON(http.StatusBadRequest, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||||
|
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 {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated != 1 {
|
if updated != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
p.Payload = dtos
|
||||||
Message: ResponseMessageSuccess,
|
p.BaseResponse.IsError = false
|
||||||
},
|
return c.JSON(http.StatusOK, p)
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateDiscordWebHook
|
// UpdateDiscordWebHook
|
||||||
|
@ -4,7 +4,6 @@ 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"
|
||||||
@ -13,7 +12,6 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,8 +46,6 @@ 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),
|
||||||
}
|
}
|
||||||
@ -126,29 +122,30 @@ 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.
|
||||||
@ -156,7 +153,7 @@ func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
|
|||||||
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 {
|
||||||
s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
|
return JwtToken{}, errors.New(ErrJwtMissing)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = token.hasExpired()
|
err = token.hasExpired()
|
||||||
@ -173,6 +170,11 @@ 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")
|
||||||
@ -188,7 +190,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 {
|
||||||
s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
return token.GetUserId()
|
return token.GetUserId()
|
||||||
|
@ -18,20 +18,22 @@ 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.BaseResponse "Unable to reach SQL or Data problems"
|
// @Failure 400 {object} domain.SourcesResponse "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 {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||||
|
if err != nil {
|
||||||
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
|
}
|
||||||
|
|
||||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
page, err := strconv.Atoi(c.QueryParam("page"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
page = 0
|
page = 0
|
||||||
@ -40,11 +42,13 @@ 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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Payload = dtoconv.SourcesToDto(items)
|
p.Payload = dtoconv.SourcesToDto(items)
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSourcesBySource
|
// ListSourcesBySource
|
||||||
@ -55,24 +59,27 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||||
|
if err != nil {
|
||||||
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
|
}
|
||||||
|
|
||||||
source := c.QueryParam("source")
|
source := c.QueryParam("source")
|
||||||
if source == "" {
|
if source == "" {
|
||||||
return s.WriteMessage(c, fmt.Sprintf("%s source", ErrParameterMissing), http.StatusBadRequest)
|
p.BaseResponse.Message = fmt.Sprintf("%s source", ErrParameterMissing)
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
page, err := strconv.Atoi(c.QueryParam("page"))
|
||||||
@ -83,13 +90,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 {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: err.Error(),
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Payload = dtoconv.SourcesToDto(items)
|
p.Payload = dtoconv.SourcesToDto(items)
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSource
|
// GetSource
|
||||||
@ -99,37 +106,39 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) getSource(c echo.Context) error {
|
func (s *Handler) getSource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
p := domain.SourcesResponse{
|
||||||
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 {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: ErrUnableToParseId,
|
return c.JSON(http.StatusBadRequest, 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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourceByNameAndSource
|
// GetSourceByNameAndSource
|
||||||
@ -144,34 +153,37 @@ 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 {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||||
|
if err != nil {
|
||||||
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
|
}
|
||||||
|
|
||||||
var param domain.GetSourceBySourceAndNameParamRequest
|
var param domain.GetSourceBySourceAndNameParamRequest
|
||||||
err = c.Bind(¶m)
|
err = c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: err.Error(),
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedditSource
|
// NewRedditSource
|
||||||
@ -181,52 +193,71 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) newRedditSource(c echo.Context) error {
|
func (s *Handler) newRedditSource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||||
|
if err != nil {
|
||||||
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
|
}
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err = c.Bind(¶m)
|
err = c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return s.WriteMessage(c, "url is missing", http.StatusBadRequest)
|
p.BaseResponse.Message = "url is missing"
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
if !strings.Contains(param.Url, "reddit.com") {
|
if !strings.Contains(param.Url, "reddit.com") {
|
||||||
return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
|
p.BaseResponse.Message = "invalid url"
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewYoutubeSource
|
// NewYoutubeSource
|
||||||
@ -235,59 +266,71 @@ 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err = c.Bind(¶m)
|
err = c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return s.WriteMessage(c, "url is missing a value", http.StatusBadRequest)
|
p.BaseResponse.Message = "url is missing a value"
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
if !strings.Contains(param.Url, "youtube.com") {
|
if !strings.Contains(param.Url, "youtube.com") {
|
||||||
return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
|
p.BaseResponse.Message = "invalid url"
|
||||||
}
|
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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
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 {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||||
|
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 {
|
||||||
var dto []domain.SourceDto
|
p.BaseResponse.Message = err.Error()
|
||||||
dto = append(dto, dtoconv.SourceToDto(item))
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
resp.Payload = dto
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
var dto []domain.SourceDto
|
||||||
|
dto = append(dto, dtoconv.SourceToDto(item))
|
||||||
|
p.Payload = dto
|
||||||
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTwitchSource
|
// NewTwitchSource
|
||||||
@ -295,25 +338,29 @@ 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err = c.Bind(¶m)
|
err = c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: err.Error(),
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := fmt.Sprintf("twitch, %v", param.Name)
|
tags := fmt.Sprintf("twitch, %v", param.Name)
|
||||||
@ -324,27 +371,28 @@ 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
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 {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: err.Error(),
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||||
|
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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
|
p.BaseResponse.IsError = false
|
||||||
return c.JSON(http.StatusOK, resp)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRssSource
|
// NewRssSource
|
||||||
@ -354,54 +402,68 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) newRssSource(c echo.Context) error {
|
func (s *Handler) newRssSource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||||
|
if err != nil {
|
||||||
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
|
}
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err = c.Bind(¶m)
|
err = c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: err.Error(),
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
p.BaseResponse.Message = err.Error()
|
||||||
Message: "Url is missing a value",
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteSource
|
// DeleteSource
|
||||||
@ -410,50 +472,58 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = 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
|
||||||
_, 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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
if rows != 1 {
|
if rows != 1 {
|
||||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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
|
||||||
return c.JSON(http.StatusOK, domain.SourcesResponse{
|
p.IsError = false
|
||||||
BaseResponse: domain.BaseResponse{
|
return c.JSON(http.StatusOK, p)
|
||||||
Message: "OK",
|
|
||||||
},
|
|
||||||
Payload: items,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableSource
|
// DisableSource
|
||||||
@ -462,46 +532,53 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) disableSource(c echo.Context) error {
|
func (s *Handler) disableSource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = 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
|
||||||
_, 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableSource
|
// EnableSource
|
||||||
@ -510,44 +587,51 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.SourcesResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.SourcesResponse
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (s *Handler) enableSource(c echo.Context) error {
|
func (s *Handler) enableSource(c echo.Context) error {
|
||||||
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
p := domain.SourcesResponse{
|
||||||
if err != nil {
|
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
|
IsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = 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
|
||||||
_, 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 {
|
||||||
return s.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
p.BaseResponse.Message = 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))
|
||||||
resp.Payload = dto
|
p.Payload = dto
|
||||||
return c.JSON(http.StatusOK, resp)
|
p.BaseResponse.IsError = false
|
||||||
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,15 @@ const (
|
|||||||
// @Accepts x-www-form-urlencoded
|
// @Accepts x-www-form-urlencoded
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags Users
|
// @Tags Users
|
||||||
// @Success 200 {object} domain.BaseResponse
|
// @Success 201 {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")
|
||||||
|
|
||||||
@ -36,27 +41,29 @@ 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 {
|
||||||
return h.WriteError(c, err, http.StatusBadRequest)
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if exists.Username == username {
|
if exists.Username == username {
|
||||||
return h.InternalServerErrorResponse(c, ErrUsernameAlreadyExists)
|
p.Message = 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 {
|
||||||
return h.WriteError(c, err, http.StatusInternalServerError)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusCreated, domain.BaseResponse{
|
return c.JSON(http.StatusCreated, p)
|
||||||
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
|
||||||
@ -66,9 +73,19 @@ 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.BaseResponse
|
// @Failure 400 {object} domain.LoginResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.LoginResponse
|
||||||
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")
|
||||||
|
|
||||||
@ -80,13 +97,15 @@ 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO think about moving this down some?
|
// TODO think about moving this down some?
|
||||||
@ -95,53 +114,60 @@ 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
p.Token = jwt
|
||||||
BaseResponse: domain.BaseResponse{
|
p.RefreshToken = refresh
|
||||||
Message: "OK",
|
p.BaseResponse.IsError = false
|
||||||
},
|
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 == "" {
|
||||||
return h.InternalServerErrorResponse(c, ErrUserNotFound)
|
p.BaseResponse.Message = ErrUserNotFound
|
||||||
|
return c.JSON(http.StatusBadRequest, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.config.AdminSecret != password {
|
if h.config.AdminSecret != password {
|
||||||
return h.UnauthorizedResponse(c, ErrUserNotFound)
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
p.Token = token
|
||||||
BaseResponse: domain.BaseResponse{
|
p.BaseResponse.IsError = false
|
||||||
Message: "OK",
|
return c.JSON(http.StatusOK, p)
|
||||||
},
|
|
||||||
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.
|
||||||
@ -155,47 +181,58 @@ 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 {
|
||||||
return h.WriteError(c, err, http.StatusBadRequest)
|
p.BaseResponse.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = 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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.BaseResponse.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
p.Token = jwt
|
||||||
BaseResponse: domain.BaseResponse{
|
p.RefreshToken = newRefreshToken
|
||||||
Message: "OK",
|
p.BaseResponse.IsError = false
|
||||||
},
|
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
|
||||||
@ -209,25 +246,32 @@ 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 {
|
||||||
return h.WriteError(c, err, http.StatusBadRequest)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.WriteError(c, err, http.StatusBadRequest)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.BaseResponse{
|
p.IsError = false
|
||||||
Message: "OK",
|
return c.JSON(http.StatusOK, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Adds a new scope to a user account
|
// @Summary Adds a new scope to a user account
|
||||||
@ -241,30 +285,38 @@ func (h *Handler) AddScopes(c echo.Context) error {
|
|||||||
// @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 {
|
||||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusUnauthorized, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = token.IsValid(domain.ScopeAll)
|
err = token.IsValid(domain.ScopeAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
h.WriteError(c, err, http.StatusBadRequest)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.InternalServerErrorResponse(c, err.Error())
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.BaseResponse{
|
p.IsError = false
|
||||||
Message: "OK",
|
return c.JSON(http.StatusOK, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @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.
|
||||||
@ -277,17 +329,23 @@ func (h *Handler) RemoveScopes(c echo.Context) error {
|
|||||||
// @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 {
|
||||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
p.Message = err.Error()
|
||||||
|
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 {
|
||||||
return h.WriteError(c, err, http.StatusInternalServerError)
|
p.Message = err.Error()
|
||||||
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
p.IsError = false
|
||||||
Message: "OK",
|
return c.JSON(http.StatusInternalServerError, p)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user