Compare commits

...

5 Commits

16 changed files with 4330 additions and 473 deletions

2
.gitignore vendored
View File

@ -3,6 +3,7 @@ dev.session.sql
__debug_bin __debug_bin
server server
.vscode .vscode
openapi.json
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe
@ -12,6 +13,7 @@ server
*.dylib *.dylib
collector collector
newsbot.db newsbot.db
tmp/
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

3756
api/api.gen.go Normal file

File diff suppressed because it is too large Load Diff

6
api/client.yaml Normal file
View File

@ -0,0 +1,6 @@
# 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

View File

@ -16,13 +16,13 @@ import (
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
) )
// @title NewsBot collector // @title NewsBot collector
// @version 0.1 // @version 0.1
// @BasePath /api // @BasePath /api
// @securityDefinitions.apikey Bearer // @securityDefinitions.apikey Bearer
// @in header // @in header
// @name Authorization // @name Authorization
// @description Type "Bearer" followed by a space and JWT token. // @description Type "Bearer" followed by a space and JWT token.
func main() { func main() {
ctx := context.Background() ctx := context.Background()

View File

@ -32,10 +32,11 @@ const docTemplate = `{
"summary": "Lists the top 25 records ordering from newest to oldest.", "summary": "Lists the top 25 records ordering from newest to oldest.",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "integer",
"description": "page number", "description": "page number",
"name": "page", "name": "page",
"in": "query" "in": "query",
"required": true
} }
], ],
"responses": { "responses": {
@ -60,7 +61,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/articles/by/sourceId": { "/v1/articles/by/source/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
@ -79,7 +80,7 @@ const docTemplate = `{
"type": "string", "type": "string",
"description": "source id", "description": "source id",
"name": "id", "name": "id",
"in": "query", "in": "path",
"required": true "required": true
}, },
{ {
@ -111,7 +112,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/articles/{ID}": { "/v1/articles/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
@ -129,7 +130,7 @@ const docTemplate = `{
{ {
"type": "string", "type": "string",
"description": "int", "description": "int",
"name": "ID", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
@ -156,7 +157,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/articles/{ID}/details": { "/v1/articles/{id}/details": {
"get": { "get": {
"security": [ "security": [
{ {
@ -174,7 +175,7 @@ const docTemplate = `{
{ {
"type": "string", "type": "string",
"description": "int", "description": "int",
"name": "ID", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
@ -345,7 +346,50 @@ const docTemplate = `{
} }
} }
}, },
"/v1/discord/webhooks/{ID}": { "/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"
}
}
}
},
"delete": { "delete": {
"security": [ "security": [
{ {
@ -387,7 +431,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/discord/webhooks/{ID}/disable": { "/v1/discord/webhooks/{id}/disable": {
"post": { "post": {
"security": [ "security": [
{ {
@ -429,7 +473,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/discord/webhooks/{ID}/enable": { "/v1/discord/webhooks/{id}/enable": {
"post": { "post": {
"security": [ "security": [
{ {
@ -471,51 +515,6 @@ 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": { "/v1/sources": {
"get": { "get": {
"security": [ "security": [
@ -1512,24 +1511,16 @@ 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 // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "0.1", Version: "",
Host: "", Host: "",
BasePath: "/api", BasePath: "",
Schemes: []string{}, Schemes: []string{},
Title: "NewsBot collector", Title: "",
Description: "", Description: "",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate, SwaggerTemplate: docTemplate,

View File

@ -1,11 +1,8 @@
{ {
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"title": "NewsBot collector", "contact": {}
"contact": {},
"version": "0.1"
}, },
"basePath": "/api",
"paths": { "paths": {
"/v1/articles": { "/v1/articles": {
"get": { "get": {
@ -23,10 +20,11 @@
"summary": "Lists the top 25 records ordering from newest to oldest.", "summary": "Lists the top 25 records ordering from newest to oldest.",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "integer",
"description": "page number", "description": "page number",
"name": "page", "name": "page",
"in": "query" "in": "query",
"required": true
} }
], ],
"responses": { "responses": {
@ -51,7 +49,7 @@
} }
} }
}, },
"/v1/articles/by/sourceId": { "/v1/articles/by/source/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
@ -70,7 +68,7 @@
"type": "string", "type": "string",
"description": "source id", "description": "source id",
"name": "id", "name": "id",
"in": "query", "in": "path",
"required": true "required": true
}, },
{ {
@ -102,7 +100,7 @@
} }
} }
}, },
"/v1/articles/{ID}": { "/v1/articles/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
@ -120,7 +118,7 @@
{ {
"type": "string", "type": "string",
"description": "int", "description": "int",
"name": "ID", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
@ -147,7 +145,7 @@
} }
} }
}, },
"/v1/articles/{ID}/details": { "/v1/articles/{id}/details": {
"get": { "get": {
"security": [ "security": [
{ {
@ -165,7 +163,7 @@
{ {
"type": "string", "type": "string",
"description": "int", "description": "int",
"name": "ID", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
@ -336,7 +334,50 @@
} }
} }
}, },
"/v1/discord/webhooks/{ID}": { "/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"
}
}
}
},
"delete": { "delete": {
"security": [ "security": [
{ {
@ -378,7 +419,7 @@
} }
} }
}, },
"/v1/discord/webhooks/{ID}/disable": { "/v1/discord/webhooks/{id}/disable": {
"post": { "post": {
"security": [ "security": [
{ {
@ -420,7 +461,7 @@
} }
} }
}, },
"/v1/discord/webhooks/{ID}/enable": { "/v1/discord/webhooks/{id}/enable": {
"post": { "post": {
"security": [ "security": [
{ {
@ -462,51 +503,6 @@
} }
} }
}, },
"/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": { "/v1/sources": {
"get": { "get": {
"security": [ "security": [
@ -1503,13 +1499,5 @@
} }
} }
} }
},
"securityDefinitions": {
"Bearer": {
"description": "Type \"Bearer\" followed by a space and JWT token.",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
} }
} }

View File

@ -1,4 +1,3 @@
basePath: /api
definitions: definitions:
domain.ArticleAndSourceModel: domain.ArticleAndSourceModel:
properties: properties:
@ -154,8 +153,6 @@ definitions:
type: object type: object
info: info:
contact: {} contact: {}
title: NewsBot collector
version: "0.1"
paths: paths:
/v1/articles: /v1/articles:
get: get:
@ -163,7 +160,8 @@ paths:
- description: page number - description: page number
in: query in: query
name: page name: page
type: string required: true
type: integer
produces: produces:
- application/json - application/json
responses: responses:
@ -184,12 +182,12 @@ paths:
summary: Lists the top 25 records ordering from newest to oldest. summary: Lists the top 25 records ordering from newest to oldest.
tags: tags:
- Articles - Articles
/v1/articles/{ID}: /v1/articles/{id}:
get: get:
parameters: parameters:
- description: int - description: int
in: path in: path
name: ID name: id
required: true required: true
type: string type: string
produces: produces:
@ -212,12 +210,12 @@ paths:
summary: Returns an article based on defined ID. summary: Returns an article based on defined ID.
tags: tags:
- Articles - Articles
/v1/articles/{ID}/details: /v1/articles/{id}/details:
get: get:
parameters: parameters:
- description: int - description: int
in: path in: path
name: ID name: id
required: true required: true
type: string type: string
produces: produces:
@ -240,11 +238,11 @@ paths:
summary: Returns an article and source based on defined ID. summary: Returns an article and source based on defined ID.
tags: tags:
- Articles - Articles
/v1/articles/by/sourceId: /v1/articles/by/source/{id}:
get: get:
parameters: parameters:
- description: source id - description: source id
in: query in: path
name: id name: id
required: true required: true
type: string type: string
@ -295,7 +293,7 @@ paths:
summary: Returns the top 100 summary: Returns the top 100
tags: tags:
- DiscordWebhook - DiscordWebhook
/v1/discord/webhooks/{ID}: /v1/discord/webhooks/{id}:
delete: delete:
parameters: parameters:
- description: id - description: id
@ -321,59 +319,6 @@ paths:
summary: Deletes a record by ID. summary: Deletes a record by ID.
tags: tags:
- DiscordWebhook - DiscordWebhook
/v1/discord/webhooks/{ID}/disable:
post:
parameters:
- description: id
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
security:
- Bearer: []
summary: Disables a Webhook from being used.
tags:
- DiscordWebhook
/v1/discord/webhooks/{ID}/enable:
post:
parameters:
- description: id
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
security:
- Bearer: []
summary: Enables a source to continue processing.
tags:
- DiscordWebhook
/v1/discord/webhooks/{id}:
get: get:
parameters: parameters:
- description: id - description: id
@ -401,6 +346,58 @@ paths:
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:
- DiscordWebhook - DiscordWebhook
/v1/discord/webhooks/{id}/disable:
post:
parameters:
- description: id
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
security:
- Bearer: []
summary: Disables a Webhook from being used.
tags:
- DiscordWebhook
/v1/discord/webhooks/{id}/enable:
post:
parameters:
- description: id
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.DiscordWebhookResponse'
security:
- Bearer: []
summary: Enables a source to continue processing.
tags:
- DiscordWebhook
/v1/discord/webhooks/by/serverAndChannel: /v1/discord/webhooks/by/serverAndChannel:
get: get:
parameters: parameters:
@ -945,10 +942,4 @@ paths:
summary: Adds a new scope to a user account summary: Adds a new scope to a user account
tags: tags:
- Users - Users
securityDefinitions:
Bearer:
description: Type "Bearer" followed by a space and JWT token.
in: header
name: Authorization
type: apiKey
swagger: "2.0" swagger: "2.0"

View File

@ -10,15 +10,15 @@ import (
) )
// ListArticles // ListArticles
// @Summary Lists the top 25 records ordering from newest to oldest. // @Summary Lists the top 25 records ordering from newest to oldest.
// @Produce application/json // @Produce application/json
// @Param page query string false "page number" // @Param page query int true "page number" test
// @Tags Articles // @Tags Articles
// @Router /v1/articles [get] // @Router /v1/articles [get]
// @Success 200 {object} domain.ArticleResponse // @Success 200 {object} domain.ArticleResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) listArticles(c echo.Context) error { func (s *Handler) listArticles(c echo.Context) error {
resp := domain.ArticleResponse{ resp := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -48,15 +48,15 @@ func (s *Handler) listArticles(c echo.Context) error {
} }
// GetArticle // GetArticle
// @Summary Returns an article based on defined ID. // @Summary Returns an article based on defined ID.
// @Param ID path string true "int" // @Param id path string true "int"
// @Produce application/json // @Produce application/json
// @Tags Articles // @Tags Articles
// @Router /v1/articles/{ID} [get] // @Router /v1/articles/{id} [get]
// @Success 200 {object} domain.ArticleResponse "OK" // @Success 200 {object} domain.ArticleResponse "OK"
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getArticle(c echo.Context) error { func (s *Handler) getArticle(c echo.Context) error {
p := domain.ArticleResponse{ p := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -90,15 +90,15 @@ func (s *Handler) getArticle(c echo.Context) error {
} }
// GetArticleDetails // GetArticleDetails
// @Summary Returns an article and source based on defined ID. // @Summary Returns an article and source based on defined ID.
// @Param ID path string true "int" // @Param id path string true "int"
// @Produce application/json // @Produce application/json
// @Tags Articles // @Tags Articles
// @Router /v1/articles/{ID}/details [get] // @Router /v1/articles/{id}/details [get]
// @Success 200 {object} domain.ArticleDetailedResponse "OK" // @Success 200 {object} domain.ArticleDetailedResponse "OK"
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getArticleDetails(c echo.Context) error { func (s *Handler) getArticleDetails(c echo.Context) error {
p := domain.ArticleDetailedResponse{ p := domain.ArticleDetailedResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -135,16 +135,16 @@ func (s *Handler) getArticleDetails(c echo.Context) error {
} }
// ListArticlesBySourceID // ListArticlesBySourceID
// @Summary Finds the articles based on the SourceID provided. Returns the top 25. // @Summary Finds the articles based on the SourceID provided. Returns the top 25.
// @Param id query string true "source id" // @Param id path string true "source id"
// @Param page query int false "Page to query" // @Param page query int false "Page to query"
// @Produce application/json // @Produce application/json
// @Tags Articles // @Tags Articles
// @Router /v1/articles/by/sourceId [get] // @Router /v1/articles/by/source/{id} [get]
// @Success 200 {object} domain.ArticleResponse "OK" // @Success 200 {object} domain.ArticleResponse "OK"
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) ListArticlesBySourceId(c echo.Context) error { func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
p := domain.ArticleResponse{ p := domain.ArticleResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{

View File

@ -11,14 +11,14 @@ import (
) )
// ListDiscordWebhooks // ListDiscordWebhooks
// @Summary Returns the top 100 // @Summary Returns the top 100
// @Produce application/json // @Produce application/json
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks [get] // @Router /v1/discord/webhooks [get]
// @Success 200 {object} domain.DiscordWebhookResponse // @Success 200 {object} domain.DiscordWebhookResponse
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) ListDiscordWebHooks(c echo.Context) error { func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -43,15 +43,15 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
} }
// 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 int true "id" // @Param id path int true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{id} [get] // @Router /v1/discord/webhooks/{id} [get]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetDiscordWebHooksById(c echo.Context) error { func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -83,16 +83,16 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
} }
// GetDiscordWebHookByServerAndChannel // GetDiscordWebHookByServerAndChannel
// @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.
// @Produce application/json // @Produce application/json
// @Param server query string true "Fancy Server" // @Param server query string true "Fancy Server"
// @Param channel query string true "memes" // @Param channel query string true "memes"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/by/serverAndChannel [get] // @Router /v1/discord/webhooks/by/serverAndChannel [get]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error { func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -131,16 +131,16 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
} }
// 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"
// @Param server query string true "Server name" // @Param server query string true "Server name"
// @Param channel query string true "Channel name" // @Param channel query string true "Channel name"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/new [post] // @Router /v1/discord/webhooks/new [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) NewDiscordWebHook(c echo.Context) error { func (s *Handler) NewDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -208,14 +208,14 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
} }
// DisableDiscordWebHooks // DisableDiscordWebHooks
// @Summary Disables a Webhook from being used. // @Summary Disables a Webhook from being used.
// @Param id path int true "id" // @Param id path int true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID}/disable [post] // @Router /v1/discord/webhooks/{id}/disable [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) disableDiscordWebHook(c echo.Context) error { func (s *Handler) disableDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -276,14 +276,14 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
} }
// EnableDiscordWebHook // EnableDiscordWebHook
// @Summary Enables a source to continue processing. // @Summary Enables a source to continue processing.
// @Param id path int true "id" // @Param id path int true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID}/enable [post] // @Router /v1/discord/webhooks/{id}/enable [post]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) enableDiscordWebHook(c echo.Context) error { func (s *Handler) enableDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -342,14 +342,14 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
} }
// DeleteDiscordWebHook // DeleteDiscordWebHook
// @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 DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{ID} [delete] // @Router /v1/discord/webhooks/{id} [delete]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.DiscordWebhookResponse // @Failure 400 {object} domain.DiscordWebhookResponse
// @Failure 500 {object} domain.DiscordWebhookResponse // @Failure 500 {object} domain.DiscordWebhookResponse
// @Security Bearer // @Security Bearer
func (s *Handler) deleteDiscordWebHook(c echo.Context) error { func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
p := domain.DiscordWebhookResponse{ p := domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -409,13 +409,13 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
} }
// UpdateDiscordWebHook // UpdateDiscordWebHook
// @Summary Updates a valid discord webhook ID based on the body given. // @Summary Updates a valid discord webhook ID based on the body given.
// @Param id path string true "id" // @Param id path string true "id"
// @Tags DiscordWebhook // @Tags DiscordWebhook
// @Router /v1/discord/webhooks/{id} [patch] // @Router /v1/discord/webhooks/{id} [patch]
// @Success 200 {object} domain.DiscordWebhookResponse "OK" // @Success 200 {object} domain.DiscordWebhookResponse "OK"
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
//func (s *Handler) UpdateDiscordWebHook(c echo.Context) error { //func (s *Handler) UpdateDiscordWebHook(c echo.Context) error {
// id, err := strconv.Atoi(c.Param("ID")) // id, err := strconv.Atoi(c.Param("ID"))
// if err != nil { // if err != nil {

View File

@ -8,18 +8,19 @@ import (
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
// ListSources // ListSources
// @Summary Lists the top 50 records // @Summary Lists the top 50 records
// @Param page query string false "page number" // @Param page query string false "page number"
// @Produce application/json // @Produce application/json
// @Tags Source // @Tags Source
// @Router /v1/sources [get] // @Router /v1/sources [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems" // @Failure 400 {object} domain.SourcesResponse "Unable to reach SQL or Data problems"
// @Security Bearer // @Security Bearer
func (s *Handler) listSources(c echo.Context) error { func (s *Handler) listSources(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -52,16 +53,16 @@ func (s *Handler) listSources(c echo.Context) error {
} }
// ListSourcesBySource // ListSourcesBySource
// @Summary Lists the top 50 records based on the name given. Example: reddit // @Summary Lists the top 50 records based on the name given. Example: reddit
// @Param source query string true "Source Name" // @Param source query string true "Source Name"
// @Param page query string false "page number" // @Param page query string false "page number"
// @Produce application/json // @Produce application/json
// @Tags Source // @Tags Source
// @Router /v1/sources/by/source [get] // @Router /v1/sources/by/source [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) listSourcesBySource(c echo.Context) error { func (s *Handler) listSourcesBySource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -100,15 +101,15 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
} }
// GetSource // GetSource
// @Summary Returns a single entity by ID // @Summary Returns a single entity by ID
// @Param id path int true "id" // @Param id path int true "id"
// @Produce application/json // @Produce application/json
// @Tags Source // @Tags Source
// @Router /v1/sources/{id} [get] // @Router /v1/sources/{id} [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) getSource(c echo.Context) error { func (s *Handler) getSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -142,16 +143,16 @@ func (s *Handler) getSource(c echo.Context) error {
} }
// GetSourceByNameAndSource // GetSourceByNameAndSource
// @Summary Returns a single entity by ID // @Summary Returns a single entity by ID
// @Param name query string true "dadjokes" // @Param name query string true "dadjokes"
// @Param source query string true "reddit" // @Param source query string true "reddit"
// @Produce application/json // @Produce application/json
// @Tags Source // @Tags Source
// @Router /v1/sources/by/sourceAndName [get] // @Router /v1/sources/by/sourceAndName [get]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error { func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -187,15 +188,15 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
} }
// NewRedditSource // NewRedditSource
// @Summary Creates a new reddit source to monitor. // @Summary Creates a new reddit source to monitor.
// @Param name query string true "name" // @Param name query string true "name"
// @Param url query string true "url" // @Param url query string true "url"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/reddit [post] // @Router /v1/sources/new/reddit [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newRedditSource(c echo.Context) error { func (s *Handler) newRedditSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -261,15 +262,15 @@ func (s *Handler) newRedditSource(c echo.Context) error {
} }
// NewYoutubeSource // NewYoutubeSource
// @Summary Creates a new youtube source to monitor. // @Summary Creates a new youtube source to monitor.
// @Param name query string true "name" // @Param name query string true "name"
// @Param url query string true "url" // @Param url query string true "url"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/youtube [post] // @Router /v1/sources/new/youtube [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newYoutubeSource(c echo.Context) error { func (s *Handler) newYoutubeSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -334,14 +335,14 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
} }
// NewTwitchSource // NewTwitchSource
// @Summary Creates a new twitch source to monitor. // @Summary Creates a new twitch source to monitor.
// @Param name query string true "name" // @Param name query string true "name"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/twitch [post] // @Router /v1/sources/new/twitch [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newTwitchSource(c echo.Context) error { func (s *Handler) newTwitchSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -396,14 +397,14 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
} }
// NewRssSource // NewRssSource
// @Summary Creates a new rss source to monitor. // @Summary Creates a new rss source to monitor.
// @Param request body domain.NewSourceParamRequest true "body" // @Param request body domain.NewSourceParamRequest true "body"
// @Tags Source // @Tags Source
// @Router /v1/sources/new/rss [post] // @Router /v1/sources/new/rss [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) newRssSource(c echo.Context) error { func (s *Handler) newRssSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -419,7 +420,8 @@ func (s *Handler) newRssSource(c echo.Context) error {
} }
param := domain.NewSourceParamRequest{} param := domain.NewSourceParamRequest{}
err = (&echo.DefaultBinder{}).BindBody(c, &param) err = c.Bind(&param)
//err = (&echo.DefaultBinder{}).BindBody(c, &param)
if err != nil { if err != nil {
p.BaseResponse.Message = err.Error() p.BaseResponse.Message = err.Error()
return c.JSON(http.StatusBadRequest, p) return c.JSON(http.StatusBadRequest, p)
@ -431,8 +433,15 @@ func (s *Handler) newRssSource(c echo.Context) error {
} }
// Check if the record already exists // Check if the record already exists
blankRecord := entity.SourceEntity{}
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name)
if err == nil { if err != nil {
p.IsError = true
return c.JSON(http.StatusInternalServerError, p)
}
// No record was found, but no error returned
if item != blankRecord {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
p.Payload = dto p.Payload = dto
@ -440,6 +449,14 @@ func (s *Handler) newRssSource(c echo.Context) error {
return c.JSON(http.StatusOK, p) 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) tags := fmt.Sprintf("rss, %v, %s", param.Name, param.Tags)
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorRss, param.Name, param.Url, tags, true) rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorRss, param.Name, param.Url, tags, true)
if err != nil { if err != nil {
@ -466,14 +483,14 @@ func (s *Handler) newRssSource(c echo.Context) error {
} }
// DeleteSource // DeleteSource
// @Summary Marks a source as deleted based on its ID value. // @Summary Marks a source as deleted based on its ID value.
// @Param id path int true "id" // @Param id path int true "id"
// @Tags Source // @Tags Source
// @Router /v1/sources/{id} [POST] // @Router /v1/sources/{id} [POST]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) deleteSources(c echo.Context) error { func (s *Handler) deleteSources(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -526,14 +543,14 @@ func (s *Handler) deleteSources(c echo.Context) error {
} }
// DisableSource // DisableSource
// @Summary Disables a source from processing. // @Summary Disables a source from processing.
// @Param id path int true "id" // @Param id path int true "id"
// @Tags Source // @Tags Source
// @Router /v1/sources/{id}/disable [post] // @Router /v1/sources/{id}/disable [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) disableSource(c echo.Context) error { func (s *Handler) disableSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -581,14 +598,14 @@ func (s *Handler) disableSource(c echo.Context) error {
} }
// EnableSource // EnableSource
// @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 Source // @Tags Source
// @Router /v1/sources/{id}/enable [post] // @Router /v1/sources/{id}/enable [post]
// @Success 200 {object} domain.SourcesResponse "ok" // @Success 200 {object} domain.SourcesResponse "ok"
// @Failure 400 {object} domain.SourcesResponse // @Failure 400 {object} domain.SourcesResponse
// @Failure 500 {object} domain.SourcesResponse // @Failure 500 {object} domain.SourcesResponse
// @Security Bearer // @Security Bearer
func (s *Handler) enableSource(c echo.Context) error { func (s *Handler) enableSource(c echo.Context) error {
p := domain.SourcesResponse{ p := domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{

View File

@ -17,15 +17,15 @@ const (
ErrUsernameAlreadyExists = "the requested username already exists" ErrUsernameAlreadyExists = "the requested username already exists"
) )
// @Summary Creates a new user // @Summary Creates a new user
// @Router /v1/users/register [post] // @Router /v1/users/register [post]
// @Param request formData domain.LoginFormRequest true "form" // @Param request formData domain.LoginFormRequest true "form"
// @Accepts x-www-form-urlencoded // @Accepts x-www-form-urlencoded
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 201 {object} domain.BaseResponse // @Success 201 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
func (h *Handler) AuthRegister(c echo.Context) error { func (h *Handler) AuthRegister(c echo.Context) error {
p := domain.BaseResponse{ p := domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -66,15 +66,15 @@ func (h *Handler) AuthRegister(c echo.Context) error {
return c.JSON(http.StatusCreated, p) return c.JSON(http.StatusCreated, p)
} }
// @Summary Logs into the API and returns a bearer token if successful // @Summary Logs into the API and returns a bearer token if successful
// @Router /v1/users/login [post] // @Router /v1/users/login [post]
// @Param request formData domain.LoginFormRequest true "form" // @Param request formData domain.LoginFormRequest true "form"
// @Accepts x-www-form-urlencoded // @Accepts x-www-form-urlencoded
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 200 {object} domain.LoginResponse // @Success 200 {object} domain.LoginResponse
// @Failure 400 {object} domain.LoginResponse // @Failure 400 {object} domain.LoginResponse
// @Failure 500 {object} domain.LoginResponse // @Failure 500 {object} domain.LoginResponse
func (h *Handler) AuthLogin(c echo.Context) error { func (h *Handler) AuthLogin(c echo.Context) error {
p := domain.LoginResponse{ p := domain.LoginResponse{
BaseResponse: domain.BaseResponse{ 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. // This will take collect some information about the requested refresh, validate and then return a new jwt token if approved.
// Register // Register
// @Summary Generates a new token // @Summary Generates a new token
// @Router /v1/users/refresh/token [post] // @Router /v1/users/refresh/token [post]
// @Param request body domain.RefreshTokenRequest true "body" // @Param request body domain.RefreshTokenRequest true "body"
// @Tags Users // @Tags Users
// @Success 200 {object} domain.LoginResponse // @Success 200 {object} domain.LoginResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) RefreshJwtToken(c echo.Context) error { func (h *Handler) RefreshJwtToken(c echo.Context) error {
p := domain.LoginResponse{ p := domain.LoginResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -235,16 +235,16 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error {
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
// @Router /v1/users/scopes/add [post] // @Router /v1/users/scopes/add [post]
// @Param request body domain.UpdateScopesRequest true "body" // @Param request body domain.UpdateScopesRequest true "body"
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) AddScopes(c echo.Context) error { func (h *Handler) AddScopes(c echo.Context) error {
p := domain.BaseResponse{ p := domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -274,16 +274,16 @@ func (h *Handler) AddScopes(c echo.Context) error {
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
// @Router /v1/users/scopes/remove [post] // @Router /v1/users/scopes/remove [post]
// @Param request body domain.UpdateScopesRequest true "body" // @Param request body domain.UpdateScopesRequest true "body"
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) RemoveScopes(c echo.Context) error { func (h *Handler) RemoveScopes(c echo.Context) error {
p := domain.BaseResponse{ p := domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -319,15 +319,15 @@ func (h *Handler) RemoveScopes(c echo.Context) error {
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
// @Summary Revokes the current session token and replaces it with a new one. // @Summary Revokes the current session token and replaces it with a new one.
// @Router /v1/users/refresh/sessionToken [post] // @Router /v1/users/refresh/sessionToken [post]
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) NewSessionToken(c echo.Context) error { func (h *Handler) NewSessionToken(c echo.Context) error {
p := domain.BaseResponse{ p := domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,

View File

@ -121,7 +121,7 @@ func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name s
b.Select("*") b.Select("*")
b.From("Sources").Where( b.From("Sources").Where(
b.Equal("Source", source), b.Equal("Source", source),
b.Equal("Name", name), b.Equal("DisplayName", name),
) )
b.Limit(1) b.Limit(1)
query, args := b.Build() query, args := b.Build()

View File

@ -19,8 +19,13 @@ migrate-dev-down: ## revert sql migrations to dev db
goose -dir "./internal/database/migrations" sqlite3 ./cmd/newsbot.db down goose -dir "./internal/database/migrations" sqlite3 ./cmd/newsbot.db down
swag: ## Generates the swagger documentation with the swag tool swag: ## Generates the swagger documentation with the swag tool
~/go/bin/swag f ~/go/bin/swag f -g cmd/server.go
~/go/bin/swag init -g cmd/server.go ~/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/
gensql: ## Generates SQL code with sqlc install-tools: ## Installs the required tools for this project
sqlc generate 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

View File

@ -0,0 +1,17 @@
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)
}
}

View File

@ -0,0 +1,70 @@
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
}

View File

@ -0,0 +1,14 @@
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()
}
}