From 3be6a02ba0a6200e71bd0b97a040075966dfc302 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 6 May 2023 17:41:12 +0300 Subject: feat: get token endpoint --- backend/controllers/loginController.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'backend/controllers/loginController.go') diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index c533757..06cc0ba 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go @@ -83,6 +83,30 @@ func Login(c *gin.Context) { } } +// GET Token +// +// @Summary Gets the token cookie value from the user. +// @Tags auth +// @Produce json +// +// @Success 200 {object} models.Respnose{data=models.LoginResponse} +// @Failure 404 {object} models.Response +// @Router /token [get] +func GetCookie(c *gin.Context) { + cookie, err := c.Cookie("token") + if err != nil { + c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) + return + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Token cookie successfully retrieved.", + Data: models.LoginResponse{ + Token: cookie, + }, + }) +} + func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId) resp, err := http.Get(url) -- cgit v1.2.3 From e1fde2db1a8003a2e48d267dfc35ca8c8fc721da Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 6 May 2023 17:43:03 +0300 Subject: doc: token endpoint --- backend/controllers/loginController.go | 12 +++++------ docs/docs.go | 37 ++++++++++++++++++++++++++++++++++ docs/swagger.json | 37 ++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 21 +++++++++++++++++++ 4 files changed, 101 insertions(+), 6 deletions(-) (limited to 'backend/controllers/loginController.go') diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index 06cc0ba..6e1c299 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go @@ -85,13 +85,13 @@ func Login(c *gin.Context) { // GET Token // -// @Summary Gets the token cookie value from the user. -// @Tags auth -// @Produce json +// @Summary Gets the token cookie value from the user. +// @Tags auth +// @Produce json // -// @Success 200 {object} models.Respnose{data=models.LoginResponse} -// @Failure 404 {object} models.Response -// @Router /token [get] +// @Success 200 {object} models.Response{data=models.LoginResponse} +// @Failure 404 {object} models.Response +// @Router /token [get] func GetCookie(c *gin.Context) { cookie, err := c.Cookie("token") if err != nil { diff --git a/docs/docs.go b/docs/docs.go index cd129f0..bb6f6ab 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -680,6 +680,43 @@ const docTemplate = `{ } } }, + "/token": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Gets the token cookie value from the user.", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.LoginResponse" + } + } + } + ] + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/users/{id}": { "get": { "consumes": [ diff --git a/docs/swagger.json b/docs/swagger.json index 442745f..5ba8a71 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -673,6 +673,43 @@ } } }, + "/token": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "Gets the token cookie value from the user.", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.LoginResponse" + } + } + } + ] + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/users/{id}": { "get": { "consumes": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fa1a26d..a39aed4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -593,6 +593,27 @@ paths: summary: Get all user and map data. tags: - search + /token: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.LoginResponse' + type: object + "404": + description: Not Found + schema: + $ref: '#/definitions/models.Response' + summary: Gets the token cookie value from the user. + tags: + - auth /users/{id}: get: consumes: -- cgit v1.2.3