From 9a4023acab9cb560d26d764ee51ffda0c90d610a Mon Sep 17 00:00:00 2001 From: DeveloperDurp Date: Tue, 2 Apr 2024 22:00:33 -0500 Subject: [PATCH] update --- controller/dadjoke.go | 9 +++++++++ controller/openai.go | 5 +++++ docs/docs.go | 25 +++++++++++++++++++++++++ docs/swagger.json | 25 +++++++++++++++++++++++++ docs/swagger.yaml | 10 ++++++++++ main.go | 3 +++ 6 files changed, 77 insertions(+) diff --git a/controller/dadjoke.go b/controller/dadjoke.go index c2bf1a8..0a45c36 100644 --- a/controller/dadjoke.go +++ b/controller/dadjoke.go @@ -17,6 +17,9 @@ import ( // @Produce application/json // @Success 200 {object} model.Message "response" // @failure 500 {object} model.Message "error" +// +// @Security Authorization +// // @Router /jokes/dadjoke [get] func (c *Controller) GetDadJoke(w http.ResponseWriter, r *http.Request) { joke, err := service.GetRandomDadJoke(c.Db.DB) @@ -44,6 +47,9 @@ func (c *Controller) GetDadJoke(w http.ResponseWriter, r *http.Request) { // @Param joke query string true "Dad Joke you wish to enter into database" // @Success 200 {object} model.Message "response" // @failure 500 {object} model.Message "error" +// +// @Security Authorization +// // @Router /jokes/dadjoke [post] func (c *Controller) PostDadJoke(w http.ResponseWriter, r *http.Request) { contentType := r.Header.Get("Content-Type") @@ -86,6 +92,9 @@ func (c *Controller) PostDadJoke(w http.ResponseWriter, r *http.Request) { // @Param joke query string true "Dad joke you wish to delete from the database" // @Success 200 {object} model.Message "response" // @failure 500 {object} model.Message "error" +// +// @Security Authorization +// // @Router /jokes/dadjoke [delete] func (c *Controller) DeleteDadJoke(w http.ResponseWriter, r *http.Request) { contentType := r.Header.Get("Content-Type") diff --git a/controller/openai.go b/controller/openai.go index 73fc815..d49d2fb 100644 --- a/controller/openai.go +++ b/controller/openai.go @@ -31,6 +31,8 @@ type Response struct { // // @failure 400 {object} model.Message "error" // +// @Security Authorization +// // @Router /openai/general [get] func (c *Controller) GeneralOpenAI(w http.ResponseWriter, r *http.Request) { contentType := r.Header.Get("Content-Type") @@ -73,6 +75,9 @@ func (c *Controller) GeneralOpenAI(w http.ResponseWriter, r *http.Request) { // @Param message query string true "Ask ChatGPT for suggestions as a travel agent" // @Success 200 {object} model.Message "response" // @failure 400 {object} model.Message "error" +// +// @Security Authorization +// // @Router /openai/travelagent [get] func (c *Controller) TravelAgentOpenAI(w http.ResponseWriter, r *http.Request) { contentType := r.Header.Get("Content-Type") diff --git a/docs/docs.go b/docs/docs.go index 116c99b..e8fa0c0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -60,6 +60,11 @@ const docTemplate = `{ }, "/jokes/dadjoke": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "get a dad joke", "consumes": [ "application/json" @@ -87,6 +92,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "Authorization": [] + } + ], "description": "create a dad joke", "consumes": [ "application/json" @@ -123,6 +133,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "Authorization": [] + } + ], "description": "create a dad joke", "consumes": [ "application/json" @@ -161,6 +176,11 @@ const docTemplate = `{ }, "/openai/general": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "Ask ChatGPT a general question", "consumes": [ "application/json" @@ -199,6 +219,11 @@ const docTemplate = `{ }, "/openai/travelagent": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "Ask ChatGPT for suggestions as if it was a travel agent", "consumes": [ "application/json" diff --git a/docs/swagger.json b/docs/swagger.json index 51e7c4c..65cd6bf 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -52,6 +52,11 @@ }, "/jokes/dadjoke": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "get a dad joke", "consumes": [ "application/json" @@ -79,6 +84,11 @@ } }, "post": { + "security": [ + { + "Authorization": [] + } + ], "description": "create a dad joke", "consumes": [ "application/json" @@ -115,6 +125,11 @@ } }, "delete": { + "security": [ + { + "Authorization": [] + } + ], "description": "create a dad joke", "consumes": [ "application/json" @@ -153,6 +168,11 @@ }, "/openai/general": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "Ask ChatGPT a general question", "consumes": [ "application/json" @@ -191,6 +211,11 @@ }, "/openai/travelagent": { "get": { + "security": [ + { + "Authorization": [] + } + ], "description": "Ask ChatGPT for suggestions as if it was a travel agent", "consumes": [ "application/json" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2fa0e94..d477d19 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -61,6 +61,8 @@ paths: description: error schema: $ref: '#/definitions/model.Message' + security: + - Authorization: [] summary: Generate dadjoke tags: - DadJoke @@ -79,6 +81,8 @@ paths: description: error schema: $ref: '#/definitions/model.Message' + security: + - Authorization: [] summary: Get dadjoke tags: - DadJoke @@ -103,6 +107,8 @@ paths: description: error schema: $ref: '#/definitions/model.Message' + security: + - Authorization: [] summary: Generate dadjoke tags: - DadJoke @@ -128,6 +134,8 @@ paths: description: error schema: $ref: '#/definitions/model.Message' + security: + - Authorization: [] summary: Gerneral ChatGPT tags: - openai @@ -153,6 +161,8 @@ paths: description: error schema: $ref: '#/definitions/model.Message' + security: + - Authorization: [] summary: Travel Agent ChatGPT tags: - openai diff --git a/main.go b/main.go index 4743472..3c65cb4 100644 --- a/main.go +++ b/main.go @@ -35,10 +35,13 @@ func main() { router := http.NewServeMux() router.HandleFunc("/swagger/*", httpSwagger.Handler()) + router.HandleFunc("GET /api/health/gethealth", c.GetHealth) + router.HandleFunc("GET /api/jokes/dadjoke", c.GetDadJoke) router.HandleFunc("POST /api/jokes/dadjoke", c.PostDadJoke) router.HandleFunc("DELETE /api/jokes/dadjoke", c.DeleteDadJoke) + router.HandleFunc("GET /api/openai/general", c.GeneralOpenAI) router.HandleFunc("GET /api/openai/travelagent", c.TravelAgentOpenAI) // adminRouter := http.NewServeMux()