67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
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)
|
|
}
|