From 534694a2209d4806b23cdfba9c21e80442a95fc5 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 21 Oct 2023 09:10:02 +0200 Subject: [PATCH] delete verified user --- main.go | 14 ++++ modules/structs/notification.go | 2 +- public/swagger/swagger.json | 92 +++++++++++++++++++++ routers/api/v1/notification/notification.go | 2 +- routers/api/v1/verifycode/verifycode.go | 36 ++++++++ routers/router/router.go | 1 + 6 files changed, 145 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 9903982..043d668 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,17 @@ +// Package classification JNX Telegram Bot Manager API Documentation. +// +// Schemes: https +// Host: jannex +// BasePath: /v1 +// Version: 1.0.0 +// +// Consumes: +// - application/json +// +// Produces: +// - application/json +// +// swagger:meta package main import ( diff --git a/modules/structs/notification.go b/modules/structs/notification.go index 5b2f1a3..8ed346e 100644 --- a/modules/structs/notification.go +++ b/modules/structs/notification.go @@ -4,5 +4,5 @@ package structs type NotificationBody struct { UserIds []string Type uint8 - Message string + Title string } diff --git a/public/swagger/swagger.json b/public/swagger/swagger.json index 4b167cb..8571a17 100644 --- a/public/swagger/swagger.json +++ b/public/swagger/swagger.json @@ -1,5 +1,20 @@ { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "schemes": [ + "https" + ], "swagger": "2.0", + "info": { + "title": "JNX Telegram Bot Manager API Documentation.", + "version": "1.0.0" + }, + "host": "jannex", + "basePath": "/v1", "paths": { "/v1/notification": { "post": { @@ -35,6 +50,41 @@ } } }, + "/v1/status/{userId}": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "status" + ], + "summary": "Check if user is verified", + "operationId": "userVerified", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "userId", + "in": "params", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/StatusResponse" + } + }, + "400": { + "description": "Bad request" + } + } + } + }, "/v1/verifycode/{userId}": { "get": { "consumes": [ @@ -71,6 +121,39 @@ "description": "Internal server error" } } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "verifycode" + ], + "summary": "Delete verified user", + "operationId": "deleteVerifiedUser", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "userId", + "in": "params", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad request" + }, + "500": { + "description": "Internal server error" + } + } } } }, @@ -94,6 +177,15 @@ }, "x-go-package": "jannex/telegram-bot-manager/modules/structs" }, + "StatusResponse": { + "type": "object", + "properties": { + "Status": { + "type": "boolean" + } + }, + "x-go-package": "jannex/telegram-bot-manager/modules/structs" + }, "VerifyCodeResponse": { "type": "object", "properties": { diff --git a/routers/api/v1/notification/notification.go b/routers/api/v1/notification/notification.go index c17dff2..d39c70e 100644 --- a/routers/api/v1/notification/notification.go +++ b/routers/api/v1/notification/notification.go @@ -44,7 +44,7 @@ func SendNotification(c *fiber.Ctx) error { // get all verified users by body userIds database.DB.Where("user_id IN ?", body.UserIds).Find(&foundVerifiedUsers) - formattedMessage := utils.GetNotificationIconByType(body.Type) + " " + body.Message + formattedMessage := utils.GetNotificationIconByType(body.Type) + " " + body.Title // send message to all verified users for _, user := range foundVerifiedUsers { diff --git a/routers/api/v1/verifycode/verifycode.go b/routers/api/v1/verifycode/verifycode.go index 768036c..f7946bd 100644 --- a/routers/api/v1/verifycode/verifycode.go +++ b/routers/api/v1/verifycode/verifycode.go @@ -2,6 +2,7 @@ package verifycode import ( "jannex/telegram-bot-manager/modules/cache" + "jannex/telegram-bot-manager/modules/database" "jannex/telegram-bot-manager/modules/logger" "jannex/telegram-bot-manager/modules/structs" "jannex/telegram-bot-manager/modules/utils" @@ -58,3 +59,38 @@ func GetVerifyCode(c *fiber.Ctx) error { return c.JSON(structs.VerifyCodeResponse{Code: code}) } + +func DeleteVerifiedUser(c *fiber.Ctx) error { + // swagger:operation DELETE /v1/verifycode/{userId} verifycode deleteVerifiedUser + // --- + // summary: Delete verified user + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: userId + // in: params + // description: User ID + // required: true + // type: string + // responses: + // '200': + // description: OK + // '400': + // description: Bad request + // '500': + // description: Internal server error + + var params structs.UserIdParam + + if err := rsutils.ParamsParserHelper(c, ¶ms); err != nil { + return c.SendStatus(fiber.StatusBadRequest) + } + + database.DB.Where("user_id = ?", params.UserId).Delete(&structs.VerifiedUser{}) + + logger.AddSystemLog(rslogger.LogTypeInfo, "Deleted verified user %s", params.UserId) + + return c.SendStatus(fiber.StatusOK) +} diff --git a/routers/router/router.go b/routers/router/router.go index 31ae276..f21513c 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -13,6 +13,7 @@ func SetupRoutes(app *fiber.App) { vc := v1.Group("/verifycode") vc.Get("/:userId", verifycode.GetVerifyCode) + vc.Delete("/:userId", verifycode.DeleteVerifiedUser) n := v1.Group("/notification") n.Post("/", notification.SendNotification)