feat: add middleware to kyc route

This commit is contained in:
AmirMahdi Qiasvand 2025-09-16 11:35:36 +03:30
parent 7a365f57ec
commit f0914bcad9
6 changed files with 50 additions and 43 deletions

View File

@ -147,7 +147,7 @@ const docTemplate = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/dto.KYCVerifyResponse" "$ref": "#/definitions/dto.APIResponse"
} }
}, },
"400": { "400": {
@ -225,6 +225,18 @@ const docTemplate = `{
} }
}, },
"definitions": { "definitions": {
"dto.APIResponse": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
},
"dto.AuthenticateRequest": { "dto.AuthenticateRequest": {
"type": "object", "type": "object",
"required": [ "required": [
@ -283,8 +295,7 @@ const docTemplate = `{
"type": "object", "type": "object",
"required": [ "required": [
"birthDate", "birthDate",
"nationalId", "nationalId"
"userId"
], ],
"properties": { "properties": {
"birthDate": { "birthDate": {
@ -292,17 +303,6 @@ const docTemplate = `{
}, },
"nationalId": { "nationalId": {
"type": "string" "type": "string"
},
"userId": {
"type": "string"
}
}
},
"dto.KYCVerifyResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
} }
} }
}, },

View File

@ -136,7 +136,7 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/dto.KYCVerifyResponse" "$ref": "#/definitions/dto.APIResponse"
} }
}, },
"400": { "400": {
@ -214,6 +214,18 @@
} }
}, },
"definitions": { "definitions": {
"dto.APIResponse": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
},
"dto.AuthenticateRequest": { "dto.AuthenticateRequest": {
"type": "object", "type": "object",
"required": [ "required": [
@ -272,8 +284,7 @@
"type": "object", "type": "object",
"required": [ "required": [
"birthDate", "birthDate",
"nationalId", "nationalId"
"userId"
], ],
"properties": { "properties": {
"birthDate": { "birthDate": {
@ -281,17 +292,6 @@
}, },
"nationalId": { "nationalId": {
"type": "string" "type": "string"
},
"userId": {
"type": "string"
}
}
},
"dto.KYCVerifyResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
} }
} }
}, },

View File

@ -1,4 +1,12 @@
definitions: definitions:
dto.APIResponse:
properties:
data: {}
message:
type: string
success:
type: boolean
type: object
dto.AuthenticateRequest: dto.AuthenticateRequest:
properties: properties:
pubKey: pubKey:
@ -40,17 +48,9 @@ definitions:
type: string type: string
nationalId: nationalId:
type: string type: string
userId:
type: string
required: required:
- birthDate - birthDate
- nationalId - nationalId
- userId
type: object
dto.KYCVerifyResponse:
properties:
message:
type: string
type: object type: object
dto.OTPProviderReq: dto.OTPProviderReq:
properties: properties:
@ -166,7 +166,7 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/dto.KYCVerifyResponse' $ref: '#/definitions/dto.APIResponse'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:

View File

@ -43,7 +43,6 @@ type OTPVerifyResponse struct {
} }
type KYCVerifyRequest struct { type KYCVerifyRequest struct {
UserID string `json:"userId" validate:"required,uuid"`
NationalID string `json:"nationalId" validate:"required"` NationalID string `json:"nationalId" validate:"required"`
BirthDate string `json:"birthDate" validate:"required"` BirthDate string `json:"birthDate" validate:"required"`
} }
@ -51,3 +50,9 @@ type KYCVerifyRequest struct {
type KYCVerifyResponse struct { type KYCVerifyResponse struct {
Message string `json:"message"` Message string `json:"message"`
} }
type APIResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}

View File

@ -2,6 +2,7 @@ package http
import ( import (
"backend/internal/api/dto" "backend/internal/api/dto"
"backend/internal/api/http/middlewares"
"backend/internal/usecase" "backend/internal/usecase"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -160,7 +161,7 @@ func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param request body dto.KYCVerifyRequest true "KYC Verify Request" // @Param request body dto.KYCVerifyRequest true "KYC Verify Request"
// @Success 200 {object} dto.KYCVerifyResponse // @Success 200 {object} dto.APIResponse
// @Failure 400 {object} map[string]string // @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string // @Failure 500 {object} map[string]string
// @Router /auth/kyc [post] // @Router /auth/kyc [post]
@ -171,15 +172,16 @@ func (h *AuthHandler) VerifyKYC(c *fiber.Ctx) error {
"error": "invalid request body", "error": "invalid request body",
}) })
} }
claims := middlewares.GetUserClaims(c)
err := h.authService.VerifyKYC(c.Context(), req.UserID, req.NationalID, req.BirthDate) err := h.authService.VerifyKYC(c.Context(), claims.UserID, req.NationalID, req.BirthDate)
if err != nil { if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(), "error": err.Error(),
}) })
} }
return c.Status(fiber.StatusOK).JSON(dto.KYCVerifyResponse{ return c.Status(fiber.StatusOK).JSON(dto.APIResponse{
Success: true,
Message: "KYC verified successfully", Message: "KYC verified successfully",
}) })
} }

View File

@ -53,5 +53,5 @@ func registerPublicRoutes(router fiber.Router, app *app.AppContainer) {
authgroup.Post("/otp", authHandler.SendOTP) authgroup.Post("/otp", authHandler.SendOTP)
authgroup.Post("/verify", authHandler.VerifyOTP) authgroup.Post("/verify", authHandler.VerifyOTP)
// add JWT middleware for KYC // add JWT middleware for KYC
authgroup.Post("/kyc", authHandler.VerifyKYC) authgroup.Post("/kyc", middlewares.JWTAuthMiddleware([]byte("Secret")), authHandler.VerifyKYC)
} }