updated discordwebhooks to use dto
This commit is contained in:
parent
663cbc4e37
commit
176459f17d
159
docs/docs.go
159
docs/docs.go
@ -158,7 +158,14 @@ const docTemplate = `{
|
|||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/routes.ListDiscordWebhooks"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/discord/webhooks/new": {
|
"/discord/webhooks/new": {
|
||||||
@ -194,6 +201,63 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/discord/webhooks/{ID}": {
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Deletes a record by ID.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/discord/webhooks/{ID}/disable": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Disables a Webhook from being used.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/discord/webhooks/{ID}/enable": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Enables a source to continue processing.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/discord/webhooks/{id}": {
|
"/discord/webhooks/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
@ -213,24 +277,14 @@ const docTemplate = `{
|
|||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {
|
||||||
},
|
"200": {
|
||||||
"delete": {
|
"description": "OK",
|
||||||
"tags": [
|
"schema": {
|
||||||
"Discord",
|
"$ref": "#/definitions/routes.GetDiscordWebhook"
|
||||||
"Webhook"
|
}
|
||||||
],
|
|
||||||
"summary": "Deletes a record by ID.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
"responses": {}
|
|
||||||
},
|
},
|
||||||
"patch": {
|
"patch": {
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -250,44 +304,6 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/discord/webhooks/{id}/disable": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Discord",
|
|
||||||
"Webhook"
|
|
||||||
],
|
|
||||||
"summary": "Disables a Webhook from being used.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/discord/webhooks/{id}/enable": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Discord",
|
|
||||||
"Webhook"
|
|
||||||
],
|
|
||||||
"summary": "Enables a source to continue processing.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/hello/{who}": {
|
"/hello/{who}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
@ -1042,6 +1058,20 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"routes.GetDiscordWebhook": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"payload": {
|
||||||
|
"$ref": "#/definitions/models.DiscordWebHooksDto"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"routes.GetSourceResult": {
|
"routes.GetSourceResult": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -1073,6 +1103,23 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"routes.ListDiscordWebhooks": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"payload": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/models.DiscordWebHooksDto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"routes.ListSourcesResults": {
|
"routes.ListSourcesResults": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -149,7 +149,14 @@
|
|||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/routes.ListDiscordWebhooks"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/discord/webhooks/new": {
|
"/discord/webhooks/new": {
|
||||||
@ -185,6 +192,63 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/discord/webhooks/{ID}": {
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Deletes a record by ID.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/discord/webhooks/{ID}/disable": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Disables a Webhook from being used.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/discord/webhooks/{ID}/enable": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Discord",
|
||||||
|
"Webhook"
|
||||||
|
],
|
||||||
|
"summary": "Enables a source to continue processing.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/discord/webhooks/{id}": {
|
"/discord/webhooks/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
@ -204,24 +268,14 @@
|
|||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {
|
||||||
},
|
"200": {
|
||||||
"delete": {
|
"description": "OK",
|
||||||
"tags": [
|
"schema": {
|
||||||
"Discord",
|
"$ref": "#/definitions/routes.GetDiscordWebhook"
|
||||||
"Webhook"
|
}
|
||||||
],
|
|
||||||
"summary": "Deletes a record by ID.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
"responses": {}
|
|
||||||
},
|
},
|
||||||
"patch": {
|
"patch": {
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -241,44 +295,6 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/discord/webhooks/{id}/disable": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Discord",
|
|
||||||
"Webhook"
|
|
||||||
],
|
|
||||||
"summary": "Disables a Webhook from being used.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/discord/webhooks/{id}/enable": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Discord",
|
|
||||||
"Webhook"
|
|
||||||
],
|
|
||||||
"summary": "Enables a source to continue processing.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "id",
|
|
||||||
"name": "id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/hello/{who}": {
|
"/hello/{who}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
@ -1033,6 +1049,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"routes.GetDiscordWebhook": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"payload": {
|
||||||
|
"$ref": "#/definitions/models.DiscordWebHooksDto"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"routes.GetSourceResult": {
|
"routes.GetSourceResult": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -1064,6 +1094,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"routes.ListDiscordWebhooks": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"payload": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/models.DiscordWebHooksDto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"routes.ListSourcesResults": {
|
"routes.ListSourcesResults": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -161,6 +161,15 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
routes.GetDiscordWebhook:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
$ref: '#/definitions/models.DiscordWebHooksDto'
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
routes.GetSourceResult:
|
routes.GetSourceResult:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
@ -181,6 +190,17 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
routes.ListDiscordWebhooks:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/models.DiscordWebHooksDto'
|
||||||
|
type: array
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
routes.ListSourcesResults:
|
routes.ListSourcesResults:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
@ -295,7 +315,7 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
- Webhook
|
- Webhook
|
||||||
/discord/webhooks/{id}:
|
/discord/webhooks/{ID}:
|
||||||
delete:
|
delete:
|
||||||
parameters:
|
parameters:
|
||||||
- description: id
|
- description: id
|
||||||
@ -308,6 +328,33 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
- Webhook
|
- Webhook
|
||||||
|
/discord/webhooks/{ID}/disable:
|
||||||
|
post:
|
||||||
|
parameters:
|
||||||
|
- description: id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses: {}
|
||||||
|
summary: Disables a Webhook from being used.
|
||||||
|
tags:
|
||||||
|
- Discord
|
||||||
|
- Webhook
|
||||||
|
/discord/webhooks/{ID}/enable:
|
||||||
|
post:
|
||||||
|
parameters:
|
||||||
|
- description: id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses: {}
|
||||||
|
summary: Enables a source to continue processing.
|
||||||
|
tags:
|
||||||
|
- Discord
|
||||||
|
- Webhook
|
||||||
|
/discord/webhooks/{id}:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
- description: id
|
- description: id
|
||||||
@ -317,7 +364,11 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses: {}
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/routes.GetDiscordWebhook'
|
||||||
summary: Returns the top 100 entries from the queue to be processed.
|
summary: Returns the top 100 entries from the queue to be processed.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
@ -334,32 +385,6 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
- Webhook
|
- Webhook
|
||||||
/discord/webhooks/{id}/disable:
|
|
||||||
post:
|
|
||||||
parameters:
|
|
||||||
- description: id
|
|
||||||
in: path
|
|
||||||
name: id
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
responses: {}
|
|
||||||
summary: Disables a Webhook from being used.
|
|
||||||
tags:
|
|
||||||
- Discord
|
|
||||||
- Webhook
|
|
||||||
/discord/webhooks/{id}/enable:
|
|
||||||
post:
|
|
||||||
parameters:
|
|
||||||
- description: id
|
|
||||||
in: path
|
|
||||||
name: id
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
responses: {}
|
|
||||||
summary: Enables a source to continue processing.
|
|
||||||
tags:
|
|
||||||
- Discord
|
|
||||||
- Webhook
|
|
||||||
/discord/webhooks/by/serverAndChannel:
|
/discord/webhooks/by/serverAndChannel:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
@ -375,7 +400,11 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses: {}
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/routes.ListDiscordWebhooks'
|
||||||
summary: Returns all the known web hooks based on the Server and Channel given.
|
summary: Returns all the known web hooks based on the Server and Channel given.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
|
63
dto/discordwebhooks.go
Normal file
63
dto/discordwebhooks.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jtom38/newsbot/collector/database"
|
||||||
|
"github.com/jtom38/newsbot/collector/domain/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c DtoClient) ListDiscordWebHooks(ctx context.Context, total int32) ([]models.DiscordWebHooksDto, error) {
|
||||||
|
var res []models.DiscordWebHooksDto
|
||||||
|
|
||||||
|
items, err := c.db.ListDiscordWebhooks(ctx, total)
|
||||||
|
if err != nil {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
res = append(res, c.ConvertDiscordWebhook(item))
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c DtoClient) GetDiscordWebhook(ctx context.Context, id uuid.UUID) (models.DiscordWebHooksDto, error) {
|
||||||
|
var res models.DiscordWebHooksDto
|
||||||
|
|
||||||
|
item, err := c.db.GetDiscordWebHooksByID(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.ConvertDiscordWebhook(item), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c DtoClient) GetDiscordWebHookByServerAndChannel(ctx context.Context, server, channel string) ([]models.DiscordWebHooksDto, error) {
|
||||||
|
var res []models.DiscordWebHooksDto
|
||||||
|
|
||||||
|
items, err := c.db.GetDiscordWebHooksByServerAndChannel(ctx, database.GetDiscordWebHooksByServerAndChannelParams{
|
||||||
|
Server: server,
|
||||||
|
Channel: channel,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
res = append(res, c.ConvertDiscordWebhook(item))
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c DtoClient) ConvertDiscordWebhook(i database.Discordwebhook) models.DiscordWebHooksDto {
|
||||||
|
return models.DiscordWebHooksDto{
|
||||||
|
ID: i.ID,
|
||||||
|
Url: i.Url,
|
||||||
|
Server: i.Server,
|
||||||
|
Channel: i.Channel,
|
||||||
|
Enabled: i.Enabled,
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -10,63 +9,106 @@ import (
|
|||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jtom38/newsbot/collector/database"
|
"github.com/jtom38/newsbot/collector/database"
|
||||||
|
"github.com/jtom38/newsbot/collector/domain/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetDiscordWebHooks
|
func (s Server) DiscordWebHookRouter() http.Handler {
|
||||||
|
r := chi.NewRouter()
|
||||||
|
|
||||||
|
r.Get("/", s.ListDiscordWebHooks)
|
||||||
|
r.Post("/new", s.NewDiscordWebHook)
|
||||||
|
r.Get("/by/serverAndChannel", s.GetDiscordWebHooksByServerAndChannel)
|
||||||
|
r.Route("/{ID}", func(r chi.Router) {
|
||||||
|
r.Get("/", s.GetDiscordWebHooksById)
|
||||||
|
r.Delete("/", s.deleteDiscordWebHook)
|
||||||
|
r.Post("/disable", s.disableDiscordWebHook)
|
||||||
|
r.Post("/enable", s.enableDiscordWebHook)
|
||||||
|
})
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListDiscordWebhooks struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload []models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListDiscordWebhooks
|
||||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks [get]
|
// @Router /discord/webhooks [get]
|
||||||
func (s *Server) GetDiscordWebHooks(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ListDiscordWebHooks(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
p := ListDiscordWebhooks{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
res, err := s.Db.ListDiscordWebhooks(*s.ctx, 100)
|
StatusCode: http.StatusOK,
|
||||||
if err != nil {
|
},
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bres, err := json.Marshal(res)
|
w.Header().Set(HeaderContentType, ApplicationJson)
|
||||||
|
|
||||||
|
res, err := s.dto.ListDiscordWebHooks(r.Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
panic(err)
|
return
|
||||||
|
}
|
||||||
|
p.Payload = res
|
||||||
|
|
||||||
|
bres, err := json.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(bres)
|
w.Write(bres)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetDiscordWebhook struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetDiscordWebHook
|
// GetDiscordWebHook
|
||||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id} [get]
|
// @Router /discord/webhooks/{id} [get]
|
||||||
|
// @Success 200 {object} GetDiscordWebhook "OK"
|
||||||
func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
p := GetDiscordWebhook{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set(HeaderContentType, ApplicationJson)
|
||||||
|
|
||||||
_id := chi.URLParam(r, "ID")
|
_id := chi.URLParam(r, "ID")
|
||||||
if _id == "" {
|
if _id == "" {
|
||||||
http.Error(w, "id is missing", http.StatusBadRequest)
|
s.WriteError(w, "id is missing", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, err := uuid.Parse(_id)
|
uuid, err := uuid.Parse(_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "unable to parse id value", http.StatusBadRequest)
|
s.WriteError(w, "unable to parse id value", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
res, err := s.dto.GetDiscordWebhook(r.Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "no record found", http.StatusBadRequest)
|
s.WriteError(w, "no record found", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p.Payload = res
|
||||||
|
|
||||||
bres, err := json.Marshal(res)
|
bres, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "unable to convert to json", http.StatusBadRequest)
|
s.WriteError(w, "unable to convert to json", http.StatusBadRequest)
|
||||||
panic(err)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(bres)
|
w.Write(bres)
|
||||||
@ -79,41 +121,47 @@ func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request)
|
|||||||
// @Param channel query string true "memes"
|
// @Param channel query string true "memes"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/by/serverAndChannel [get]
|
// @Router /discord/webhooks/by/serverAndChannel [get]
|
||||||
|
// @Success 200 {object} ListDiscordWebhooks "OK"
|
||||||
func (s *Server) GetDiscordWebHooksByServerAndChannel(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) GetDiscordWebHooksByServerAndChannel(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
p := ListDiscordWebhooks{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set(HeaderContentType, ApplicationJson)
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
_server := query["server"][0]
|
_server := query["server"][0]
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
http.Error(w, "ID is missing", http.StatusInternalServerError)
|
s.WriteError(w, "ID is missing", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_channel := query["channel"][0]
|
_channel := query["channel"][0]
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
http.Error(w, "Channel is missing", http.StatusInternalServerError)
|
s.WriteError(w, "Channel is missing", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.Db.GetDiscordWebHooksByServerAndChannel(context.Background(), database.GetDiscordWebHooksByServerAndChannelParams{
|
res, err := s.dto.GetDiscordWebHookByServerAndChannel(r.Context(), _server, _channel)
|
||||||
Server: _server,
|
|
||||||
Channel: _channel,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bres, err := json.Marshal(res)
|
p.Payload = res
|
||||||
|
|
||||||
|
bres, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "unable to convert to json", http.StatusInternalServerError)
|
s.WriteError(w, "unable to convert to json", http.StatusInternalServerError)
|
||||||
panic(err)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(bres)
|
w.Write(bres)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NewDiscordWebHook
|
// NewDiscordWebHook
|
||||||
// @Summary Creates a new record for a discord web hook to post data to.
|
// @Summary Creates a new record for a discord web hook to post data to.
|
||||||
// @Param url query string true "url"
|
// @Param url query string true "url"
|
||||||
@ -162,23 +210,25 @@ func (s *Server) NewDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
|||||||
// @Summary Disables a Webhook from being used.
|
// @Summary Disables a Webhook from being used.
|
||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id}/disable [post]
|
// @Router /discord/webhooks/{ID}/disable [post]
|
||||||
func (s *Server) disableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) disableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||||
id := chi.URLParam(r, "ID")
|
id := chi.URLParam(r, "ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Db.DisableDiscordWebHook(*s.ctx, uuid)
|
err = s.Db.DisableDiscordWebHook(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,23 +236,23 @@ func (s *Server) disableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
|||||||
// @Summary Enables a source to continue processing.
|
// @Summary Enables a source to continue processing.
|
||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id}/enable [post]
|
// @Router /discord/webhooks/{ID}/enable [post]
|
||||||
func (s *Server) enableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) enableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||||
id := chi.URLParam(r, "ID")
|
id := chi.URLParam(r, "ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Db.EnableDiscordWebHook(*s.ctx, uuid)
|
err = s.Db.EnableDiscordWebHook(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,26 +260,26 @@ func (s *Server) enableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
|||||||
// @Summary Deletes a record by ID.
|
// @Summary Deletes a record by ID.
|
||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id} [delete]
|
// @Router /discord/webhooks/{ID} [delete]
|
||||||
func (s *Server) deleteDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) deleteDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||||
//var item model.Sources = model.Sources{}
|
//var item model.Sources = model.Sources{}
|
||||||
|
|
||||||
id := chi.URLParam(r, "ID")
|
id := chi.URLParam(r, "ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetDiscordQueueByID(*s.ctx, uuid)
|
_, err = s.Db.GetDiscordQueueByID(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the record
|
// Delete the record
|
||||||
err = s.Db.DeleteDiscordWebHooks(*s.ctx, uuid)
|
err = s.Db.DeleteDiscordWebHooks(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,21 +80,8 @@ func (s *Server) MountRoutes() {
|
|||||||
|
|
||||||
s.Router.Mount("/api/articles", s.GetArticleRouter())
|
s.Router.Mount("/api/articles", s.GetArticleRouter())
|
||||||
s.Router.Mount("/api/queue", s.GetQueueRouter())
|
s.Router.Mount("/api/queue", s.GetQueueRouter())
|
||||||
|
s.Router.Mount("/api/discord/webhooks", s.DiscordWebHookRouter())
|
||||||
|
|
||||||
/* Discord WebHooks */
|
|
||||||
s.Router.Get("/api/discord/webhooks", s.GetDiscordWebHooks)
|
|
||||||
s.Router.Post("/api/discord/webhooks/new", s.NewDiscordWebHook)
|
|
||||||
//s.Router.Get("/api/discord/webhooks/byId", s.GetDiscordWebHooksById)
|
|
||||||
s.Router.Get("/api/discord/webhooks/by/serverAndChannel", s.GetDiscordWebHooksByServerAndChannel)
|
|
||||||
|
|
||||||
s.Router.Route("/api/discord/webhooks/{ID}", func(r chi.Router) {
|
|
||||||
r.Get("/", s.GetDiscordWebHooksById)
|
|
||||||
r.Delete("/", s.deleteDiscordWebHook)
|
|
||||||
r.Post("/disable", s.disableDiscordWebHook)
|
|
||||||
r.Post("/enable", s.enableDiscordWebHook)
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Settings */
|
|
||||||
s.Router.Get("/api/settings", s.getSettings)
|
s.Router.Get("/api/settings", s.getSettings)
|
||||||
|
|
||||||
s.Router.Mount("/api/sources", s.GetSourcesRouter())
|
s.Router.Mount("/api/sources", s.GetSourcesRouter())
|
||||||
|
Loading…
Reference in New Issue
Block a user