From f01a8ff592905cf98fe5b9f83dcdbfafe32c3dcd Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Wed, 13 Jul 2022 21:31:53 -0700 Subject: [PATCH] Features/swagger update (#14) * ArticlesByTag added * format cleanup --- docs/docs.go | 25 +++++++++++++++++++++++-- docs/swagger.json | 24 +++++++++++++++++++++++- docs/swagger.yaml | 18 +++++++++++++++++- main.go | 7 ++++--- routes/articles.go | 6 +++--- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index df00253..63e2ec6 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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", diff --git a/docs/swagger.json b/docs/swagger.json index ccecfb2..adcacd0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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 } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 8474a8c..a48fb98 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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: diff --git a/main.go b/main.go index 0286896..3e02f58 100644 --- a/main.go +++ b/main.go @@ -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) + } } \ No newline at end of file diff --git a/routes/articles.go b/routes/articles.go index c800afa..2841b23 100644 --- a/routes/articles.go +++ b/routes/articles.go @@ -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 {