All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Signed-off-by: Asai Neko <sugar@sne.moe>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package kyc
|
|
|
|
import (
|
|
"errors"
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service/service_kyc"
|
|
"nixcn-cms/tracer"
|
|
"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
|
|
// @Security Bearer
|
|
// @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"
|
|
// @Router /kyc/query [post]
|
|
func (self *KycHandler) Query(c *gin.Context) {
|
|
ctx, span := tracer.StartSpan(
|
|
c.Request.Context(),
|
|
"api_kyc",
|
|
"query",
|
|
)
|
|
defer span.End()
|
|
|
|
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointKycQuery)
|
|
ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint)
|
|
|
|
userIdOrig, ok := c.Get("user_id")
|
|
if !ok {
|
|
errorCode := exception.New(
|
|
exception.WithStatus(exception.StatusUser),
|
|
exception.WithType(exception.TypeCommon),
|
|
exception.WithOriginal(exception.CommonErrorMissingUserId),
|
|
exception.WithError(errors.New("Missing UserId")),
|
|
).Throw(ctx).String()
|
|
utils.HttpResponse(c, 403, errorCode)
|
|
return
|
|
}
|
|
|
|
var queryData service_kyc.KycQueryData
|
|
if err := c.ShouldBindJSON(&queryData); err != nil {
|
|
errorCode := exception.New(
|
|
exception.WithStatus(exception.StatusUser),
|
|
exception.WithType(exception.TypeCommon),
|
|
exception.WithOriginal(exception.CommonErrorInvalidInput),
|
|
exception.WithError(err),
|
|
).Throw(ctx).String()
|
|
utils.HttpResponse(c, 400, errorCode)
|
|
return
|
|
}
|
|
|
|
queryData.UserId = userIdOrig.(string)
|
|
|
|
queryPayload := &service_kyc.KycQueryPayload{
|
|
Context: ctx,
|
|
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)
|
|
}
|