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": { "/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": { "get": {
"produces": [ "produces": [
"application/json" "application/json"
@ -41,7 +62,7 @@ const docTemplate = `{
{ {
"type": "string", "type": "string",
"description": "Tag name", "description": "Tag name",
"name": "Tag", "name": "tag",
"in": "query", "in": "query",
"required": true "required": true
} }
@ -497,7 +518,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "0.1", Version: "0.1",
Host: "", Host: "localhost:8081",
BasePath: "/api", BasePath: "/api",
Schemes: []string{}, Schemes: []string{},
Title: "NewsBot collector", Title: "NewsBot collector",

View File

@ -5,6 +5,7 @@
"contact": {}, "contact": {},
"version": "0.1" "version": "0.1"
}, },
"host": "localhost:8081",
"basePath": "/api", "basePath": "/api",
"paths": { "paths": {
"/articles": { "/articles": {
@ -20,6 +21,27 @@
} }
}, },
"/articles/by/sourceid": { "/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": { "get": {
"produces": [ "produces": [
"application/json" "application/json"
@ -32,7 +54,7 @@
{ {
"type": "string", "type": "string",
"description": "Tag name", "description": "Tag name",
"name": "Tag", "name": "tag",
"in": "query", "in": "query",
"required": true "required": true
} }

View File

@ -1,4 +1,5 @@
basePath: /api basePath: /api
host: localhost:8081
info: info:
contact: {} contact: {}
title: NewsBot collector title: NewsBot collector
@ -27,11 +28,26 @@ paths:
tags: tags:
- Articles - Articles
/articles/by/sourceid: /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: get:
parameters: parameters:
- description: Tag name - description: Tag name
in: query in: query
name: Tag name: tag
required: true required: true
type: string type: string
produces: produces:

View File

@ -10,11 +10,10 @@ import (
"github.com/jtom38/newsbot/collector/services/cron" "github.com/jtom38/newsbot/collector/services/cron"
) )
// @title NewsBot collector // @title NewsBot collector
// @version 0.1 // @version 0.1
// @BasePath /api // @BasePath /api
func main() { func main() {
ctx := context.Background() ctx := context.Background()
c := cron.New(ctx) c := cron.New(ctx)
@ -26,5 +25,7 @@ func main() {
fmt.Println("API: http://localhost:8081/api") fmt.Println("API: http://localhost:8081/api")
fmt.Println("Swagger: http://localhost:8081/swagger/index.html") fmt.Println("Swagger: http://localhost:8081/swagger/index.html")
err := http.ListenAndServe(":8081", server.Router) 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 // TODO add page support
// GetArticlesByTag // GetArticlesByTag
// @Summary Finds the articles based on the SourceID provided. Returns the top 50. // @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 // @Produce application/json
// @Tags Articles // @Tags Articles
// @Router /articles/by/sourceid [get] // @Router /articles/by/tag [get]
func (s *Server) GetArticlesByTag(w http.ResponseWriter, r *http.Request) { func (s *Server) GetArticlesByTag(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
r.URL.Query() r.URL.Query()
query := r.URL.Query() query := r.URL.Query()
_id := query["id"][0] _id := query["tag"][0]
uuid, err := uuid.Parse(_id) uuid, err := uuid.Parse(_id)
if err != nil { if err != nil {