From fbed111fbb00a52c19e616efcb43c8b9893754a7 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Mon, 29 Apr 2024 16:49:52 -0700 Subject: [PATCH] cleaned up the old dto and starting to add the internal queue system --- .gitignore | 2 +- cmd/server.go | 12 +- docs/docs.go | 386 --------------------------- docs/swagger.json | 386 --------------------------- docs/swagger.yaml | 251 ----------------- internal/domain/events.go | 9 + internal/handler/v1/handler.go | 23 +- internal/handler/v1/queue.go | 42 ++- internal/handler/v1/subscriptions.go | 2 + internal/services/cron/rss.go | 34 +++ internal/services/cron/scheduler.go | 1 + internal/services/cron/youtube.go | 2 + internal/services/queue.go | 9 +- makefile | 4 +- 14 files changed, 94 insertions(+), 1069 deletions(-) create mode 100644 internal/domain/events.go create mode 100644 internal/services/cron/rss.go diff --git a/.gitignore b/.gitignore index efcc85d..7282efc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ dev.session.sql __debug_bin server -.vscode # Binaries for programs and plugins *.exe @@ -11,6 +10,7 @@ server *.so *.dylib collector +*.db # Test binary, built with `go test -c` *.test diff --git a/cmd/server.go b/cmd/server.go index c028d1d..6e8cb83 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -10,8 +10,7 @@ import ( "github.com/pressly/goose/v3" "git.jamestombleson.com/jtom38/newsbot-api/docs" - "git.jamestombleson.com/jtom38/newsbot-api/internal/database" - "git.jamestombleson.com/jtom38/newsbot-api/internal/handler/v1" + v1 "git.jamestombleson.com/jtom38/newsbot-api/internal/handler/v1" "git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" ) @@ -42,12 +41,15 @@ func main() { panic(err) } - queries := database.New(db) + //queues := services.NewQueues(db) + //queues.RssIndex.Send(ctx, goqite.Message{ + // Body: []byte("hello world"), + //}) - c := cron.NewScheduler(ctx) + c := cron.NewScheduler(ctx, db) c.Start() - server := v1.NewServer(ctx, queries, configs, db) + server := v1.NewServer(ctx, configs, db) fmt.Println("API is online and waiting for requests.") fmt.Printf("API: http://%v:8081/api\r\n", configs.ServerAddress) diff --git a/docs/docs.go b/docs/docs.go index 85bff2f..a628a49 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -449,25 +449,6 @@ const docTemplate = `{ } } }, - "/queue/discord/webhooks": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Queue" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListDiscordWebHooksQueueResults" - } - } - } - } - }, "/settings/{key}": { "get": { "produces": [ @@ -875,167 +856,6 @@ const docTemplate = `{ } } } - }, - "/subscriptions": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - }, - "400": { - "description": "Unable to reach SQL.", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - }, - "500": { - "description": "Failed to process data from SQL.", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - } - } - } - }, - "/subscriptions/by/SourceId": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - } - } - } - }, - "/subscriptions/by/discordId": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - }, - "400": { - "description": "Unable to reach SQL or Data problems", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - }, - "500": { - "description": "Data problems", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - } - } - } - }, - "/subscriptions/details": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 50 entries with full deatils on the source and output.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptionDetails" - } - } - } - } - }, - "/subscriptions/discord/webhook/delete": { - "delete": { - "tags": [ - "Subscription" - ], - "summary": "Removes a Discord WebHook Subscription based on the Subscription ID.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": {} - } - }, - "/subscriptions/discord/webhook/new": { - "post": { - "tags": [ - "Subscription" - ], - "summary": "Creates a new subscription to link a post from a Source to a DiscordWebHook.", - "parameters": [ - { - "type": "string", - "description": "discordWebHookId", - "name": "discordWebHookId", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "sourceId", - "name": "sourceId", - "in": "query", - "required": true - } - ], - "responses": {} - } } }, "definitions": { @@ -1192,212 +1012,6 @@ const docTemplate = `{ } } } - }, - "models.ArticleDetailsDto": { - "type": "object", - "properties": { - "authorImage": { - "type": "string" - }, - "authorName": { - "type": "string" - }, - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "pubdate": { - "type": "string" - }, - "source": { - "$ref": "#/definitions/models.SourceDto" - }, - "tags": { - "type": "array", - "items": { - "type": "string" - } - }, - "thumbnail": { - "type": "string" - }, - "title": { - "type": "string" - }, - "url": { - "type": "string" - }, - "video": { - "type": "string" - }, - "videoHeight": { - "type": "integer" - }, - "videoWidth": { - "type": "integer" - } - } - }, - "models.DiscordQueueDetailsDto": { - "type": "object", - "properties": { - "article": { - "$ref": "#/definitions/models.ArticleDetailsDto" - }, - "id": { - "type": "string" - } - } - }, - "models.DiscordWebHooksDto": { - "type": "object", - "properties": { - "ID": { - "type": "string" - }, - "channel": { - "type": "string" - }, - "enabled": { - "type": "boolean" - }, - "server": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "models.SourceDto": { - "type": "object", - "properties": { - "deleted": { - "type": "boolean" - }, - "enabled": { - "type": "boolean" - }, - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "site": { - "type": "string" - }, - "source": { - "type": "string" - }, - "tags": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - }, - "url": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, - "models.SubscriptionDetailsDto": { - "type": "object", - "properties": { - "discordwebhook": { - "$ref": "#/definitions/models.DiscordWebHooksDto" - }, - "id": { - "type": "string" - }, - "source": { - "$ref": "#/definitions/models.SourceDto" - } - } - }, - "models.SubscriptionDto": { - "type": "object", - "properties": { - "discordwebhookid": { - "type": "string" - }, - "id": { - "type": "string" - }, - "sourceid": { - "type": "string" - } - } - }, - "v1.ApiError": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListDiscordWebHooksQueueResults": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.DiscordQueueDetailsDto" - } - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListSubscriptionDetails": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.SubscriptionDetailsDto" - } - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListSubscriptions": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.SubscriptionDto" - } - }, - "status": { - "type": "integer" - } - } } } }` diff --git a/docs/swagger.json b/docs/swagger.json index b4260d7..485712f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -440,25 +440,6 @@ } } }, - "/queue/discord/webhooks": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Queue" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListDiscordWebHooksQueueResults" - } - } - } - } - }, "/settings/{key}": { "get": { "produces": [ @@ -866,167 +847,6 @@ } } } - }, - "/subscriptions": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - }, - "400": { - "description": "Unable to reach SQL.", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - }, - "500": { - "description": "Failed to process data from SQL.", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - } - } - } - }, - "/subscriptions/by/SourceId": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - } - } - } - }, - "/subscriptions/by/discordId": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 100 entries from the queue to be processed.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptions" - } - }, - "400": { - "description": "Unable to reach SQL or Data problems", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - }, - "500": { - "description": "Data problems", - "schema": { - "$ref": "#/definitions/v1.ApiError" - } - } - } - } - }, - "/subscriptions/details": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Subscription" - ], - "summary": "Returns the top 50 entries with full deatils on the source and output.", - "responses": { - "200": { - "description": "ok", - "schema": { - "$ref": "#/definitions/v1.ListSubscriptionDetails" - } - } - } - } - }, - "/subscriptions/discord/webhook/delete": { - "delete": { - "tags": [ - "Subscription" - ], - "summary": "Removes a Discord WebHook Subscription based on the Subscription ID.", - "parameters": [ - { - "type": "string", - "description": "id", - "name": "id", - "in": "query", - "required": true - } - ], - "responses": {} - } - }, - "/subscriptions/discord/webhook/new": { - "post": { - "tags": [ - "Subscription" - ], - "summary": "Creates a new subscription to link a post from a Source to a DiscordWebHook.", - "parameters": [ - { - "type": "string", - "description": "discordWebHookId", - "name": "discordWebHookId", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "sourceId", - "name": "sourceId", - "in": "query", - "required": true - } - ], - "responses": {} - } } }, "definitions": { @@ -1183,212 +1003,6 @@ } } } - }, - "models.ArticleDetailsDto": { - "type": "object", - "properties": { - "authorImage": { - "type": "string" - }, - "authorName": { - "type": "string" - }, - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "pubdate": { - "type": "string" - }, - "source": { - "$ref": "#/definitions/models.SourceDto" - }, - "tags": { - "type": "array", - "items": { - "type": "string" - } - }, - "thumbnail": { - "type": "string" - }, - "title": { - "type": "string" - }, - "url": { - "type": "string" - }, - "video": { - "type": "string" - }, - "videoHeight": { - "type": "integer" - }, - "videoWidth": { - "type": "integer" - } - } - }, - "models.DiscordQueueDetailsDto": { - "type": "object", - "properties": { - "article": { - "$ref": "#/definitions/models.ArticleDetailsDto" - }, - "id": { - "type": "string" - } - } - }, - "models.DiscordWebHooksDto": { - "type": "object", - "properties": { - "ID": { - "type": "string" - }, - "channel": { - "type": "string" - }, - "enabled": { - "type": "boolean" - }, - "server": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "models.SourceDto": { - "type": "object", - "properties": { - "deleted": { - "type": "boolean" - }, - "enabled": { - "type": "boolean" - }, - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "site": { - "type": "string" - }, - "source": { - "type": "string" - }, - "tags": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - }, - "url": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, - "models.SubscriptionDetailsDto": { - "type": "object", - "properties": { - "discordwebhook": { - "$ref": "#/definitions/models.DiscordWebHooksDto" - }, - "id": { - "type": "string" - }, - "source": { - "$ref": "#/definitions/models.SourceDto" - } - } - }, - "models.SubscriptionDto": { - "type": "object", - "properties": { - "discordwebhookid": { - "type": "string" - }, - "id": { - "type": "string" - }, - "sourceid": { - "type": "string" - } - } - }, - "v1.ApiError": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListDiscordWebHooksQueueResults": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.DiscordQueueDetailsDto" - } - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListSubscriptionDetails": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.SubscriptionDetailsDto" - } - }, - "status": { - "type": "integer" - } - } - }, - "v1.ListSubscriptions": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/models.SubscriptionDto" - } - }, - "status": { - "type": "integer" - } - } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9638e3f..9bf3589 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -102,140 +102,6 @@ definitions: $ref: '#/definitions/domain.SourceDto' type: array type: object - models.ArticleDetailsDto: - properties: - authorImage: - type: string - authorName: - type: string - description: - type: string - id: - type: string - pubdate: - type: string - source: - $ref: '#/definitions/models.SourceDto' - tags: - items: - type: string - type: array - thumbnail: - type: string - title: - type: string - url: - type: string - video: - type: string - videoHeight: - type: integer - videoWidth: - type: integer - type: object - models.DiscordQueueDetailsDto: - properties: - article: - $ref: '#/definitions/models.ArticleDetailsDto' - id: - type: string - type: object - models.DiscordWebHooksDto: - properties: - ID: - type: string - channel: - type: string - enabled: - type: boolean - server: - type: string - url: - type: string - type: object - models.SourceDto: - properties: - deleted: - type: boolean - enabled: - type: boolean - id: - type: string - name: - type: string - site: - type: string - source: - type: string - tags: - items: - type: string - type: array - type: - type: string - url: - type: string - value: - type: string - type: object - models.SubscriptionDetailsDto: - properties: - discordwebhook: - $ref: '#/definitions/models.DiscordWebHooksDto' - id: - type: string - source: - $ref: '#/definitions/models.SourceDto' - type: object - models.SubscriptionDto: - properties: - discordwebhookid: - type: string - id: - type: string - sourceid: - type: string - type: object - v1.ApiError: - properties: - message: - type: string - status: - type: integer - type: object - v1.ListDiscordWebHooksQueueResults: - properties: - message: - type: string - payload: - items: - $ref: '#/definitions/models.DiscordQueueDetailsDto' - type: array - status: - type: integer - type: object - v1.ListSubscriptionDetails: - properties: - message: - type: string - payload: - items: - $ref: '#/definitions/models.SubscriptionDetailsDto' - type: array - status: - type: integer - type: object - v1.ListSubscriptions: - properties: - message: - type: string - payload: - items: - $ref: '#/definitions/models.SubscriptionDto' - type: array - status: - type: integer - type: object info: contact: {} title: NewsBot collector @@ -527,18 +393,6 @@ paths: tags: - Discord - Webhook - /queue/discord/webhooks: - get: - produces: - - application/json - responses: - "200": - description: ok - schema: - $ref: '#/definitions/v1.ListDiscordWebHooksQueueResults' - summary: Returns the top 100 entries from the queue to be processed. - tags: - - Queue /settings/{key}: get: parameters: @@ -807,109 +661,4 @@ paths: summary: Creates a new youtube source to monitor. tags: - Source - /subscriptions: - get: - produces: - - application/json - responses: - "200": - description: ok - schema: - $ref: '#/definitions/v1.ListSubscriptions' - "400": - description: Unable to reach SQL. - schema: - $ref: '#/definitions/v1.ApiError' - "500": - description: Failed to process data from SQL. - schema: - $ref: '#/definitions/v1.ApiError' - summary: Returns the top 100 entries from the queue to be processed. - tags: - - Subscription - /subscriptions/by/SourceId: - get: - parameters: - - description: id - in: query - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: ok - schema: - $ref: '#/definitions/v1.ListSubscriptions' - summary: Returns the top 100 entries from the queue to be processed. - tags: - - Subscription - /subscriptions/by/discordId: - get: - parameters: - - description: id - in: query - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: ok - schema: - $ref: '#/definitions/v1.ListSubscriptions' - "400": - description: Unable to reach SQL or Data problems - schema: - $ref: '#/definitions/v1.ApiError' - "500": - description: Data problems - schema: - $ref: '#/definitions/v1.ApiError' - summary: Returns the top 100 entries from the queue to be processed. - tags: - - Subscription - /subscriptions/details: - get: - produces: - - application/json - responses: - "200": - description: ok - schema: - $ref: '#/definitions/v1.ListSubscriptionDetails' - summary: Returns the top 50 entries with full deatils on the source and output. - tags: - - Subscription - /subscriptions/discord/webhook/delete: - delete: - parameters: - - description: id - in: query - name: id - required: true - type: string - responses: {} - summary: Removes a Discord WebHook Subscription based on the Subscription ID. - tags: - - Subscription - /subscriptions/discord/webhook/new: - post: - parameters: - - description: discordWebHookId - in: query - name: discordWebHookId - required: true - type: string - - description: sourceId - in: query - name: sourceId - required: true - type: string - responses: {} - summary: Creates a new subscription to link a post from a Source to a DiscordWebHook. - tags: - - Subscription swagger: "2.0" diff --git a/internal/domain/events.go b/internal/domain/events.go new file mode 100644 index 0000000..ae3a337 --- /dev/null +++ b/internal/domain/events.go @@ -0,0 +1,9 @@ +package domain + +const ( + QueueRssCollection = "RssCollection" +) + +type RssCollectionEvent struct { + +} diff --git a/internal/handler/v1/handler.go b/internal/handler/v1/handler.go index c510f65..e501237 100644 --- a/internal/handler/v1/handler.go +++ b/internal/handler/v1/handler.go @@ -11,13 +11,12 @@ import ( "git.jamestombleson.com/jtom38/newsbot-api/internal/database" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/services" - "git.jamestombleson.com/jtom38/newsbot-api/internal/services/dto" ) type Handler struct { Router *echo.Echo Db *database.Queries - dto *dto.DtoClient + //dto *dto.DtoClient config services.Configs repo services.RepositoryService } @@ -39,10 +38,10 @@ var ( ErrUnableToConvertToJson string = "Unable to convert to json" ) -func NewServer(ctx context.Context, db *database.Queries, configs services.Configs, conn *sql.DB) *Handler { +func NewServer(ctx context.Context, configs services.Configs, conn *sql.DB) *Handler { s := &Handler{ - Db: db, - dto: dto.NewDtoClient(db), + //Db: db, + //dto: dto.NewDtoClient(db), config: configs, repo: services.NewRepositoryService(conn), } @@ -85,13 +84,13 @@ func NewServer(ctx context.Context, db *database.Queries, configs services.Confi sources.POST("/:ID/disable", s.disableSource) sources.POST("/:ID/enable", s.enableSource) - subs := v1.Group("/subscriptions") - subs.GET("/", s.ListSubscriptions) - subs.GET("/details", s.ListSubscriptionDetails) - subs.GET("/by/discordId", s.GetSubscriptionsByDiscordId) - subs.GET("/by/sourceId", s.GetSubscriptionsBySourceId) - subs.POST("/discord/webhook/new", s.newDiscordWebHookSubscription) - subs.DELETE("/discord/webhook/delete", s.DeleteDiscordWebHookSubscription) + //subs := v1.Group("/subscriptions") + //subs.GET("/", s.ListSubscriptions) + //subs.GET("/details", s.ListSubscriptionDetails) + //subs.GET("/by/discordId", s.GetSubscriptionsByDiscordId) + //subs.GET("/by/sourceId", s.GetSubscriptionsBySourceId) + //subs.POST("/discord/webhook/new", s.newDiscordWebHookSubscription) + //subs.DELETE("/discord/webhook/delete", s.DeleteDiscordWebHookSubscription) return s } diff --git a/internal/handler/v1/queue.go b/internal/handler/v1/queue.go index deadb89..c52b3c3 100644 --- a/internal/handler/v1/queue.go +++ b/internal/handler/v1/queue.go @@ -1,11 +1,7 @@ package v1 import ( - "net/http" - - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models" - "github.com/labstack/echo/v4" ) type ListDiscordWebHooksQueueResults struct { @@ -19,22 +15,22 @@ type ListDiscordWebHooksQueueResults struct { // @Tags Queue // @Router /queue/discord/webhooks [get] // @Success 200 {object} ListDiscordWebHooksQueueResults "ok" -func (s *Handler) ListDiscordWebhookQueue(c echo.Context) error { - p := ListDiscordWebHooksQueueResults{ - ApiStatusModel: ApiStatusModel{ - Message: "OK", - StatusCode: http.StatusOK, - }, - } - - // Get the raw resp from sql - res, err := s.dto.ListDiscordWebhookQueueDetails(c.Request().Context(), 50) - if err != nil { - return c.JSON(http.StatusInternalServerError, domain.BaseResponse{ - Message: err.Error(), - }) - } - - p.Payload = res - return c.JSON(http.StatusOK, p) -} +//func (s *Handler) ListDiscordWebhookQueue(c echo.Context) error { +// p := ListDiscordWebHooksQueueResults{ +// ApiStatusModel: ApiStatusModel{ +// Message: "OK", +// StatusCode: http.StatusOK, +// }, +// } +// +// // Get the raw resp from sql +// res, err := s.dto.ListDiscordWebhookQueueDetails(c.Request().Context(), 50) +// if err != nil { +// return c.JSON(http.StatusInternalServerError, domain.BaseResponse{ +// Message: err.Error(), +// }) +// } +// +// p.Payload = res +// return c.JSON(http.StatusOK, p) +//} diff --git a/internal/handler/v1/subscriptions.go b/internal/handler/v1/subscriptions.go index eff2512..6c32d95 100644 --- a/internal/handler/v1/subscriptions.go +++ b/internal/handler/v1/subscriptions.go @@ -1,5 +1,6 @@ package v1 +/* import ( "context" "encoding/json" @@ -228,3 +229,4 @@ func (s *Handler) DeleteDiscordWebHookSubscription(c echo.Context) error { return c.JSON(http.StatusOK, nil) } +*/ \ No newline at end of file diff --git a/internal/services/cron/rss.go b/internal/services/cron/rss.go new file mode 100644 index 0000000..ecbaade --- /dev/null +++ b/internal/services/cron/rss.go @@ -0,0 +1,34 @@ +package cron + +import ( + "log" + + "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" +) + +func (c *Cron) LoadRssQueue() { + sources, err := c.repo.Sources.ListBySource(*c.ctx, 0, 1000, domain.SourceCollectorRss) + if err != nil { + log.Println(err) + } + + for _, source := range sources { + if !source.Enabled { + continue + } + + + } + +} + +func (c *Cron) ListAllSourceRecords(sourceType string) ([]domain.SourceEntity, error) { + var records []domain.SourceEntity + + sources, err := c.repo.Sources.ListBySource(*c.ctx, 0, 1000, sourceType) + if err != nil { + return records, err + } + + return sources, nil +} diff --git a/internal/services/cron/scheduler.go b/internal/services/cron/scheduler.go index de98b1b..3f0572c 100644 --- a/internal/services/cron/scheduler.go +++ b/internal/services/cron/scheduler.go @@ -17,6 +17,7 @@ type Cron struct { ctx *context.Context timer *cron.Cron repo services.RepositoryService + //queues services } func NewScheduler(ctx context.Context, conn *sql.DB) *Cron { diff --git a/internal/services/cron/youtube.go b/internal/services/cron/youtube.go index 6266e0c..609537c 100644 --- a/internal/services/cron/youtube.go +++ b/internal/services/cron/youtube.go @@ -30,3 +30,5 @@ func (c *Cron) CheckYoutube() { } log.Print("[YouTube] Done!") } + + diff --git a/internal/services/queue.go b/internal/services/queue.go index 80c8c7f..817f5e8 100644 --- a/internal/services/queue.go +++ b/internal/services/queue.go @@ -3,21 +3,24 @@ package services import ( "database/sql" + "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "github.com/maragudk/goqite" ) + + type queues struct { repos RepositoryService - RssIndex goqite.Queue + RssCollection goqite.Queue } func NewQueues(conn *sql.DB) queues { return queues{ repos: NewRepositoryService(conn), - RssIndex: *goqite.New(goqite.NewOpts{ + RssCollection: *goqite.New(goqite.NewOpts{ DB: conn, - Name: "rss", + Name: domain.QueueRssCollection, }), } } diff --git a/makefile b/makefile index c0ccd02..55689f2 100644 --- a/makefile +++ b/makefile @@ -4,8 +4,8 @@ help: ## Shows this help command build: ## builds the application with the current go runtime ~/go/bin/swag f - ~/go/bin/swag i - go build . + ~/go/bin/swag init -g cmd/server.go + go build cmd/server.go docker-build: ## Generates the docker image docker build -t "newsbot.collector.api" .