Added discord management that was missing (#27)
This commit is contained in:
parent
b082c904ea
commit
ac8eeaea01
@ -261,6 +261,15 @@ func (q *Queries) DeleteSubscription(ctx context.Context, id uuid.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const disableDiscordWebHook = `-- name: DisableDiscordWebHook :exec
|
||||
Update discordwebhooks Set Enabled = FALSE where ID = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DisableDiscordWebHook(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, disableDiscordWebHook, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const disableSource = `-- name: DisableSource :exec
|
||||
Update Sources Set Enabled = FALSE where ID = $1
|
||||
`
|
||||
@ -270,6 +279,15 @@ func (q *Queries) DisableSource(ctx context.Context, id uuid.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const enableDiscordWebHook = `-- name: EnableDiscordWebHook :exec
|
||||
Update discordwebhooks Set Enabled = TRUE where ID = $1
|
||||
`
|
||||
|
||||
func (q *Queries) EnableDiscordWebHook(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, enableDiscordWebHook, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const enableSource = `-- name: EnableSource :exec
|
||||
Update Sources Set Enabled = TRUE where ID = $1
|
||||
`
|
||||
|
@ -78,6 +78,11 @@ Select * From discordwebhooks LIMIT $1;
|
||||
-- name: DeleteDiscordWebHooks :exec
|
||||
Delete From discordwebhooks Where ID = $1;
|
||||
|
||||
-- name: DisableDiscordWebHook :exec
|
||||
Update discordwebhooks Set Enabled = FALSE where ID = $1;
|
||||
|
||||
-- name: EnableDiscordWebHook :exec
|
||||
Update discordwebhooks Set Enabled = TRUE where ID = $1;
|
||||
|
||||
/* Icons */
|
||||
|
||||
|
104
docs/docs.go
104
docs/docs.go
@ -305,29 +305,6 @@ const docTemplate = `{
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/byId": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/new": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@ -362,6 +339,87 @@ const docTemplate = `{
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"Config",
|
||||
"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": [
|
||||
"Config",
|
||||
"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": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Enables a source to continue processing.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/hello/{who}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -296,29 +296,6 @@
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/byId": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/new": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@ -353,6 +330,87 @@
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"Config",
|
||||
"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": [
|
||||
"Config",
|
||||
"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": [
|
||||
"Config",
|
||||
"Discord",
|
||||
"Webhook"
|
||||
],
|
||||
"summary": "Enables a source to continue processing.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/hello/{who}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -205,11 +205,24 @@ paths:
|
||||
- Config
|
||||
- Discord
|
||||
- Webhook
|
||||
/discord/webhooks/byId:
|
||||
/discord/webhooks/{id}:
|
||||
delete:
|
||||
parameters:
|
||||
- description: id
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
responses: {}
|
||||
summary: Deletes a record by ID.
|
||||
tags:
|
||||
- Config
|
||||
- Discord
|
||||
- Webhook
|
||||
get:
|
||||
parameters:
|
||||
- description: id
|
||||
in: query
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
@ -221,6 +234,34 @@ paths:
|
||||
- Config
|
||||
- Discord
|
||||
- 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:
|
||||
- Config
|
||||
- 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:
|
||||
- Config
|
||||
- Discord
|
||||
- Webhook
|
||||
/discord/webhooks/new:
|
||||
post:
|
||||
parameters:
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jtom38/newsbot/collector/database"
|
||||
)
|
||||
@ -33,12 +34,12 @@ func (s *Server) GetDiscordWebHooks(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(bres)
|
||||
}
|
||||
|
||||
// GetDiscorWebHooksById
|
||||
// GetDiscordWebHook
|
||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Param id path string true "id"
|
||||
// @Tags Config, Discord, Webhook
|
||||
// @Router /discord/webhooks/byId [get]
|
||||
// @Router /discord/webhooks/{id} [get]
|
||||
func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@ -113,3 +114,78 @@ func (s *Server) NewDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(bJson)
|
||||
}
|
||||
|
||||
// DisableDiscordWebHooks
|
||||
// @Summary Disables a Webhook from being used.
|
||||
// @Param id path string true "id"
|
||||
// @Tags Config, Discord, Webhook
|
||||
// @Router /discord/webhooks/{id}/disable [post]
|
||||
func (s *Server) disableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||
id := chi.URLParam(r, "ID")
|
||||
uuid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err = s.Db.DisableDiscordWebHook(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// EnableDiscordWebHook
|
||||
// @Summary Enables a source to continue processing.
|
||||
// @Param id path string true "id"
|
||||
// @Tags Config, Discord, Webhook
|
||||
// @Router /discord/webhooks/{id}/enable [post]
|
||||
func (s *Server) enableDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||
id := chi.URLParam(r, "ID")
|
||||
uuid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.Db.GetDiscordWebHooksByID(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err = s.Db.EnableDiscordWebHook(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteDiscordWebHook
|
||||
// @Summary Deletes a record by ID.
|
||||
// @Param id path string true "id"
|
||||
// @Tags Config, Discord, Webhook
|
||||
// @Router /discord/webhooks/{id} [delete]
|
||||
func (s *Server) deleteDiscordWebHook(w http.ResponseWriter, r *http.Request) {
|
||||
//var item model.Sources = model.Sources{}
|
||||
|
||||
id := chi.URLParam(r, "ID")
|
||||
uuid, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Check to make sure we can find the record
|
||||
_, err = s.Db.GetDiscordQueueByID(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Delete the record
|
||||
err = s.Db.DeleteDiscordWebHooks(*s.ctx, uuid)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,13 @@ func (s *Server) MountRoutes() {
|
||||
/* Discord WebHooks */
|
||||
s.Router.Post("/api/discord/webhooks/new", s.NewDiscordWebHook)
|
||||
s.Router.Get("/api/discord/webhooks", s.GetDiscordWebHooks)
|
||||
s.Router.Get("/api/discord/webhooks/byId", s.GetDiscordWebHooksById)
|
||||
//s.Router.Get("/api/discord/webhooks/byId", s.GetDiscordWebHooksById)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user