Features/swagger update (#14)

* ArticlesByTag added

* format cleanup
This commit is contained in:
James Tombleson 2022-07-13 21:31:53 -07:00 committed by GitHub
parent 65f4281f92
commit f01a8ff592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 10 deletions

View File

@ -29,6 +29,27 @@ const docTemplate = `{
}
},
"/articles/by/sourceid": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Articles"
],
"summary": "Finds the articles based on the SourceID provided. Returns the top 50.",
"parameters": [
{
"type": "string",
"description": "Source ID UUID",
"name": "id",
"in": "query",
"required": true
}
],
"responses": {}
}
},
"/articles/by/tag": {
"get": {
"produces": [
"application/json"
@ -41,7 +62,7 @@ const docTemplate = `{
{
"type": "string",
"description": "Tag name",
"name": "Tag",
"name": "tag",
"in": "query",
"required": true
}
@ -497,7 +518,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "0.1",
Host: "",
Host: "localhost:8081",
BasePath: "/api",
Schemes: []string{},
Title: "NewsBot collector",

View File

@ -5,6 +5,7 @@
"contact": {},
"version": "0.1"
},
"host": "localhost:8081",
"basePath": "/api",
"paths": {
"/articles": {
@ -20,6 +21,27 @@
}
},
"/articles/by/sourceid": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Articles"
],
"summary": "Finds the articles based on the SourceID provided. Returns the top 50.",
"parameters": [
{
"type": "string",
"description": "Source ID UUID",
"name": "id",
"in": "query",
"required": true
}
],
"responses": {}
}
},
"/articles/by/tag": {
"get": {
"produces": [
"application/json"
@ -32,7 +54,7 @@
{
"type": "string",
"description": "Tag name",
"name": "Tag",
"name": "tag",
"in": "query",
"required": true
}

View File

@ -1,4 +1,5 @@
basePath: /api
host: localhost:8081
info:
contact: {}
title: NewsBot collector
@ -27,11 +28,26 @@ paths:
tags:
- Articles
/articles/by/sourceid:
get:
parameters:
- description: Source ID UUID
in: query
name: id
required: true
type: string
produces:
- application/json
responses: {}
summary: Finds the articles based on the SourceID provided. Returns the top
50.
tags:
- Articles
/articles/by/tag:
get:
parameters:
- description: Tag name
in: query
name: Tag
name: tag
required: true
type: string
produces:

View File

@ -10,11 +10,10 @@ import (
"github.com/jtom38/newsbot/collector/services/cron"
)
// @title NewsBot collector
// @version 0.1
// @BasePath /api
func main() {
ctx := context.Background()
c := cron.New(ctx)
@ -26,5 +25,7 @@ func main() {
fmt.Println("API: http://localhost:8081/api")
fmt.Println("Swagger: http://localhost:8081/swagger/index.html")
err := http.ListenAndServe(":8081", server.Router)
if err != nil { panic(err) }
if err != nil {
panic(err)
}
}

View File

@ -99,16 +99,16 @@ func (s *Server) GetArticlesBySourceId(w http.ResponseWriter, r *http.Request) {
// TODO add page support
// GetArticlesByTag
// @Summary Finds the articles based on the SourceID provided. Returns the top 50.
// @Param Tag query string true "Tag name"
// @Param tag query string true "Tag name"
// @Produce application/json
// @Tags Articles
// @Router /articles/by/sourceid [get]
// @Router /articles/by/tag [get]
func (s *Server) GetArticlesByTag(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
r.URL.Query()
query := r.URL.Query()
_id := query["id"][0]
_id := query["tag"][0]
uuid, err := uuid.Parse(_id)
if err != nil {