@@ -2,10 +2,20 @@ package kyc
|
||||
|
||||
import (
|
||||
"nixcn-cms/middleware"
|
||||
"nixcn-cms/service/service_kyc"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func ApiHandler(r *gin.RouterGroup) {
|
||||
r.Use(middleware.ApiVersionCheck(), middleware.JWTAuth(), middleware.Permission(10))
|
||||
type KycHandler struct {
|
||||
svc service_kyc.KycService
|
||||
}
|
||||
|
||||
func ApiHandler(r *gin.RouterGroup) {
|
||||
kycSvc := service_kyc.NewKycService()
|
||||
kycHandler := &KycHandler{kycSvc}
|
||||
|
||||
r.Use(middleware.ApiVersionCheck(), middleware.JWTAuth(), middleware.Permission(10))
|
||||
r.POST("/kyc/session", kycHandler.Session)
|
||||
r.POST("/kyc/query", kycHandler.Query)
|
||||
}
|
||||
|
||||
66
api/kyc/query.go
Normal file
66
api/kyc/query.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package kyc
|
||||
|
||||
import (
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/service_kyc"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Summary Query KYC Status
|
||||
// @Description Checks the current state of a KYC session and updates local database if approved.
|
||||
// @Tags KYC
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param payload body service_kyc.KycQueryData true "KYC query data (KycId)"
|
||||
// @Success 200 {object} utils.RespStatus{data=service_kyc.KycQueryResponse} "Query processed (success/pending/failed)"
|
||||
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid UUID or input"
|
||||
// @Failure 403 {object} utils.RespStatus{data=nil} "Unauthorized"
|
||||
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /kyc/query [post]
|
||||
func (self *KycHandler) Query(c *gin.Context) {
|
||||
_, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorMissingUserId).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 403, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
var queryData service_kyc.KycQueryData
|
||||
if err := c.ShouldBindJSON(&queryData); err != nil {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 400, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
queryPayload := &service_kyc.KycQueryPayload{
|
||||
Context: c,
|
||||
Data: &queryData,
|
||||
}
|
||||
|
||||
result := self.svc.QueryKyc(queryPayload)
|
||||
|
||||
if result.Common.Exception.Original != exception.CommonSuccess {
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
||||
return
|
||||
}
|
||||
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
||||
}
|
||||
68
api/kyc/session.go
Normal file
68
api/kyc/session.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package kyc
|
||||
|
||||
import (
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/service_kyc"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Summary Create KYC Session
|
||||
// @Description Initializes a KYC process (CNRid or Passport) and returns the status or redirect URI.
|
||||
// @Tags KYC
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param payload body service_kyc.KycSessionData true "KYC session data (Type and Base64 Identity)"
|
||||
// @Success 200 {object} utils.RespStatus{data=service_kyc.KycSessionResponse} "Session created successfully"
|
||||
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid input or decode failed"
|
||||
// @Failure 403 {object} utils.RespStatus{data=nil} "Missing User ID"
|
||||
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error / KYC Service Error"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /kyc/session [post]
|
||||
func (self *KycHandler) Session(c *gin.Context) {
|
||||
userIdFromHeaderOrig, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorMissingUserId).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 403, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
var sessionData service_kyc.KycSessionData
|
||||
if err := c.ShouldBindJSON(&sessionData); err != nil {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 400, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
sessionData.UserId = userIdFromHeaderOrig.(string)
|
||||
|
||||
kycPayload := &service_kyc.KycSessionPayload{
|
||||
Context: c,
|
||||
Data: &sessionData,
|
||||
}
|
||||
|
||||
result := self.svc.SessionKyc(kycPayload)
|
||||
|
||||
if result.Common.Exception.Original != exception.CommonSuccess {
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
||||
return
|
||||
}
|
||||
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
||||
}
|
||||
Reference in New Issue
Block a user