Compare commits
No commits in common. "43f42d9db0311d91b0e4aae853d5159bafe7e262" and "8fc2e56ad5f00f87d7849209983ac9e3afbeba64" have entirely different histories.
43f42d9db0
...
8fc2e56ad5
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,9 @@ __debug_bin
|
|||||||
server
|
server
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
# hide the swagger files in the repo
|
||||||
|
docs/
|
||||||
|
|
||||||
# Binaries for programs and plugins
|
# Binaries for programs and plugins
|
||||||
*.exe
|
*.exe
|
||||||
*.exe~
|
*.exe~
|
||||||
|
725
docs/docs.go
725
docs/docs.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,107 +1,5 @@
|
|||||||
basePath: /api
|
basePath: /api
|
||||||
definitions:
|
definitions:
|
||||||
domain.ArticleAndSourceModel:
|
|
||||||
properties:
|
|
||||||
article:
|
|
||||||
$ref: '#/definitions/domain.ArticleDto'
|
|
||||||
source:
|
|
||||||
$ref: '#/definitions/domain.SourceDto'
|
|
||||||
type: object
|
|
||||||
domain.ArticleDetailedResponse:
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
payload:
|
|
||||||
$ref: '#/definitions/domain.ArticleAndSourceModel'
|
|
||||||
type: object
|
|
||||||
domain.ArticleDto:
|
|
||||||
properties:
|
|
||||||
authorImage:
|
|
||||||
type: string
|
|
||||||
authorName:
|
|
||||||
type: string
|
|
||||||
description:
|
|
||||||
type: string
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
isVideo:
|
|
||||||
type: boolean
|
|
||||||
pubDate:
|
|
||||||
type: string
|
|
||||||
sourceId:
|
|
||||||
type: integer
|
|
||||||
tags:
|
|
||||||
type: string
|
|
||||||
thumbnail:
|
|
||||||
type: string
|
|
||||||
title:
|
|
||||||
type: string
|
|
||||||
url:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
domain.ArticleResponse:
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
payload:
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/domain.ArticleDto'
|
|
||||||
type: array
|
|
||||||
type: object
|
|
||||||
domain.BaseResponse:
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
domain.DiscordWebHookDto:
|
|
||||||
properties:
|
|
||||||
channel:
|
|
||||||
type: string
|
|
||||||
enabled:
|
|
||||||
type: boolean
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
server:
|
|
||||||
type: string
|
|
||||||
url:
|
|
||||||
description: |-
|
|
||||||
Name string `json:"name"`
|
|
||||||
Key string `json:"key"`
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
domain.DiscordWebhookResponse:
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
payload:
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/domain.DiscordWebHookDto'
|
|
||||||
type: array
|
|
||||||
type: object
|
|
||||||
domain.SourceDto:
|
|
||||||
properties:
|
|
||||||
enabled:
|
|
||||||
type: boolean
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
source:
|
|
||||||
type: string
|
|
||||||
tags:
|
|
||||||
type: string
|
|
||||||
url:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
domain.SourcesResponse:
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
payload:
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/domain.SourceDto'
|
|
||||||
type: array
|
|
||||||
type: object
|
|
||||||
models.ArticleDetailsDto:
|
models.ArticleDetailsDto:
|
||||||
properties:
|
properties:
|
||||||
authorImage:
|
authorImage:
|
||||||
@ -133,6 +31,37 @@ definitions:
|
|||||||
videoWidth:
|
videoWidth:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
models.ArticleDto:
|
||||||
|
properties:
|
||||||
|
authorImage:
|
||||||
|
type: string
|
||||||
|
authorName:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
pubdate:
|
||||||
|
type: string
|
||||||
|
sourceid:
|
||||||
|
type: string
|
||||||
|
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:
|
models.DiscordQueueDetailsDto:
|
||||||
properties:
|
properties:
|
||||||
article:
|
article:
|
||||||
@ -196,14 +125,61 @@ definitions:
|
|||||||
sourceid:
|
sourceid:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
v1.ApiError:
|
routes.ApiError:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
v1.ListDiscordWebHooksQueueResults:
|
routes.ArticleDetailsResult:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
$ref: '#/definitions/models.ArticleDetailsDto'
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.ArticleGetResults:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
$ref: '#/definitions/models.ArticleDto'
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.ArticlesListResults:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/models.ArticleDto'
|
||||||
|
type: array
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.GetDiscordWebhook:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
$ref: '#/definitions/models.DiscordWebHooksDto'
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.GetSource:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
$ref: '#/definitions/models.SourceDto'
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.ListDiscordWebHooksQueueResults:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
@ -214,7 +190,29 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
v1.ListSubscriptionDetails:
|
routes.ListDiscordWebhooks:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/models.DiscordWebHooksDto'
|
||||||
|
type: array
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.ListSources:
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
payload:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/models.SourceDto'
|
||||||
|
type: array
|
||||||
|
status:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
routes.ListSubscriptionDetails:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
@ -225,7 +223,7 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
v1.ListSubscriptions:
|
routes.ListSubscriptions:
|
||||||
properties:
|
properties:
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
@ -254,22 +252,14 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.ArticleResponse'
|
$ref: '#/definitions/routes.ArticlesListResults'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
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
|
||||||
/articles/{ID}:
|
/articles/{ID}:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
- description: int
|
- description: uuid
|
||||||
in: path
|
in: path
|
||||||
name: ID
|
name: ID
|
||||||
required: true
|
required: true
|
||||||
@ -280,22 +270,14 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.ArticleResponse'
|
$ref: '#/definitions/routes.ArticleGetResults'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Returns an article based on defined ID.
|
summary: Returns an article based on defined ID.
|
||||||
tags:
|
tags:
|
||||||
- Articles
|
- Articles
|
||||||
/articles/{ID}/details:
|
/articles/{ID}/details:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
- description: int
|
- description: uuid
|
||||||
in: path
|
in: path
|
||||||
name: ID
|
name: ID
|
||||||
required: true
|
required: true
|
||||||
@ -306,22 +288,14 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.ArticleDetailedResponse'
|
$ref: '#/definitions/routes.ArticleDetailsResult'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Returns an article and source based on defined ID.
|
summary: Returns an article and source based on defined ID.
|
||||||
tags:
|
tags:
|
||||||
- Articles
|
- Articles
|
||||||
/articles/by/sourceid:
|
/articles/by/sourceid:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
- description: source id
|
- description: Source ID UUID
|
||||||
in: query
|
in: query
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
@ -336,15 +310,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.ArticleResponse'
|
$ref: '#/definitions/routes.ArticlesListResults'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Finds the articles based on the SourceID provided. Returns the top
|
summary: Finds the articles based on the SourceID provided. Returns the top
|
||||||
25.
|
25.
|
||||||
tags:
|
tags:
|
||||||
@ -353,20 +319,8 @@ paths:
|
|||||||
get:
|
get:
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
summary: Returns the top 100 entries from the queue to be processed.
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Returns the top 100
|
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
- Webhook
|
- Webhook
|
||||||
@ -378,19 +332,7 @@ paths:
|
|||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Deletes a record by ID.
|
summary: Deletes a record by ID.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
@ -402,20 +344,8 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Disables a Webhook from being used.
|
summary: Disables a Webhook from being used.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
@ -427,7 +357,7 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
responses: {}
|
responses: {}
|
||||||
summary: Enables a source to continue processing.
|
summary: Enables a source to continue processing.
|
||||||
tags:
|
tags:
|
||||||
@ -440,26 +370,30 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
$ref: '#/definitions/routes.GetDiscordWebhook'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Returns the top 100 entries from the queue to be processed.
|
summary: Returns the top 100 entries from the queue to be processed.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
- Webhook
|
- Webhook
|
||||||
|
patch:
|
||||||
|
parameters:
|
||||||
|
- description: id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses: {}
|
||||||
|
summary: Updates a valid discord webhook ID based on the body given.
|
||||||
|
tags:
|
||||||
|
- Discord
|
||||||
|
- Webhook
|
||||||
/discord/webhooks/by/serverAndChannel:
|
/discord/webhooks/by/serverAndChannel:
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
@ -479,15 +413,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
$ref: '#/definitions/routes.ListDiscordWebhooks'
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Returns all the known web hooks based on the Server and Channel given.
|
summary: Returns all the known web hooks based on the Server and Channel given.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
@ -510,19 +436,7 @@ paths:
|
|||||||
name: channel
|
name: channel
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.DiscordWebhookResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
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.
|
||||||
tags:
|
tags:
|
||||||
- Discord
|
- Discord
|
||||||
@ -535,42 +449,23 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ListDiscordWebHooksQueueResults'
|
$ref: '#/definitions/routes.ListDiscordWebHooksQueueResults'
|
||||||
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:
|
||||||
- Queue
|
- Queue
|
||||||
/settings/{key}:
|
|
||||||
get:
|
|
||||||
parameters:
|
|
||||||
- description: Settings Key value
|
|
||||||
in: path
|
|
||||||
name: key
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses: {}
|
|
||||||
summary: Returns a object based on the Key that was given.
|
|
||||||
tags:
|
|
||||||
- Settings
|
|
||||||
/sources:
|
/sources:
|
||||||
get:
|
get:
|
||||||
parameters:
|
|
||||||
- description: page number
|
|
||||||
in: query
|
|
||||||
name: page
|
|
||||||
type: string
|
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
$ref: '#/definitions/routes.ListSources'
|
||||||
"400":
|
"400":
|
||||||
description: Unable to reach SQL or Data problems
|
description: Unable to reach SQL or Data problems
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
summary: Lists the top 50 records
|
summary: Lists the top 50 records
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -581,22 +476,26 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
$ref: '#/definitions/routes.GetSource'
|
||||||
|
"204":
|
||||||
|
description: No record found.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Unable to query SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Failed to process data from SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
summary: Returns a single entity by ID
|
summary: Returns a single entity by ID
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -618,20 +517,8 @@ paths:
|
|||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: ok
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Disables a source from processing.
|
summary: Disables a source from processing.
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -643,19 +530,7 @@ paths:
|
|||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: ok
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Enables a source to continue processing.
|
summary: Enables a source to continue processing.
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -667,25 +542,21 @@ paths:
|
|||||||
name: source
|
name: source
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- description: page number
|
|
||||||
in: query
|
|
||||||
name: page
|
|
||||||
type: string
|
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
$ref: '#/definitions/routes.ListSources'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Unable to query SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Problems with data.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
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'
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -708,15 +579,19 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
$ref: '#/definitions/routes.GetSource'
|
||||||
|
"204":
|
||||||
|
description: No record found.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Unable to query SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Failed to process data from SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
summary: Returns a single entity by ID
|
summary: Returns a single entity by ID
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
@ -733,51 +608,10 @@ paths:
|
|||||||
name: url
|
name: url
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses: {}
|
||||||
"200":
|
|
||||||
description: ok
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Creates a new reddit source to monitor.
|
summary: Creates a new reddit source to monitor.
|
||||||
tags:
|
tags:
|
||||||
- Source
|
- Source
|
||||||
/sources/new/rss:
|
|
||||||
post:
|
|
||||||
parameters:
|
|
||||||
- description: Site Name
|
|
||||||
in: query
|
|
||||||
name: name
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: RSS Url
|
|
||||||
in: query
|
|
||||||
name: url
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: ok
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.SourcesResponse'
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/domain.BaseResponse'
|
|
||||||
summary: Creates a new rss source to monitor.
|
|
||||||
tags:
|
|
||||||
- Source
|
|
||||||
/sources/new/twitch:
|
/sources/new/twitch:
|
||||||
post:
|
post:
|
||||||
parameters:
|
parameters:
|
||||||
@ -815,15 +649,15 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ListSubscriptions'
|
$ref: '#/definitions/routes.ListSubscriptions'
|
||||||
"400":
|
"400":
|
||||||
description: Unable to reach SQL.
|
description: Unable to reach SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ApiError'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"500":
|
"500":
|
||||||
description: Failed to process data from SQL.
|
description: Failed to process data from SQL.
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ApiError'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
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:
|
||||||
- Subscription
|
- Subscription
|
||||||
@ -841,7 +675,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ListSubscriptions'
|
$ref: '#/definitions/routes.ListSubscriptions'
|
||||||
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:
|
||||||
- Subscription
|
- Subscription
|
||||||
@ -859,15 +693,15 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ListSubscriptions'
|
$ref: '#/definitions/routes.ListSubscriptions'
|
||||||
"400":
|
"400":
|
||||||
description: Unable to reach SQL or Data problems
|
description: Unable to reach SQL or Data problems
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ApiError'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
"500":
|
"500":
|
||||||
description: Data problems
|
description: Data problems
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ApiError'
|
$ref: '#/definitions/routes.ApiError'
|
||||||
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:
|
||||||
- Subscription
|
- Subscription
|
||||||
@ -879,7 +713,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: ok
|
description: ok
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.ListSubscriptionDetails'
|
$ref: '#/definitions/routes.ListSubscriptionDetails'
|
||||||
summary: Returns the top 50 entries with full deatils on the source and output.
|
summary: Returns the top 50 entries with full deatils on the source and output.
|
||||||
tags:
|
tags:
|
||||||
- Subscription
|
- Subscription
|
||||||
|
@ -23,9 +23,9 @@ type DiscordQueueDto struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DiscordWebHookDto struct {
|
type DiscordWebHookDto struct {
|
||||||
ID int64 `json:"id"`
|
ID uint `json:"id"`
|
||||||
//Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
//Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Server string `json:"server"`
|
Server string `json:"server"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
|
@ -35,6 +35,8 @@ type DiscordWebHookEntity struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt time.Time
|
DeletedAt time.Time
|
||||||
|
//Name string
|
||||||
|
//Key string
|
||||||
Url string
|
Url string
|
||||||
Server string
|
Server string
|
||||||
Channel string
|
Channel string
|
||||||
|
@ -15,7 +15,7 @@ type ArticleAndSourceModel struct {
|
|||||||
Source SourceDto `json:"source"`
|
Source SourceDto `json:"source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArticleDetailedResponse struct {
|
type ArticleDetailResponse struct {
|
||||||
BaseResponse
|
BaseResponse
|
||||||
Payload ArticleAndSourceModel `json:"payload"`
|
Payload ArticleAndSourceModel `json:"payload"`
|
||||||
}
|
}
|
||||||
@ -24,8 +24,3 @@ type DiscordWebhookResponse struct {
|
|||||||
BaseResponse
|
BaseResponse
|
||||||
Payload []DiscordWebHookDto `json:"payload"`
|
Payload []DiscordWebHookDto `json:"payload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SourcesResponse struct {
|
|
||||||
BaseResponse
|
|
||||||
Payload []SourceDto `json:"payload"`
|
|
||||||
}
|
|
@ -45,7 +45,7 @@ func (s *Handler) listArticles(c echo.Context) error {
|
|||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Articles
|
// @Tags Articles
|
||||||
// @Router /articles/{ID} [get]
|
// @Router /articles/{ID} [get]
|
||||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
// @Success 200 {object} ArticleGetResults "OK"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 400 {object} domain.BaseResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.BaseResponse
|
||||||
func (s *Handler) getArticle(c echo.Context) error {
|
func (s *Handler) getArticle(c echo.Context) error {
|
||||||
@ -79,11 +79,11 @@ func (s *Handler) getArticle(c echo.Context) error {
|
|||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Articles
|
// @Tags Articles
|
||||||
// @Router /articles/{ID}/details [get]
|
// @Router /articles/{ID}/details [get]
|
||||||
// @Success 200 {object} domain.ArticleDetailedResponse "OK"
|
// @Success 200 {object} ArticleDetailsResult "OK"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 400 {object} domain.BaseResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.BaseResponse
|
||||||
func (s *Handler) getArticleDetails(c echo.Context) error {
|
func (s *Handler) getArticleDetails(c echo.Context) error {
|
||||||
p := domain.ArticleDetailedResponse{
|
p := domain.ArticleDetailResponse{
|
||||||
BaseResponse: domain.BaseResponse{
|
BaseResponse: domain.BaseResponse{
|
||||||
Message: ResponseMessageSuccess,
|
Message: ResponseMessageSuccess,
|
||||||
},
|
},
|
||||||
@ -115,12 +115,12 @@ 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 query string true
|
||||||
// @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 /articles/by/sourceid [get]
|
// @Router /articles/by/sourceid [get]
|
||||||
// @Success 200 {object} domain.ArticleResponse "OK"
|
// @Success 200 {object} ArticlesListResults "OK"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 400 {object} domain.BaseResponse
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} domain.BaseResponse
|
||||||
func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
|
func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
|
||||||
|
@ -1,66 +1,84 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/services"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ListDiscordWebhooks struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload []models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDiscordWebhook struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
// ListDiscordWebhooks
|
// ListDiscordWebhooks
|
||||||
// @Summary Returns the top 100
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks [get]
|
// @Router /discord/webhooks [get]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
|
func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
|
||||||
p := domain.DiscordWebhookResponse{
|
p := ListDiscordWebhooks{
|
||||||
BaseResponse: domain.BaseResponse{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: ResponseMessageSuccess,
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.repo.DiscordWebHooks.ListByServerName(c.Request().Context(), "")
|
res, err := s.dto.ListDiscordWebHooks(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err)
|
return c.JSON(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
p.Payload = services.DiscordWebhooksToDto(res)
|
p.Payload = res
|
||||||
return c.JSON(http.StatusOK, p)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id} [get]
|
// @Router /discord/webhooks/{id} [get]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
// @Success 200 {object} GetDiscordWebhook "OK"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
||||||
p := domain.DiscordWebhookResponse{
|
p := GetDiscordWebhook{
|
||||||
BaseResponse: domain.BaseResponse{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: ResponseMessageSuccess,
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
_id := c.Param("ID")
|
||||||
if err != nil {
|
if _id == "" {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: ErrIdValueMissing,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
uuid, err := uuid.Parse(_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: ErrUnableToParseId,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
dtos = append(dtos, services.DiscordWebhookToDto(res))
|
res, err := s.dto.GetDiscordWebhook(c.Request().Context(), uuid)
|
||||||
p.Payload = dtos
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: ErrNoRecordFound,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
p.Payload = res
|
||||||
return c.JSON(http.StatusOK, p)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,32 +89,37 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
|||||||
// @Param channel query string true "memes"
|
// @Param channel query string true "memes"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/by/serverAndChannel [get]
|
// @Router /discord/webhooks/by/serverAndChannel [get]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
// @Success 200 {object} ListDiscordWebhooks "OK"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
||||||
p := domain.DiscordWebhookResponse{
|
p := ListDiscordWebhooks{
|
||||||
BaseResponse: domain.BaseResponse{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: ResponseMessageSuccess,
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_server := c.QueryParam("server")
|
_server := c.QueryParam("server")
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
s.WriteMessage(c, "server was not defined", http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: ErrIdValueMissing,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_channel := c.QueryParam("channel")
|
_channel := c.QueryParam("channel")
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
s.WriteMessage(c, "channel was not defined", http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: fmt.Sprintf("%s channel", ErrParameterMissing),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.repo.DiscordWebHooks.ListByServerAndChannel(c.Request().Context(), _server, _channel)
|
res, err := s.dto.GetDiscordWebHookByServerAndChannel(c.Request().Context(), _server, _channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = services.DiscordWebhooksToDto(res)
|
p.Payload = res
|
||||||
return c.JSON(http.StatusOK, p)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,9 +130,6 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
|||||||
// @Param channel query string true "Channel name"
|
// @Param channel query string true "Channel name"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/new [post]
|
// @Router /discord/webhooks/new [post]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
||||||
_url := c.QueryParam("url")
|
_url := c.QueryParam("url")
|
||||||
_server := c.QueryParam("server")
|
_server := c.QueryParam("server")
|
||||||
@ -135,42 +155,26 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
|||||||
Message: "channel is missing",
|
Message: "channel is missing",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
params := database.CreateDiscordWebHookParams{
|
||||||
rows, err := s.repo.DiscordWebHooks.Create(c.Request().Context(), _url, _server, _channel, true)
|
ID: uuid.New(),
|
||||||
if err != nil {
|
Url: _url,
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
Server: _server,
|
||||||
|
Channel: _channel,
|
||||||
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
s.Db.CreateDiscordWebHook(c.Request().Context(), params)
|
||||||
|
|
||||||
if rows != 1 {
|
return c.JSON(http.StatusOK, params)
|
||||||
s.WriteMessage(c, "data was not written to database", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.DiscordWebHooks.GetByUrl(c.Request().Context(), _url)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
dtos = append(dtos, services.DiscordWebhookToDto(item))
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{ID}/disable [post]
|
// @Router /discord/webhooks/{ID}/disable [post]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
id := c.Param("ID")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
@ -178,76 +182,45 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
_, err = s.Db.GetDiscordWebHooksByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// flip the it
|
err = s.Db.DisableDiscordWebHook(c.Request().Context(), uuid)
|
||||||
updated, err := s.repo.DiscordWebHooks.Disable(c.Request().Context(), int64(id))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
// make sure we got a row updated
|
|
||||||
if updated != 1 {
|
|
||||||
s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
dtos = append(dtos, services.DiscordWebhookToDto(item))
|
|
||||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{ID}/enable [post]
|
// @Router /discord/webhooks/{ID}/enable [post]
|
||||||
func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
id := c.Param("ID")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
_, err = s.Db.GetDiscordWebHooksByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, err := s.repo.DiscordWebHooks.Enable(c.Request().Context(), int64(id))
|
err = s.Db.EnableDiscordWebHook(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
if updated != 1 {
|
|
||||||
s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
dtos = append(dtos, services.DiscordWebhookToDto(item))
|
|
||||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteDiscordWebHook
|
// DeleteDiscordWebHook
|
||||||
@ -255,44 +228,28 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
|||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{ID} [delete]
|
// @Router /discord/webhooks/{ID} [delete]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
//var item model.Sources = model.Sources{}
|
||||||
|
|
||||||
|
id := c.Param("ID")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, err.Error())
|
return c.JSON(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
_, err = s.Db.GetDiscordQueueByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soft delete the record
|
// Delete the record
|
||||||
updated, err := s.repo.DiscordWebHooks.SoftDelete(c.Request().Context(), int64(id))
|
err = s.Db.DeleteDiscordWebHooks(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated != 1 {
|
return nil
|
||||||
s.WriteMessage(c, "unexpected number of updates found", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
dtos = append(dtos, services.DiscordWebhookToDto(item))
|
|
||||||
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
Payload: dtos,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateDiscordWebHook
|
// UpdateDiscordWebHook
|
||||||
@ -300,31 +257,19 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
|
|||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Discord, Webhook
|
// @Tags Discord, Webhook
|
||||||
// @Router /discord/webhooks/{id} [patch]
|
// @Router /discord/webhooks/{id} [patch]
|
||||||
// @Success 200 {object} domain.DiscordWebhookResponse "OK"
|
func (s *Handler) UpdateDiscordWebHook(c echo.Context) error {
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
id := c.Param("ID")
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
//func (s *Handler) UpdateDiscordWebHook(c echo.Context) error {
|
uuid, err := uuid.Parse(id)
|
||||||
// id, err := strconv.Atoi(c.Param("ID"))
|
if err != nil {
|
||||||
// if err != nil {
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
// return c.JSON(http.StatusInternalServerError, err.Error())
|
}
|
||||||
// }
|
|
||||||
//
|
// Check to make sure we can find the record
|
||||||
// // Check to make sure we can find the record
|
_, err = s.Db.GetDiscordQueueByID(c.Request().Context(), uuid)
|
||||||
// _, err = s.repo.DiscordWebHooks.GetById(c.Request().Context(), int64(id))
|
if err != nil {
|
||||||
// if err != nil {
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
// return c.JSON(http.StatusInternalServerError, err.Error())
|
}
|
||||||
// }
|
|
||||||
//
|
return nil
|
||||||
// // Soft delete the record
|
}
|
||||||
// updated, err := s.repo.DiscordWebHooks(c.Request().Context(), int64(id))
|
|
||||||
// if err != nil {
|
|
||||||
// return c.JSON(http.StatusInternalServerError, err.Error())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _, err = s.Db.GetDiscordQueueByID(c.Request().Context(), uuid)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.JSON(http.StatusInternalServerError, err.Error())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
//}
|
|
||||||
|
@ -23,11 +23,14 @@ type Handler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrParameterIdMissing = "The requested parameter ID was not found."
|
HeaderContentType = "Content-Type"
|
||||||
ErrParameterMissing = "The requested parameter was not found found:"
|
|
||||||
ErrUnableToParseId = "Unable to parse the requested ID"
|
//ApplicationJson = "application/json"
|
||||||
ErrRecordMissing = "The requested record was not found"
|
|
||||||
ErrFailedToCreateRecord = "The record was not created due to a database problem"
|
ErrParameterIdMissing = "The requested parameter ID was not found."
|
||||||
|
ErrParameterMissing = "The requested parameter was found found:"
|
||||||
|
ErrUnableToParseId = "Unable to parse the requested ID."
|
||||||
|
ErrRecordMissing = "The requested record was not found"
|
||||||
|
|
||||||
ResponseMessageSuccess = "Success"
|
ResponseMessageSuccess = "Success"
|
||||||
)
|
)
|
||||||
@ -57,14 +60,14 @@ func NewServer(ctx context.Context, db *database.Queries, configs services.Confi
|
|||||||
articles.GET("/:id/details", s.getArticleDetails)
|
articles.GET("/:id/details", s.getArticleDetails)
|
||||||
articles.GET("/by/source/:id", s.ListArticlesBySourceId)
|
articles.GET("/by/source/:id", s.ListArticlesBySourceId)
|
||||||
|
|
||||||
//dwh := v1.Group("/discord/webhooks")
|
dwh := v1.Group("/discord/webhooks")
|
||||||
//dwh.GET("/", s.ListDiscordWebHooks)
|
dwh.GET("/", s.ListDiscordWebHooks)
|
||||||
//dwh.POST("/new", s.NewDiscordWebHook)
|
dwh.POST("/new", s.NewDiscordWebHook)
|
||||||
//dwh.GET("/by/serverAndChannel", s.GetDiscordWebHooksByServerAndChannel)
|
dwh.GET("/by/serverAndChannel", s.GetDiscordWebHooksByServerAndChannel)
|
||||||
//dwh.GET("/:ID", s.GetDiscordWebHooksById)
|
dwh.GET("/:ID", s.GetDiscordWebHooksById)
|
||||||
//dwh.DELETE("/:ID", s.deleteDiscordWebHook)
|
dwh.DELETE("/:ID", s.deleteDiscordWebHook)
|
||||||
//dwh.POST("/:ID/disable", s.disableDiscordWebHook)
|
dwh.POST("/:ID/disable", s.disableDiscordWebHook)
|
||||||
//dwh.POST("/:ID/enable", s.enableDiscordWebHook)
|
dwh.POST("/:ID/enable", s.enableDiscordWebHook)
|
||||||
|
|
||||||
//queue := v1.Group("/queue")
|
//queue := v1.Group("/queue")
|
||||||
//queue.GET("/discord/webhooks", s.ListDiscordWebhookQueue) // TODO this needs to be reworked
|
//queue.GET("/discord/webhooks", s.ListDiscordWebhookQueue) // TODO this needs to be reworked
|
||||||
@ -76,11 +79,11 @@ func NewServer(ctx context.Context, db *database.Queries, configs services.Confi
|
|||||||
sources.GET("/", s.listSources)
|
sources.GET("/", s.listSources)
|
||||||
sources.GET("/by/source", s.listSourcesBySource)
|
sources.GET("/by/source", s.listSourcesBySource)
|
||||||
sources.GET("/by/sourceAndName", s.GetSourceBySourceAndName)
|
sources.GET("/by/sourceAndName", s.GetSourceBySourceAndName)
|
||||||
//sources.POST("/new/reddit", s.newRedditSource)
|
sources.POST("/new/reddit", s.newRedditSource)
|
||||||
//sources.POST("/new/youtube", s.newYoutubeSource)
|
sources.POST("/new/youtube", s.newYoutubeSource)
|
||||||
//sources.POST("/new/twitch", s.newTwitchSource)
|
sources.POST("/new/twitch", s.newTwitchSource)
|
||||||
sources.POST("/new/rss", s.newRssSource)
|
|
||||||
sources.GET("/:ID/", s.getSource)
|
sources.GET("/:ID/", s.getSources)
|
||||||
sources.DELETE("/:ID/", s.deleteSources)
|
sources.DELETE("/:ID/", s.deleteSources)
|
||||||
sources.POST("/:ID/disable", s.disableSource)
|
sources.POST("/:ID/disable", s.disableSource)
|
||||||
sources.POST("/:ID/enable", s.enableSource)
|
sources.POST("/:ID/enable", s.enableSource)
|
||||||
|
1
internal/handler/v1/root_test.go
Normal file
1
internal/handler/v1/root_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package v1_test
|
@ -5,13 +5,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/services"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -28,105 +26,115 @@ type GetSource struct {
|
|||||||
|
|
||||||
// ListSources
|
// ListSources
|
||||||
// @Summary Lists the top 50 records
|
// @Summary Lists the top 50 records
|
||||||
// @Param page query string false "page number"
|
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources [get]
|
// @Router /sources [get]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
// @Success 200 {object} ListSources "ok"
|
||||||
// @Failure 400 {object} domain.BaseResponse "Unable to reach SQL or Data problems"
|
// @Failure 400 {object} domain.BaseResponse "Unable to reach SQL or Data problems"
|
||||||
func (s *Handler) listSources(c echo.Context) error {
|
func (s *Handler) listSources(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse {
|
//TODO Add top?
|
||||||
BaseResponse: domain.BaseResponse{
|
/*
|
||||||
Message: ResponseMessageSuccess,
|
top := chi.URLParam(r, "top")
|
||||||
|
topInt, err := strconv.ParseInt(top, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
res, err := s.Db.ListSources(r.Context(), int32(topInt))
|
||||||
|
*/
|
||||||
|
|
||||||
|
p := ListSources{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
Message: "OK",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
|
||||||
if err != nil {
|
|
||||||
page = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default way of showing all sources
|
// Default way of showing all sources
|
||||||
items, err := s.repo.Sources.List(c.Request().Context(), page, 25)
|
items, err := s.dto.ListSources(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Payload = services.SourcesToDto(items)
|
p.Payload = items
|
||||||
return c.JSON(http.StatusOK, resp)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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"
|
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/by/source [get]
|
// @Router /sources/by/source [get]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
// @Success 200 {object} ListSources "ok"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 400 {object} ApiError "Unable to query SQL."
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 500 {object} ApiError "Problems with data."
|
||||||
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
func (s *Handler) listSourcesBySource(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse{
|
//TODO Add top?
|
||||||
BaseResponse: domain.BaseResponse{
|
/*
|
||||||
Message: ResponseMessageSuccess,
|
top := chi.URLParam(r, "top")
|
||||||
|
topInt, err := strconv.ParseInt(top, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
res, err := s.Db.ListSources(r.Context(), int32(topInt))
|
||||||
|
*/
|
||||||
|
|
||||||
|
p := ListSources{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
Message: "OK",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
source := c.QueryParam("source")
|
source := c.QueryParam("source")
|
||||||
if source == "" {
|
|
||||||
s.WriteMessage(c, fmt.Sprintf("%s source", ErrParameterMissing), http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
page, err := strconv.Atoi(c.QueryParam("page"))
|
|
||||||
if err != nil {
|
|
||||||
page = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shows the list by Sources.source
|
// Shows the list by Sources.source
|
||||||
items, err := s.repo.Sources.ListBySource(c.Request().Context(), page, 25, source)
|
res, err := s.dto.ListSourcesBySource(c.Request().Context(), source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Payload = services.SourcesToDto(items)
|
p.Payload = res
|
||||||
return c.JSON(http.StatusOK, resp)
|
return c.JSON(http.StatusOK, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSource
|
// GetSource
|
||||||
// @Summary Returns a single entity by ID
|
// @Summary Returns a single entity by ID
|
||||||
// @Param id path int true "uuid"
|
// @Param id path string true "uuid"
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/{id} [get]
|
// @Router /sources/{id} [get]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
// @Success 200 {object} GetSource "ok"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 204 {object} ApiError "No record found."
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 400 {object} ApiError "Unable to query SQL."
|
||||||
func (s *Handler) getSource(c echo.Context) error {
|
// @Failure 500 {object} ApiError "Failed to process data from SQL."
|
||||||
resp := domain.SourcesResponse{
|
func (s *Handler) getSources(c echo.Context) error {
|
||||||
BaseResponse: domain.BaseResponse{
|
payload := GetSource{
|
||||||
Message: ResponseMessageSuccess,
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
id := c.Param("ID")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrUnableToParseId,
|
Message: ErrUnableToParseId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
res, err := s.dto.GetSourceById(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: ErrNoRecordFound,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
payload.Payload = res
|
||||||
dto = append(dto, services.SourceToDto(item))
|
return c.JSON(http.StatusOK, payload)
|
||||||
resp.Payload = dto
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourceByNameAndSource
|
// GetSourceByNameAndSource
|
||||||
@ -136,13 +144,15 @@ func (s *Handler) getSource(c echo.Context) error {
|
|||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/by/sourceAndName [get]
|
// @Router /sources/by/sourceAndName [get]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
// @Success 200 {object} GetSource "ok"
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
// @Failure 204 {object} ApiError "No record found."
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
// @Failure 400 {object} ApiError "Unable to query SQL."
|
||||||
|
// @Failure 500 {object} ApiError "Failed to process data from SQL."
|
||||||
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse{
|
p := GetSource{
|
||||||
BaseResponse: domain.BaseResponse{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: ResponseMessageSuccess,
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,15 +164,25 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), param.Source, param.Name)
|
//name := c.QueryParam("name")
|
||||||
|
//if name == "" {
|
||||||
|
// s.WriteError(w, "Parameter 'name' was missing in the query.", http.StatusInternalServerError)
|
||||||
|
// return c.JSON(http.bad)
|
||||||
|
//}
|
||||||
|
|
||||||
|
//source := query["source"][0]
|
||||||
|
//if source == "" {
|
||||||
|
// s.WriteError(w, "The parameter 'source' was missing in the query.", http.StatusInternalServerError)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
|
item, err := s.dto.GetSourceByNameAndSource(c.Request().Context(), param.Name, param.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err.Error())
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
p.Payload = item
|
||||||
dto = append(dto, services.SourceToDto(item))
|
return c.JSON(http.StatusOK, p)
|
||||||
resp.Payload = dto
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedditSource
|
// NewRedditSource
|
||||||
@ -171,16 +191,7 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
|||||||
// @Param url query string true "url"
|
// @Param url query string true "url"
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/new/reddit [post]
|
// @Router /sources/new/reddit [post]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) newRedditSource(c echo.Context) error {
|
func (s *Handler) newRedditSource(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err := c.Bind(¶m)
|
err := c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,6 +199,10 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
|||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
//query := r.URL.Query()
|
||||||
|
//_name := query["name"][0]
|
||||||
|
//_url := query["url"][0]
|
||||||
|
//_tags := query["tags"][0]
|
||||||
|
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
@ -200,25 +215,40 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := fmt.Sprintf("twitch, %v, %s", param.Name, param.Tags)
|
/*
|
||||||
rows, err := s.repo.Sources.Create(c.Request().Context(), domain.SourceCollectorReddit, param.Name, param.Url, tags, true)
|
var tags string
|
||||||
|
if _tags == "" {
|
||||||
|
tags = fmt.Sprintf("twitch, %v", _name)
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
tags := fmt.Sprintf("twitch, %v", param.Name)
|
||||||
|
|
||||||
|
params := database.CreateSourceParams{
|
||||||
|
ID: uuid.New(),
|
||||||
|
Site: "reddit",
|
||||||
|
Name: param.Name,
|
||||||
|
Source: "reddit",
|
||||||
|
Type: "feed",
|
||||||
|
Enabled: true,
|
||||||
|
Url: param.Url,
|
||||||
|
Tags: tags,
|
||||||
|
}
|
||||||
|
err = s.Db.CreateSource(c.Request().Context(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
//s.WriteJson(w, ¶ms)
|
||||||
|
|
||||||
if rows != 1 {
|
bJson, err := json.Marshal(¶ms)
|
||||||
s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorReddit, param.Name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
return c.JSON(http.StatusOK, bJson)
|
||||||
dto = append(dto, services.SourceToDto(item))
|
|
||||||
resp.Payload = dto
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewYoutubeSource
|
// NewYoutubeSource
|
||||||
@ -332,57 +362,6 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusOK, bJson)
|
return c.JSON(http.StatusOK, bJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRssSource
|
|
||||||
// @Summary Creates a new rss source to monitor.
|
|
||||||
// @Param name query string true "Site Name"
|
|
||||||
// @Param url query string true "RSS Url"
|
|
||||||
// @Tags Source
|
|
||||||
// @Router /sources/new/rss [post]
|
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) newRssSource(c echo.Context) error {
|
|
||||||
resp := domain.SourcesResponse{
|
|
||||||
BaseResponse: domain.BaseResponse{
|
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var param domain.NewSourceParamRequest
|
|
||||||
err := c.Bind(¶m)
|
|
||||||
if err != nil {
|
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
|
||||||
Message: err.Error(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if param.Url == "" {
|
|
||||||
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
|
||||||
Message: "Url is missing a value",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rows != 1 {
|
|
||||||
s.WriteMessage(c, ErrFailedToCreateRecord, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorRss, param.Name)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
|
||||||
dto = append(dto, services.SourceToDto(item))
|
|
||||||
resp.Payload = dto
|
|
||||||
return c.JSON(http.StatusOK, resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 string true "id"
|
// @Param id path string true "id"
|
||||||
@ -430,44 +409,46 @@ 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 string true "id"
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/{id}/disable [post]
|
// @Router /sources/{id}/disable [post]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) disableSource(c echo.Context) error {
|
func (s *Handler) disableSource(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse {
|
id := c.Param("ID")
|
||||||
BaseResponse: domain.BaseResponse{
|
uuid, err := uuid.Parse(id)
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.repo.Sources.Disable(c.Request().Context(), int64(id))
|
err = s.Db.DisableSource(context.Background(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
p := ApiStatusModel{
|
||||||
if err != nil {
|
Message: "OK",
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
StatusCode: http.StatusOK,
|
||||||
}
|
}
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
b, err := json.Marshal(p)
|
||||||
dto = append(dto, services.SourceToDto(item))
|
if err != nil {
|
||||||
resp.Payload = dto
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
return c.JSON(http.StatusOK, resp)
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableSource
|
// EnableSource
|
||||||
@ -475,39 +456,39 @@ func (s *Handler) disableSource(c echo.Context) error {
|
|||||||
// @Param id path string true "id"
|
// @Param id path string true "id"
|
||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources/{id}/enable [post]
|
// @Router /sources/{id}/enable [post]
|
||||||
// @Success 200 {object} domain.SourcesResponse "ok"
|
|
||||||
// @Failure 400 {object} domain.BaseResponse
|
|
||||||
// @Failure 500 {object} domain.BaseResponse
|
|
||||||
func (s *Handler) enableSource(c echo.Context) error {
|
func (s *Handler) enableSource(c echo.Context) error {
|
||||||
resp := domain.SourcesResponse {
|
id := c.Param("ID")
|
||||||
BaseResponse: domain.BaseResponse{
|
uuid, err := uuid.Parse(id)
|
||||||
Message: ResponseMessageSuccess,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
id, err := strconv.Atoi(c.Param("ID"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusBadRequest)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.repo.Sources.Enable(c.Request().Context(), int64(id))
|
err = s.Db.EnableSource(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
item, err := s.repo.Sources.GetById(c.Request().Context(), int64(id))
|
p := ApiStatusModel{
|
||||||
if err != nil {
|
Message: "OK",
|
||||||
s.WriteError(c, err, http.StatusInternalServerError)
|
StatusCode: http.StatusOK,
|
||||||
}
|
}
|
||||||
|
|
||||||
var dto []domain.SourceDto
|
b, err := json.Marshal(p)
|
||||||
dto = append(dto, services.SourceToDto(item))
|
if err != nil {
|
||||||
resp.Payload = dto
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
return c.JSON(http.StatusOK, resp)
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, b)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ type Sources interface {
|
|||||||
GetById(ctx context.Context, id int64) (domain.SourceEntity, error)
|
GetById(ctx context.Context, id int64) (domain.SourceEntity, error)
|
||||||
GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error)
|
GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error)
|
||||||
GetBySource(ctx context.Context, source string) (domain.SourceEntity, error)
|
GetBySource(ctx context.Context, source string) (domain.SourceEntity, error)
|
||||||
GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error)
|
|
||||||
List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error)
|
List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error)
|
||||||
ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error)
|
ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error)
|
||||||
Enable(ctx context.Context, id int64) (int64, error)
|
Enable(ctx context.Context, id int64) (int64, error)
|
||||||
@ -116,29 +115,6 @@ func (r sourceRepository) GetBySource(ctx context.Context, source string) (domai
|
|||||||
return data[0], nil
|
return data[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error) {
|
|
||||||
b := sqlbuilder.NewSelectBuilder()
|
|
||||||
b.Select("*")
|
|
||||||
b.From("Sources").Where(
|
|
||||||
b.Equal("Source", source),
|
|
||||||
b.Equal("Name", name),
|
|
||||||
)
|
|
||||||
b.Limit(1)
|
|
||||||
query, args := b.Build()
|
|
||||||
|
|
||||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
|
||||||
if err != nil {
|
|
||||||
return domain.SourceEntity{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := r.processRows(rows)
|
|
||||||
if len(data) == 0 {
|
|
||||||
return domain.SourceEntity{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return data[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r sourceRepository) List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error) {
|
func (r sourceRepository) List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error) {
|
||||||
builder := sqlbuilder.NewSelectBuilder()
|
builder := sqlbuilder.NewSelectBuilder()
|
||||||
builder.Select("*")
|
builder.Select("*")
|
||||||
|
@ -26,24 +26,6 @@ func ArticleToDto(item domain.ArticleEntity) domain.ArticleDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiscordWebhooksToDto(items []domain.DiscordWebHookEntity) []domain.DiscordWebHookDto{
|
|
||||||
var dtos []domain.DiscordWebHookDto
|
|
||||||
for _, item := range items {
|
|
||||||
dtos = append(dtos, DiscordWebhookToDto(item))
|
|
||||||
}
|
|
||||||
return dtos
|
|
||||||
}
|
|
||||||
|
|
||||||
func DiscordWebhookToDto(item domain.DiscordWebHookEntity) domain.DiscordWebHookDto {
|
|
||||||
return domain.DiscordWebHookDto{
|
|
||||||
ID: item.ID,
|
|
||||||
Server: item.Server,
|
|
||||||
Channel: item.Channel,
|
|
||||||
Url: item.Url,
|
|
||||||
Enabled: item.Enabled,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SourcesToDto(items []domain.SourceEntity) []domain.SourceDto {
|
func SourcesToDto(items []domain.SourceEntity) []domain.SourceDto {
|
||||||
var dtos []domain.SourceDto
|
var dtos []domain.SourceDto
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
|
Loading…
Reference in New Issue
Block a user