Compare commits
No commits in common. "3cf6afb39c5e01317e89fb8888871cb4f5433daf" and "56199a795a2b7a8c5e37a904aa133829b9026c47" have entirely different histories.
3cf6afb39c
...
56199a795a
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,7 +3,6 @@ dev.session.sql
|
||||
__debug_bin
|
||||
server
|
||||
.vscode
|
||||
openapi.json
|
||||
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
@ -13,7 +12,6 @@ openapi.json
|
||||
*.dylib
|
||||
collector
|
||||
newsbot.db
|
||||
tmp/
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
3756
api/api.gen.go
3756
api/api.gen.go
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
|
||||
package: api
|
||||
output: api.gen.go
|
||||
generate:
|
||||
models: true
|
||||
client: true
|
@ -16,13 +16,13 @@ import (
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
|
||||
)
|
||||
|
||||
// @title NewsBot collector
|
||||
// @version 0.1
|
||||
// @BasePath /api
|
||||
// @securityDefinitions.apikey Bearer
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @description Type "Bearer" followed by a space and JWT token.
|
||||
// @title NewsBot collector
|
||||
// @version 0.1
|
||||
// @BasePath /api
|
||||
// @securityDefinitions.apikey Bearer
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @description Type "Bearer" followed by a space and JWT token.
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
|
125
docs/docs.go
125
docs/docs.go
@ -32,11 +32,10 @@ const docTemplate = `{
|
||||
"summary": "Lists the top 25 records ordering from newest to oldest.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"type": "string",
|
||||
"description": "page number",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@ -61,7 +60,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/by/source/{id}": {
|
||||
"/v1/articles/by/sourceId": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -80,7 +79,7 @@ const docTemplate = `{
|
||||
"type": "string",
|
||||
"description": "source id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -112,7 +111,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/{id}": {
|
||||
"/v1/articles/{ID}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -130,7 +129,7 @@ const docTemplate = `{
|
||||
{
|
||||
"type": "string",
|
||||
"description": "int",
|
||||
"name": "id",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
@ -157,7 +156,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/{id}/details": {
|
||||
"/v1/articles/{ID}/details": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -175,7 +174,7 @@ const docTemplate = `{
|
||||
{
|
||||
"type": "string",
|
||||
"description": "int",
|
||||
"name": "id",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
@ -346,50 +345,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{ID}": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
@ -431,7 +387,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}/disable": {
|
||||
"/v1/discord/webhooks/{ID}/disable": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
@ -473,7 +429,7 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}/enable": {
|
||||
"/v1/discord/webhooks/{ID}/enable": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
@ -515,6 +471,51 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/sources": {
|
||||
"get": {
|
||||
"security": [
|
||||
@ -1511,16 +1512,24 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"Bearer": {
|
||||
"description": "Type \"Bearer\" followed by a space and JWT token.",
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "",
|
||||
Version: "0.1",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
BasePath: "/api",
|
||||
Schemes: []string{},
|
||||
Title: "",
|
||||
Title: "NewsBot collector",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
|
@ -1,8 +1,11 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"contact": {}
|
||||
"title": "NewsBot collector",
|
||||
"contact": {},
|
||||
"version": "0.1"
|
||||
},
|
||||
"basePath": "/api",
|
||||
"paths": {
|
||||
"/v1/articles": {
|
||||
"get": {
|
||||
@ -20,11 +23,10 @@
|
||||
"summary": "Lists the top 25 records ordering from newest to oldest.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"type": "string",
|
||||
"description": "page number",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@ -49,7 +51,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/by/source/{id}": {
|
||||
"/v1/articles/by/sourceId": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -68,7 +70,7 @@
|
||||
"type": "string",
|
||||
"description": "source id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -100,7 +102,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/{id}": {
|
||||
"/v1/articles/{ID}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -118,7 +120,7 @@
|
||||
{
|
||||
"type": "string",
|
||||
"description": "int",
|
||||
"name": "id",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
@ -145,7 +147,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/articles/{id}/details": {
|
||||
"/v1/articles/{ID}/details": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
@ -163,7 +165,7 @@
|
||||
{
|
||||
"type": "string",
|
||||
"description": "int",
|
||||
"name": "id",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
@ -334,50 +336,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{ID}": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
@ -419,7 +378,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}/disable": {
|
||||
"/v1/discord/webhooks/{ID}/disable": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
@ -461,7 +420,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}/enable": {
|
||||
"/v1/discord/webhooks/{ID}/enable": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
@ -503,6 +462,51 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/discord/webhooks/{id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"DiscordWebhook"
|
||||
],
|
||||
"summary": "Returns the top 100 entries from the queue to be processed.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "id",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/sources": {
|
||||
"get": {
|
||||
"security": [
|
||||
@ -1499,5 +1503,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"Bearer": {
|
||||
"description": "Type \"Bearer\" followed by a space and JWT token.",
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
basePath: /api
|
||||
definitions:
|
||||
domain.ArticleAndSourceModel:
|
||||
properties:
|
||||
@ -153,6 +154,8 @@ definitions:
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
title: NewsBot collector
|
||||
version: "0.1"
|
||||
paths:
|
||||
/v1/articles:
|
||||
get:
|
||||
@ -160,8 +163,7 @@ paths:
|
||||
- description: page number
|
||||
in: query
|
||||
name: page
|
||||
required: true
|
||||
type: integer
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -182,12 +184,12 @@ paths:
|
||||
summary: Lists the top 25 records ordering from newest to oldest.
|
||||
tags:
|
||||
- Articles
|
||||
/v1/articles/{id}:
|
||||
/v1/articles/{ID}:
|
||||
get:
|
||||
parameters:
|
||||
- description: int
|
||||
in: path
|
||||
name: id
|
||||
name: ID
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
@ -210,12 +212,12 @@ paths:
|
||||
summary: Returns an article based on defined ID.
|
||||
tags:
|
||||
- Articles
|
||||
/v1/articles/{id}/details:
|
||||
/v1/articles/{ID}/details:
|
||||
get:
|
||||
parameters:
|
||||
- description: int
|
||||
in: path
|
||||
name: id
|
||||
name: ID
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
@ -238,11 +240,11 @@ paths:
|
||||
summary: Returns an article and source based on defined ID.
|
||||
tags:
|
||||
- Articles
|
||||
/v1/articles/by/source/{id}:
|
||||
/v1/articles/by/sourceId:
|
||||
get:
|
||||
parameters:
|
||||
- description: source id
|
||||
in: path
|
||||
in: query
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
@ -293,7 +295,7 @@ paths:
|
||||
summary: Returns the top 100
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
/v1/discord/webhooks/{id}:
|
||||
/v1/discord/webhooks/{ID}:
|
||||
delete:
|
||||
parameters:
|
||||
- description: id
|
||||
@ -319,34 +321,7 @@ paths:
|
||||
summary: Deletes a record by ID.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
get:
|
||||
parameters:
|
||||
- description: id
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns the top 100 entries from the queue to be processed.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
/v1/discord/webhooks/{id}/disable:
|
||||
/v1/discord/webhooks/{ID}/disable:
|
||||
post:
|
||||
parameters:
|
||||
- description: id
|
||||
@ -372,7 +347,7 @@ paths:
|
||||
summary: Disables a Webhook from being used.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
/v1/discord/webhooks/{id}/enable:
|
||||
/v1/discord/webhooks/{ID}/enable:
|
||||
post:
|
||||
parameters:
|
||||
- description: id
|
||||
@ -398,6 +373,34 @@ paths:
|
||||
summary: Enables a source to continue processing.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
/v1/discord/webhooks/{id}:
|
||||
get:
|
||||
parameters:
|
||||
- description: id
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Returns the top 100 entries from the queue to be processed.
|
||||
tags:
|
||||
- DiscordWebhook
|
||||
/v1/discord/webhooks/by/serverAndChannel:
|
||||
get:
|
||||
parameters:
|
||||
@ -942,4 +945,10 @@ paths:
|
||||
summary: Adds a new scope to a user account
|
||||
tags:
|
||||
- Users
|
||||
securityDefinitions:
|
||||
Bearer:
|
||||
description: Type "Bearer" followed by a space and JWT token.
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
swagger: "2.0"
|
||||
|
@ -10,15 +10,15 @@ import (
|
||||
)
|
||||
|
||||
// ListArticles
|
||||
// @Summary Lists the top 25 records ordering from newest to oldest.
|
||||
// @Produce application/json
|
||||
// @Param page query int true "page number" test
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles [get]
|
||||
// @Success 200 {object} domain.ArticleResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Lists the top 25 records ordering from newest to oldest.
|
||||
// @Produce application/json
|
||||
// @Param page query string false "page number"
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles [get]
|
||||
// @Success 200 {object} domain.ArticleResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) listArticles(c echo.Context) error {
|
||||
resp := domain.ArticleResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -48,15 +48,15 @@ func (s *Handler) listArticles(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetArticle
|
||||
// @Summary Returns an article based on defined ID.
|
||||
// @Param id path string true "int"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/{id} [get]
|
||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns an article based on defined ID.
|
||||
// @Param ID path string true "int"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/{ID} [get]
|
||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) getArticle(c echo.Context) error {
|
||||
p := domain.ArticleResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -90,15 +90,15 @@ func (s *Handler) getArticle(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetArticleDetails
|
||||
// @Summary Returns an article and source based on defined ID.
|
||||
// @Param id path string true "int"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/{id}/details [get]
|
||||
// @Success 200 {object} domain.ArticleDetailedResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns an article and source based on defined ID.
|
||||
// @Param ID path string true "int"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/{ID}/details [get]
|
||||
// @Success 200 {object} domain.ArticleDetailedResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) getArticleDetails(c echo.Context) error {
|
||||
p := domain.ArticleDetailedResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -135,16 +135,16 @@ func (s *Handler) getArticleDetails(c echo.Context) error {
|
||||
}
|
||||
|
||||
// ListArticlesBySourceID
|
||||
// @Summary Finds the articles based on the SourceID provided. Returns the top 25.
|
||||
// @Param id path string true "source id"
|
||||
// @Param page query int false "Page to query"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/by/source/{id} [get]
|
||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Finds the articles based on the SourceID provided. Returns the top 25.
|
||||
// @Param id query string true "source id"
|
||||
// @Param page query int false "Page to query"
|
||||
// @Produce application/json
|
||||
// @Tags Articles
|
||||
// @Router /v1/articles/by/sourceId [get]
|
||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
|
||||
p := domain.ArticleResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
|
@ -11,14 +11,14 @@ import (
|
||||
)
|
||||
|
||||
// ListDiscordWebhooks
|
||||
// @Summary Returns the top 100
|
||||
// @Produce application/json
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns the top 100
|
||||
// @Produce application/json
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -43,15 +43,15 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetDiscordWebHook
|
||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||
// @Produce application/json
|
||||
// @Param id path int true "id"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{id} [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||
// @Produce application/json
|
||||
// @Param id path int true "id"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{id} [get]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -83,16 +83,16 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetDiscordWebHookByServerAndChannel
|
||||
// @Summary Returns all the known web hooks based on the Server and Channel given.
|
||||
// @Produce application/json
|
||||
// @Param server query string true "Fancy Server"
|
||||
// @Param channel query string true "memes"
|
||||
// @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
|
||||
// @Security Bearer
|
||||
// @Summary Returns all the known web hooks based on the Server and Channel given.
|
||||
// @Produce application/json
|
||||
// @Param server query string true "Fancy Server"
|
||||
// @Param channel query string true "memes"
|
||||
// @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
|
||||
// @Security Bearer
|
||||
func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -131,16 +131,16 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
||||
}
|
||||
|
||||
// NewDiscordWebHook
|
||||
// @Summary Creates a new record for a discord web hook to post data to.
|
||||
// @Param url query string true "url"
|
||||
// @Param server query string true "Server name"
|
||||
// @Param channel query string true "Channel name"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/new [post]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
// @Summary Creates a new record for a discord web hook to post data to.
|
||||
// @Param url query string true "url"
|
||||
// @Param server query string true "Server name"
|
||||
// @Param channel query string true "Channel name"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/new [post]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.DiscordWebhookResponse
|
||||
// @Failure 500 {object} domain.DiscordWebhookResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -208,14 +208,14 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DisableDiscordWebHooks
|
||||
// @Summary Disables a Webhook from being used.
|
||||
// @Param id path int true "id"
|
||||
// @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
|
||||
// @Security Bearer
|
||||
// @Summary Disables a Webhook from being used.
|
||||
// @Param id path int true "id"
|
||||
// @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
|
||||
// @Security Bearer
|
||||
func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -276,14 +276,14 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
||||
}
|
||||
|
||||
// EnableDiscordWebHook
|
||||
// @Summary Enables a source to continue processing.
|
||||
// @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
|
||||
// @Summary Enables a source to continue processing.
|
||||
// @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{
|
||||
@ -342,14 +342,14 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteDiscordWebHook
|
||||
// @Summary Deletes a record by ID.
|
||||
// @Param id path string true "id"
|
||||
// @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
|
||||
// @Summary Deletes a record by ID.
|
||||
// @Param id path string true "id"
|
||||
// @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
|
||||
func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
||||
p := domain.DiscordWebhookResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -409,13 +409,13 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
||||
}
|
||||
|
||||
// UpdateDiscordWebHook
|
||||
// @Summary Updates a valid discord webhook ID based on the body given.
|
||||
// @Param id path string true "id"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{id} [patch]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Summary Updates a valid discord webhook ID based on the body given.
|
||||
// @Param id path string true "id"
|
||||
// @Tags DiscordWebhook
|
||||
// @Router /v1/discord/webhooks/{id} [patch]
|
||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
//func (s *Handler) UpdateDiscordWebHook(c echo.Context) error {
|
||||
// id, err := strconv.Atoi(c.Param("ID"))
|
||||
// if err != nil {
|
||||
|
@ -8,19 +8,18 @@ import (
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// ListSources
|
||||
// @Summary Lists the top 50 records
|
||||
// @Param page query string false "page number"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems"
|
||||
// @Security Bearer
|
||||
// @Summary Lists the top 50 records
|
||||
// @Param page query string false "page number"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems"
|
||||
// @Security Bearer
|
||||
func (s *Handler) listSources(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -53,16 +52,16 @@ func (s *Handler) listSources(c echo.Context) error {
|
||||
}
|
||||
|
||||
// ListSourcesBySource
|
||||
// @Summary Lists the top 50 records based on the name given. Example: reddit
|
||||
// @Param source query string true "Source Name"
|
||||
// @Param page query string false "page number"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/by/source [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Lists the top 50 records based on the name given. Example: reddit
|
||||
// @Param source query string true "Source Name"
|
||||
// @Param page query string false "page number"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/by/source [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -101,15 +100,15 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetSource
|
||||
// @Summary Returns a single entity by ID
|
||||
// @Param id path int true "id"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns a single entity by ID
|
||||
// @Param id path int true "id"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) getSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -143,16 +142,16 @@ func (s *Handler) getSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// GetSourceByNameAndSource
|
||||
// @Summary Returns a single entity by ID
|
||||
// @Param name query string true "dadjokes"
|
||||
// @Param source query string true "reddit"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/by/sourceAndName [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Returns a single entity by ID
|
||||
// @Param name query string true "dadjokes"
|
||||
// @Param source query string true "reddit"
|
||||
// @Produce application/json
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/by/sourceAndName [get]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -188,15 +187,15 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
||||
}
|
||||
|
||||
// NewRedditSource
|
||||
// @Summary Creates a new reddit source to monitor.
|
||||
// @Param name query string true "name"
|
||||
// @Param url query string true "url"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/reddit [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Creates a new reddit source to monitor.
|
||||
// @Param name query string true "name"
|
||||
// @Param url query string true "url"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/reddit [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newRedditSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -262,15 +261,15 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// NewYoutubeSource
|
||||
// @Summary Creates a new youtube source to monitor.
|
||||
// @Param name query string true "name"
|
||||
// @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
|
||||
// @Summary Creates a new youtube source to monitor.
|
||||
// @Param name query string true "name"
|
||||
// @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{
|
||||
@ -335,14 +334,14 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// NewTwitchSource
|
||||
// @Summary Creates a new twitch source to monitor.
|
||||
// @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
|
||||
// @Summary Creates a new twitch source to monitor.
|
||||
// @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{
|
||||
@ -397,14 +396,14 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// NewRssSource
|
||||
// @Summary Creates a new rss source to monitor.
|
||||
// @Param request body domain.NewSourceParamRequest true "body"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/rss [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Creates a new rss source to monitor.
|
||||
// @Param request body domain.NewSourceParamRequest true "body"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/new/rss [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) newRssSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -420,8 +419,7 @@ func (s *Handler) newRssSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
param := domain.NewSourceParamRequest{}
|
||||
err = c.Bind(¶m)
|
||||
//err = (&echo.DefaultBinder{}).BindBody(c, ¶m)
|
||||
err = (&echo.DefaultBinder{}).BindBody(c, ¶m)
|
||||
if err != nil {
|
||||
p.BaseResponse.Message = err.Error()
|
||||
return c.JSON(http.StatusBadRequest, p)
|
||||
@ -433,15 +431,8 @@ func (s *Handler) newRssSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// Check if the record already exists
|
||||
blankRecord := entity.SourceEntity{}
|
||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name)
|
||||
if err != nil {
|
||||
p.IsError = true
|
||||
return c.JSON(http.StatusInternalServerError, p)
|
||||
}
|
||||
|
||||
// No record was found, but no error returned
|
||||
if item != blankRecord {
|
||||
if err == nil {
|
||||
var dto []domain.SourceDto
|
||||
dto = append(dto, dtoconv.SourceToDto(item))
|
||||
p.Payload = dto
|
||||
@ -449,14 +440,6 @@ func (s *Handler) newRssSource(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, 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)
|
||||
//}
|
||||
|
||||
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 {
|
||||
@ -483,14 +466,14 @@ func (s *Handler) newRssSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DeleteSource
|
||||
// @Summary Marks a source as deleted based on its ID value.
|
||||
// @Param id path int true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [POST]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Marks a source as deleted based on its ID value.
|
||||
// @Param id path int true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id} [POST]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) deleteSources(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -543,14 +526,14 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
||||
}
|
||||
|
||||
// DisableSource
|
||||
// @Summary Disables a source from processing.
|
||||
// @Param id path int true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/disable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Disables a source from processing.
|
||||
// @Param id path int true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/disable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) disableSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -598,14 +581,14 @@ func (s *Handler) disableSource(c echo.Context) error {
|
||||
}
|
||||
|
||||
// EnableSource
|
||||
// @Summary Enables a source to continue processing.
|
||||
// @Param id path string true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/enable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
// @Summary Enables a source to continue processing.
|
||||
// @Param id path string true "id"
|
||||
// @Tags Source
|
||||
// @Router /v1/sources/{id}/enable [post]
|
||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
||||
// @Failure 400 {object} domain.SourcesResponse
|
||||
// @Failure 500 {object} domain.SourcesResponse
|
||||
// @Security Bearer
|
||||
func (s *Handler) enableSource(c echo.Context) error {
|
||||
p := domain.SourcesResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
|
@ -17,15 +17,15 @@ const (
|
||||
ErrUsernameAlreadyExists = "the requested username already exists"
|
||||
)
|
||||
|
||||
// @Summary Creates a new user
|
||||
// @Router /v1/users/register [post]
|
||||
// @Param request formData domain.LoginFormRequest true "form"
|
||||
// @Accepts x-www-form-urlencoded
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 201 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Summary Creates a new user
|
||||
// @Router /v1/users/register [post]
|
||||
// @Param request formData domain.LoginFormRequest true "form"
|
||||
// @Accepts x-www-form-urlencoded
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 201 {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,
|
||||
@ -66,15 +66,15 @@ func (h *Handler) AuthRegister(c echo.Context) error {
|
||||
return c.JSON(http.StatusCreated, p)
|
||||
}
|
||||
|
||||
// @Summary Logs into the API and returns a bearer token if successful
|
||||
// @Router /v1/users/login [post]
|
||||
// @Param request formData domain.LoginFormRequest true "form"
|
||||
// @Accepts x-www-form-urlencoded
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 200 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.LoginResponse
|
||||
// @Failure 500 {object} domain.LoginResponse
|
||||
// @Summary Logs into the API and returns a bearer token if successful
|
||||
// @Router /v1/users/login [post]
|
||||
// @Param request formData domain.LoginFormRequest true "form"
|
||||
// @Accepts x-www-form-urlencoded
|
||||
// @Produce json
|
||||
// @Tags Users
|
||||
// @Success 200 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.LoginResponse
|
||||
// @Failure 500 {object} domain.LoginResponse
|
||||
func (h *Handler) AuthLogin(c echo.Context) error {
|
||||
p := domain.LoginResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -172,14 +172,14 @@ func (h *Handler) createAdminToken(c echo.Context, password string) error {
|
||||
|
||||
// This will take collect some information about the requested refresh, validate and then return a new jwt token if approved.
|
||||
// Register
|
||||
// @Summary Generates a new token
|
||||
// @Router /v1/users/refresh/token [post]
|
||||
// @Param request body domain.RefreshTokenRequest true "body"
|
||||
// @Tags Users
|
||||
// @Success 200 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Generates a new token
|
||||
// @Router /v1/users/refresh/token [post]
|
||||
// @Param request body domain.RefreshTokenRequest true "body"
|
||||
// @Tags Users
|
||||
// @Success 200 {object} domain.LoginResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) RefreshJwtToken(c echo.Context) error {
|
||||
p := domain.LoginResponse{
|
||||
BaseResponse: domain.BaseResponse{
|
||||
@ -235,16 +235,16 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
// @Summary Adds a new scope to a user account
|
||||
// @Router /v1/users/scopes/add [post]
|
||||
// @Param request body domain.UpdateScopesRequest true "body"
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Adds a new scope to a user account
|
||||
// @Router /v1/users/scopes/add [post]
|
||||
// @Param request body domain.UpdateScopesRequest true "body"
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) AddScopes(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
@ -274,16 +274,16 @@ func (h *Handler) AddScopes(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
// @Summary Adds a new scope to a user account
|
||||
// @Router /v1/users/scopes/remove [post]
|
||||
// @Param request body domain.UpdateScopesRequest true "body"
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Adds a new scope to a user account
|
||||
// @Router /v1/users/scopes/remove [post]
|
||||
// @Param request body domain.UpdateScopesRequest true "body"
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) RemoveScopes(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
@ -319,15 +319,15 @@ func (h *Handler) RemoveScopes(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, p)
|
||||
}
|
||||
|
||||
// @Summary Revokes the current session token and replaces it with a new one.
|
||||
// @Router /v1/users/refresh/sessionToken [post]
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
// @Summary Revokes the current session token and replaces it with a new one.
|
||||
// @Router /v1/users/refresh/sessionToken [post]
|
||||
// @Tags Users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.BaseResponse
|
||||
// @Failure 400 {object} domain.BaseResponse
|
||||
// @Failure 500 {object} domain.BaseResponse
|
||||
// @Security Bearer
|
||||
func (h *Handler) NewSessionToken(c echo.Context) error {
|
||||
p := domain.BaseResponse{
|
||||
Message: ResponseMessageSuccess,
|
||||
|
@ -121,7 +121,7 @@ func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name s
|
||||
b.Select("*")
|
||||
b.From("Sources").Where(
|
||||
b.Equal("Source", source),
|
||||
b.Equal("DisplayName", name),
|
||||
b.Equal("Name", name),
|
||||
)
|
||||
b.Limit(1)
|
||||
query, args := b.Build()
|
||||
|
11
makefile
11
makefile
@ -19,13 +19,8 @@ migrate-dev-down: ## revert sql migrations to dev db
|
||||
goose -dir "./internal/database/migrations" sqlite3 ./cmd/newsbot.db down
|
||||
|
||||
swag: ## Generates the swagger documentation with the swag tool
|
||||
~/go/bin/swag f -g cmd/server.go
|
||||
~/go/bin/swag f
|
||||
~/go/bin/swag init -g cmd/server.go
|
||||
go run tools/swaggertoopenapi/main.go
|
||||
oapi-codegen -config api/client.yaml docs/openapi.json
|
||||
mv api.gen.go api/
|
||||
|
||||
install-tools: ## Installs the required tools for this project
|
||||
go install github.com/swaggo/swag/cmd/swag@v1.8.1
|
||||
go install github.com/pressly/goose/v3/cmd/goose@latest
|
||||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.3.0
|
||||
gensql: ## Generates SQL code with sqlc
|
||||
sqlc generate
|
@ -1,17 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/tools/swaggertoopenapi/src"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
err := src.ConvertToOpenApi("docs/swagger.json", "docs/openapi.json", true)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package src
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
ApplicationJson = "application/json"
|
||||
)
|
||||
|
||||
func ConvertToOpenApi(filePath, outputPath string, force bool) error {
|
||||
// check if the file already exists
|
||||
exists, err := os.Stat(outputPath)
|
||||
if exists != nil {
|
||||
// if force was given, attempt to remove it
|
||||
if force {
|
||||
err = os.Remove(outputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("'%s' already exists and force was not approved", outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Reading '%s'", filePath)
|
||||
content, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest(http.MethodPost, "https://converter.swagger.io/api/convert", bytes.NewReader(content))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Accept", ApplicationJson)
|
||||
req.Header.Add("Content-Type", ApplicationJson)
|
||||
|
||||
log.Println("Converting to OpenAPI spec")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Reading the response")
|
||||
respContent, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Writing converted data to openapi.json")
|
||||
writer, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer writer.Close()
|
||||
|
||||
_, err = writer.Write(respContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package src_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/tools/swaggerToOpenapi/src"
|
||||
)
|
||||
|
||||
func TestConvertOnline(t *testing.T) {
|
||||
err := src.ConvertToOpenApi("../../docs/swagger.json", "../../docs/openapi.json", true)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user