Compare commits
No commits in common. "9237369e5a762028edeaf20760a1d93fd90fd1a6" and "877a6a9619d4f9d92c1cc08f67324affd6e57356" have entirely different histories.
9237369e5a
...
877a6a9619
148
docs/docs.go
148
docs/docs.go
@ -225,13 +225,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,13 +277,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -333,13 +333,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,11 +347,6 @@ const docTemplate = `{
|
||||
},
|
||||
"/v1/discord/webhooks/{ID}": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
@ -375,13 +370,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -417,13 +412,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -449,26 +444,7 @@ const docTemplate = `{
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
@ -504,13 +480,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -548,7 +524,7 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Unable to reach SQL or Data problems",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -593,13 +569,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -694,13 +670,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -743,13 +719,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -775,26 +751,7 @@ const docTemplate = `{
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/sources/new/youtube": {
|
||||
@ -824,26 +781,7 @@ const docTemplate = `{
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/sources/{id}": {
|
||||
@ -879,13 +817,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -919,13 +857,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -961,13 +899,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1003,13 +941,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1046,13 +984,13 @@ const docTemplate = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.LoginResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.LoginResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1163,8 +1101,8 @@ const docTemplate = `{
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
@ -1300,9 +1238,6 @@ const docTemplate = `{
|
||||
"domain.ArticleDetailedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1352,9 +1287,6 @@ const docTemplate = `{
|
||||
"domain.ArticleResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1369,9 +1301,6 @@ const docTemplate = `{
|
||||
"domain.BaseResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
@ -1401,9 +1330,6 @@ const docTemplate = `{
|
||||
"domain.DiscordWebhookResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1418,9 +1344,6 @@ const docTemplate = `{
|
||||
"domain.LoginResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1472,9 +1395,6 @@ const docTemplate = `{
|
||||
"domain.SourcesResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -216,13 +216,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -268,13 +268,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,13 +324,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -338,11 +338,6 @@
|
||||
},
|
||||
"/v1/discord/webhooks/{ID}": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
@ -366,13 +361,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -408,13 +403,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -440,26 +435,7 @@
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
@ -495,13 +471,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.DiscordWebhookResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -539,7 +515,7 @@
|
||||
"400": {
|
||||
"description": "Unable to reach SQL or Data problems",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -584,13 +560,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -685,13 +661,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -734,13 +710,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -766,26 +742,7 @@
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/sources/new/youtube": {
|
||||
@ -815,26 +772,7 @@
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/sources/{id}": {
|
||||
@ -870,13 +808,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -910,13 +848,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -952,13 +890,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -994,13 +932,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SourcesResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1037,13 +975,13 @@
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.LoginResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.LoginResponse"
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1154,8 +1092,8 @@
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.BaseResponse"
|
||||
}
|
||||
@ -1291,9 +1229,6 @@
|
||||
"domain.ArticleDetailedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1343,9 +1278,6 @@
|
||||
"domain.ArticleResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1360,9 +1292,6 @@
|
||||
"domain.BaseResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
@ -1392,9 +1321,6 @@
|
||||
"domain.DiscordWebhookResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1409,9 +1335,6 @@
|
||||
"domain.LoginResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1463,9 +1386,6 @@
|
||||
"domain.SourcesResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -9,8 +9,6 @@ definitions:
|
||||
type: object
|
||||
domain.ArticleDetailedResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
payload:
|
||||
@ -43,8 +41,6 @@ definitions:
|
||||
type: object
|
||||
domain.ArticleResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
payload:
|
||||
@ -54,8 +50,6 @@ definitions:
|
||||
type: object
|
||||
domain.BaseResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
type: object
|
||||
@ -77,8 +71,6 @@ definitions:
|
||||
type: object
|
||||
domain.DiscordWebhookResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
payload:
|
||||
@ -88,8 +80,6 @@ definitions:
|
||||
type: object
|
||||
domain.LoginResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
refreshToken:
|
||||
@ -123,8 +113,6 @@ definitions:
|
||||
type: object
|
||||
domain.SourcesResponse:
|
||||
properties:
|
||||
isError:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
payload:
|
||||
@ -276,11 +264,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns the top 100
|
||||
@ -302,13 +290,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
summary: Deletes a record by ID.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
@ -328,11 +314,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Disables a Webhook from being used.
|
||||
@ -346,19 +332,7 @@ paths:
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
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'
|
||||
responses: {}
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Enables a source to continue processing.
|
||||
@ -382,11 +356,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns the top 100 entries from the queue to be processed.
|
||||
@ -415,11 +389,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns all the known web hooks based on the Server and Channel given.
|
||||
@ -451,11 +425,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Creates a new record for a discord web hook to post data to.
|
||||
@ -478,7 +452,7 @@ paths:
|
||||
"400":
|
||||
description: Unable to reach SQL or Data problems
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Lists the top 50 records
|
||||
@ -502,11 +476,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns a single entity by ID
|
||||
@ -527,11 +501,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Marks a source as deleted based on its ID value.
|
||||
@ -553,11 +527,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Disables a source from processing.
|
||||
@ -579,11 +553,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Enables a source to continue processing.
|
||||
@ -611,11 +585,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: 'Lists the top 50 records based on the name given. Example: reddit'
|
||||
@ -675,11 +649,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Creates a new reddit source to monitor.
|
||||
@ -706,11 +680,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SourcesResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Creates a new rss source to monitor.
|
||||
@ -724,19 +698,7 @@ paths:
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
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'
|
||||
responses: {}
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Creates a new twitch source to monitor.
|
||||
@ -755,19 +717,7 @@ paths:
|
||||
name: url
|
||||
required: true
|
||||
type: string
|
||||
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'
|
||||
responses: {}
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Creates a new youtube source to monitor.
|
||||
@ -792,11 +742,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.LoginResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.LoginResponse'
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
summary: Logs into the API and returns a bearer token if successful
|
||||
tags:
|
||||
- Users
|
||||
@ -863,8 +813,8 @@ paths:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"201":
|
||||
description: Created
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.BaseResponse'
|
||||
"400":
|
||||
|
@ -2,7 +2,6 @@ package domain
|
||||
|
||||
type BaseResponse struct {
|
||||
Message string `json:"message"`
|
||||
IsError bool `json:"isError"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
|
@ -20,18 +20,17 @@ import (
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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"))
|
||||
if err != nil {
|
||||
page = 0
|
||||
@ -39,11 +38,10 @@ func (s *Handler) listArticles(c echo.Context) error {
|
||||
|
||||
res, err := s.repo.Articles.ListByPage(c.Request().Context(), page, 25)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, resp)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
resp.Payload = dtoconv.ArticlesToDto(res)
|
||||
resp.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
@ -58,34 +56,32 @@ func (s *Handler) listArticles(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeArticleRead)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
}
|
||||
|
||||
id := c.Param("ID")
|
||||
idNumber, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
item, err := s.repo.Articles.GetById(c.Request().Context(), int64(idNumber))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
var dtos []domain.ArticleDto
|
||||
dtos = append(dtos, dtoconv.ArticleToDto(item))
|
||||
p.Payload = dtos
|
||||
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
@ -100,37 +96,36 @@ func (s *Handler) getArticle(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
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"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
article, err := s.repo.Articles.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
source, err := s.repo.Sources.GetById(c.Request().Context(), article.SourceID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
p.Payload.Article = dtoconv.ArticleToDto(article)
|
||||
p.Payload.Source = dtoconv.SourceToDto(source)
|
||||
p.BaseResponse.IsError = false
|
||||
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
@ -146,21 +141,20 @@ func (s *Handler) getArticleDetails(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// if the page number is missing, default to 0
|
||||
@ -171,11 +165,9 @@ func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
|
||||
|
||||
items, err := s.repo.Articles.ListBySource(c.Request().Context(), _page, 25, id, "")
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
p.Payload = dtoconv.ArticlesToDto(items)
|
||||
p.BaseResponse.IsError = false
|
||||
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
@ -16,29 +16,26 @@ import (
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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(), "")
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
p.Payload = dtoconv.DiscordWebhooksToDto(res)
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
@ -49,36 +46,33 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{id} [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
res, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dtos []domain.DiscordWebHookDto
|
||||
dtos = append(dtos, dtoconv.DiscordWebhookToDto(res))
|
||||
p.Payload = dtos
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
@ -90,43 +84,37 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/by/serverAndChannel [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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")
|
||||
if _server == "" {
|
||||
p.BaseResponse.Message = "server was not defined"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, "server was not defined", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
_channel := c.QueryParam("channel")
|
||||
if _channel == "" {
|
||||
p.BaseResponse.Message = "channel was not defined"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, "channel was not defined", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
res, err := s.repo.DiscordWebHooks.ListByServerAndChannel(c.Request().Context(), _server, _channel)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
p.Payload = dtoconv.DiscordWebhooksToDto(res)
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
@ -138,21 +126,13 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/new [post]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
_url := c.QueryParam("url")
|
||||
@ -160,51 +140,54 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
||||
_channel := c.QueryParam("channel")
|
||||
|
||||
if _url == "" {
|
||||
p.Message = "url is missing a value"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: "url is missing a value",
|
||||
})
|
||||
}
|
||||
if !strings.Contains(_url, "discord.com/api/webhooks") {
|
||||
p.Message = "invalid url"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: "invalid url",
|
||||
})
|
||||
}
|
||||
if _server == "" {
|
||||
p.Message = "server is missing"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: "server is missing",
|
||||
})
|
||||
}
|
||||
if _channel == "" {
|
||||
p.Message = "channel is missing"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: "channel is missing",
|
||||
})
|
||||
}
|
||||
|
||||
user, err := s.repo.Users.GetUser(c.Request().Context(), token.UserName)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, ErrUserUnknown, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
rows, err := s.repo.DiscordWebHooks.Create(c.Request().Context(), user.ID, _url, _server, _channel, true)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if rows != 1 {
|
||||
p.Message = "data was not written to database"
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, "data was not written to database", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.DiscordWebHooks.GetByUrl(c.Request().Context(), _url)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dtos []domain.DiscordWebHookDto
|
||||
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
|
||||
|
||||
p.Payload = dtos
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
Payload: dtos,
|
||||
})
|
||||
}
|
||||
|
||||
// DisableDiscordWebHooks
|
||||
@ -213,66 +196,56 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{ID}/disable [post]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// flip the it
|
||||
updated, err := s.repo.DiscordWebHooks.Disable(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// make sure we got a row updated
|
||||
if updated != 1 {
|
||||
p.BaseResponse.Message = "unexpected number of updates found"
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dtos []domain.DiscordWebHookDto
|
||||
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
|
||||
|
||||
p.Payload = dtos
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
Payload: dtos,
|
||||
})
|
||||
}
|
||||
|
||||
// EnableDiscordWebHook
|
||||
@ -280,65 +253,50 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
||||
// @Param id path int true "id"
|
||||
// @Tags DiscordWebhook
|
||||
// @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
|
||||
func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
updated, err := s.repo.DiscordWebHooks.Enable(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if updated != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dtos []domain.DiscordWebHookDto
|
||||
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
|
||||
|
||||
p.Payload = dtos
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
Payload: dtos,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteDiscordWebHook
|
||||
@ -347,65 +305,52 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{ID} [delete]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
record, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if record.UserID != s.GetUserIdFromJwtToken(c) {
|
||||
p.BaseResponse.Message = ErrYouDontOwnTheRecord
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, ErrYouDontOwnTheRecord, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Soft delete the record
|
||||
updated, err := s.repo.DiscordWebHooks.SoftDelete(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if updated != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dtos []domain.DiscordWebHookDto
|
||||
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
|
||||
|
||||
p.Payload = dtos
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
Payload: dtos,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDiscordWebHook
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
echojwt "github.com/labstack/echo-jwt/v4"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
swagger "github.com/swaggo/echo-swagger"
|
||||
|
||||
_ "git.jamestombleson.com/jtom38/newsbot-api/docs"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/services"
|
||||
)
|
||||
|
||||
@ -46,6 +48,8 @@ var (
|
||||
|
||||
func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Handler {
|
||||
s := &Handler{
|
||||
//Db: db,
|
||||
//dto: dto.NewDtoClient(db),
|
||||
config: configs,
|
||||
repo: services.NewRepositoryService(conn),
|
||||
}
|
||||
@ -122,30 +126,29 @@ func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Han
|
||||
// *ApiStatusModel
|
||||
//}
|
||||
|
||||
//func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error {
|
||||
// return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
// Message: errMessage.Error(),
|
||||
// IsError: true,
|
||||
// })
|
||||
//}
|
||||
func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error {
|
||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
Message: errMessage.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
//func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error {
|
||||
// return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
// Message: msg,
|
||||
// })
|
||||
//}
|
||||
func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error {
|
||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
//func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error {
|
||||
// return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
// Message: msg,
|
||||
// })
|
||||
//}
|
||||
func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error {
|
||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
//func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
|
||||
// return c.JSON(http.StatusUnauthorized, domain.BaseResponse{
|
||||
// Message: msg,
|
||||
// })
|
||||
//}
|
||||
func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
|
||||
return c.JSON(http.StatusUnauthorized, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
// 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.
|
||||
@ -153,7 +156,7 @@ func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Han
|
||||
func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtToken, error) {
|
||||
token, err := s.getJwtTokenFromContext(c)
|
||||
if err != nil {
|
||||
return JwtToken{}, errors.New(ErrJwtMissing)
|
||||
s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
err = token.hasExpired()
|
||||
@ -170,11 +173,6 @@ func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtTok
|
||||
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)
|
||||
if err != nil {
|
||||
return JwtToken{}, errors.New("user record not found")
|
||||
@ -190,7 +188,7 @@ func (s *Handler) ValidateJwtToken(c echo.Context, requiredScope string) (JwtTok
|
||||
func (s *Handler) GetUserIdFromJwtToken(c echo.Context) int64 {
|
||||
token, err := s.getJwtTokenFromContext(c)
|
||||
if err != nil {
|
||||
return -1
|
||||
s.WriteMessage(c, ErrJwtMissing, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
return token.GetUserId()
|
||||
|
@ -18,20 +18,18 @@ import (
|
||||
// @Tags Source
|
||||
// @Router /v1/sources [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems"
|
||||
// @Failure 400 {object} domain.BaseResponse "Unable to reach SQL or Data problems"
|
||||
// @Security Bearer
|
||||
func (s *Handler) listSources(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
||||
@ -42,13 +40,11 @@ func (s *Handler) listSources(c echo.Context) error {
|
||||
// Default way of showing all sources
|
||||
items, err := s.repo.Sources.List(c.Request().Context(), page, 25)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
p.Payload = dtoconv.SourcesToDto(items)
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dtoconv.SourcesToDto(items)
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListSourcesBySource
|
||||
@ -59,27 +55,24 @@ func (s *Handler) listSources(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/by/source [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
source := c.QueryParam("source")
|
||||
if source == "" {
|
||||
p.BaseResponse.Message = fmt.Sprintf("%s source", ErrParameterMissing)
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, fmt.Sprintf("%s source", ErrParameterMissing), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
||||
@ -90,13 +83,13 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||
// Shows the list by Sources.source
|
||||
items, err := s.repo.Sources.ListBySource(c.Request().Context(), page, 25, source)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
p.Payload = dtoconv.SourcesToDto(items)
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dtoconv.SourcesToDto(items)
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetSource
|
||||
@ -106,39 +99,37 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) getSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||
if err != nil {
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
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"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: ErrUnableToParseId,
|
||||
})
|
||||
}
|
||||
|
||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetSourceByNameAndSource
|
||||
@ -153,37 +144,34 @@ func (s *Handler) getSource(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceRead)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
var param domain.GetSourceBySourceAndNameParamRequest
|
||||
err = c.Bind(¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), param.Source, param.Name)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// NewRedditSource
|
||||
@ -193,71 +181,52 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/reddit [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newRedditSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
var param domain.NewSourceParamRequest
|
||||
err = c.Bind(¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
if param.Url == "" {
|
||||
p.BaseResponse.Message = "url is missing"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, "url is missing", http.StatusBadRequest)
|
||||
}
|
||||
if !strings.Contains(param.Url, "reddit.com") {
|
||||
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)
|
||||
return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if rows != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
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 {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// NewYoutubeSource
|
||||
@ -266,71 +235,59 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
||||
// @Param url query string true "url"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/youtube [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newYoutubeSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
// Validate the jwt
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var param domain.NewSourceParamRequest
|
||||
err = c.Bind(¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
if param.Url == "" {
|
||||
p.BaseResponse.Message = "url is missing a value"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, "url is missing a value", http.StatusBadRequest)
|
||||
}
|
||||
if !strings.Contains(param.Url, "youtube.com") {
|
||||
p.BaseResponse.Message = "invalid url"
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteMessage(c, "invalid url", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, 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)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
tags := fmt.Sprintf("twitch, %v", param.Name)
|
||||
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorYoutube, param.Name, param.Url, tags, true)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if rows != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
}
|
||||
|
||||
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)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// NewTwitchSource
|
||||
@ -338,29 +295,25 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
|
||||
// @Param name query string true "name"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/twitch [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newTwitchSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var param domain.NewSourceParamRequest
|
||||
err = c.Bind(¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
tags := fmt.Sprintf("twitch, %v", param.Name)
|
||||
@ -371,28 +324,27 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
||||
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)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorTwitch, param.Name, url, tags, true)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
if rows != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// NewRssSource
|
||||
@ -402,68 +354,54 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/rss [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newRssSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeSourceCreate)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
var param domain.NewSourceParamRequest
|
||||
err = c.Bind(¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
if param.Url == "" {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
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)
|
||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||
Message: "Url is missing a value",
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if rows != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToCreateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
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 {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteSource
|
||||
@ -472,58 +410,50 @@ func (s *Handler) newRssSource(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [POST]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) deleteSources(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Delete the record
|
||||
rows, err := s.repo.Sources.SoftDelete(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
if rows != 1 {
|
||||
p.BaseResponse.Message = ErrFailedToUpdateRecord
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteMessage(c, ErrFailedToUpdateRecord, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// pull the record with its updated value
|
||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var items []domain.SourceDto
|
||||
items = append(items, dtoconv.SourceToDto(item))
|
||||
p.Payload = items
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
|
||||
return c.JSON(http.StatusOK, domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: "OK",
|
||||
},
|
||||
Payload: items,
|
||||
})
|
||||
}
|
||||
|
||||
// DisableSource
|
||||
@ -532,53 +462,46 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/disable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) disableSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
_, err = s.repo.Sources.Disable(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// EnableSource
|
||||
@ -587,51 +510,44 @@ func (s *Handler) disableSource(c echo.Context) error {
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/enable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) enableSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
_, err := s.ValidateJwtToken(c, domain.ScopeAll)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("ID"))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return s.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
_, err = s.repo.Sources.Enable(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
resp.Payload = dto
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
@ -23,15 +23,10 @@ const (
|
||||
// @Accepts x-www-form-urlencoded
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 201 {object} domain.BaseResponse
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
func (h *Handler) AuthRegister(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
}
|
||||
|
||||
username := c.FormValue("username")
|
||||
password := c.FormValue("password")
|
||||
|
||||
@ -41,29 +36,27 @@ func (h *Handler) AuthRegister(c echo.Context) error {
|
||||
// if we have an err, validate that if its not user not found.
|
||||
// if the user is not found, we can use that name
|
||||
if err.Error() != repository.ErrUserNotFound {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return h.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
if exists.Username == username {
|
||||
p.Message = ErrUsernameAlreadyExists
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, ErrUsernameAlreadyExists)
|
||||
}
|
||||
|
||||
//password := c.QueryParam("password")
|
||||
err = h.repo.Users.CheckPasswordForRequirements(password)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
_, err = h.repo.Users.Create(c.Request().Context(), username, password, domain.ScopeArticleRead)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusCreated, p)
|
||||
return c.JSON(http.StatusCreated, domain.BaseResponse{
|
||||
Message: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Logs into the API and returns a bearer token if successful
|
||||
@ -73,19 +66,9 @@ func (h *Handler) AuthRegister(c echo.Context) error {
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 200 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.LoginResponse
|
||||
// @Failure 500 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
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")
|
||||
password := c.FormValue("password")
|
||||
|
||||
@ -97,15 +80,13 @@ func (h *Handler) AuthLogin(c echo.Context) error {
|
||||
// check if the user exists
|
||||
user, err := h.repo.Users.GetUser(c.Request().Context(), username)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
// make sure the hash matches
|
||||
err = h.repo.Users.DoesPasswordMatchHash(c.Request().Context(), username, password)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
// TODO think about moving this down some?
|
||||
@ -114,60 +95,53 @@ func (h *Handler) AuthLogin(c echo.Context) error {
|
||||
|
||||
jwt, err := h.generateJwtWithExp(username, h.config.ServerAddress, user.SessionToken, userScopes, user.ID, expiresAt)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
refresh, err := h.repo.RefreshTokens.Create(c.Request().Context(), username)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
p.Token = jwt
|
||||
p.RefreshToken = refresh
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: "OK",
|
||||
},
|
||||
Token: jwt,
|
||||
Type: "Bearer",
|
||||
RefreshToken: refresh,
|
||||
})
|
||||
}
|
||||
|
||||
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.
|
||||
// this will fail right away and not progress.
|
||||
if h.config.AdminSecret == "" {
|
||||
p.BaseResponse.Message = ErrUserNotFound
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return h.InternalServerErrorResponse(c, ErrUserNotFound)
|
||||
}
|
||||
|
||||
if h.config.AdminSecret != password {
|
||||
p.BaseResponse.Message = ErrUserNotFound
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return h.UnauthorizedResponse(c, ErrUserNotFound)
|
||||
}
|
||||
var userScopes []string
|
||||
userScopes = append(userScopes, domain.ScopeAll)
|
||||
sessionToken, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
token, err := h.generateJwt("admin", h.config.ServerAddress, sessionToken.String(), userScopes, -1)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
p.Token = token
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: "OK",
|
||||
},
|
||||
Token: token,
|
||||
Type: "Bearer",
|
||||
})
|
||||
}
|
||||
|
||||
// This will take collect some information about the requested refresh, validate and then return a new jwt token if approved.
|
||||
@ -181,58 +155,47 @@ func (h *Handler) createAdminToken(c echo.Context, password string) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
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)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return h.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check the context for the refresh token
|
||||
var request domain.RefreshTokenRequest
|
||||
err = (&echo.DefaultBinder{}).BindBody(c, &request)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
err = h.repo.RefreshTokens.IsRequestValid(c.Request().Context(), request.Username, request.RefreshToken)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
user, err := h.repo.Users.GetUser(c.Request().Context(), request.Username)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
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))
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
newRefreshToken, err := h.repo.RefreshTokens.Create(c.Request().Context(), request.Username)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
p.Token = jwt
|
||||
p.RefreshToken = newRefreshToken
|
||||
p.BaseResponse.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.LoginResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Message: "OK",
|
||||
},
|
||||
Token: jwt,
|
||||
Type: "Bearer",
|
||||
RefreshToken: newRefreshToken,
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Adds a new scope to a user account
|
||||
@ -246,32 +209,25 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) AddScopes(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
}
|
||||
|
||||
_, err := h.ValidateJwtToken(c, domain.ScopeAll)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return h.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
request := domain.UpdateScopesRequest{}
|
||||
err = (&echo.DefaultBinder{}).BindBody(c, &request)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return h.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err = h.repo.Users.AddScopes(c.Request().Context(), request.Username, request.Scopes)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.BaseResponse{
|
||||
Message: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Adds a new scope to a user account
|
||||
@ -285,38 +241,30 @@ func (h *Handler) AddScopes(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) RemoveScopes(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
}
|
||||
|
||||
token, err := h.getJwtTokenFromContext(c)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
err = token.IsValid(domain.ScopeAll)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
request := domain.UpdateScopesRequest{}
|
||||
err = (&echo.DefaultBinder{}).BindBody(c, &request)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
h.WriteError(c, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err = h.repo.Users.RemoveScopes(c.Request().Context(), request.Username, request.Scopes)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.InternalServerErrorResponse(c, err.Error())
|
||||
}
|
||||
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusOK, p)
|
||||
return c.JSON(http.StatusOK, domain.BaseResponse{
|
||||
Message: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Revokes the current session token and replaces it with a new one.
|
||||
@ -329,23 +277,17 @@ func (h *Handler) RemoveScopes(c echo.Context) error {
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) NewSessionToken(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
IsError: true,
|
||||
}
|
||||
|
||||
token, err := h.getJwtTokenFromContext(c)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusUnauthorized, p)
|
||||
return h.WriteError(c, err, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
_, err = h.repo.Users.NewSessionToken(c.Request().Context(), token.UserName)
|
||||
if err != nil {
|
||||
p.Message = err.Error()
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return h.WriteError(c, err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
p.IsError = false
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
Message: "OK",
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user