Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(account-service): Add aiproxy backend real name lookup interface #5394

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controllers/pkg/database/cockroach/accountv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,9 @@ func (c *Cockroach) GetUserRealNameInfoByUserID(userID string) (*types.UserRealN
// get user realname info
var userRealNameInfo types.UserRealNameInfo
if err := c.DB.Where(&types.UserRealNameInfo{UserUID: user.UserUID}).First(&userRealNameInfo).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, gorm.ErrRecordNotFound
}
return nil, fmt.Errorf("failed to get user real name info: %w", err)
}
return &userRealNameInfo, nil
Expand All @@ -1201,6 +1204,9 @@ func (c *Cockroach) GetEnterpriseRealNameInfoByUserID(userID string) (*types.Ent
// get user realname info
var enterpriseRealNameInfo types.EnterpriseRealNameInfo
if err := c.DB.Where(&types.EnterpriseRealNameInfo{UserUID: user.UserUID}).First(&enterpriseRealNameInfo).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, gorm.ErrRecordNotFound
}
return nil, fmt.Errorf("failed to get enterprise real name info: %w", err)
}
return &enterpriseRealNameInfo, nil
Expand Down
55 changes: 55 additions & 0 deletions service/account/api/admin.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package api

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/labring/sealos/controllers/pkg/types"
"github.com/labring/sealos/service/account/dao"
"github.com/labring/sealos/service/account/helper"
"gorm.io/gorm"
)

// GetAccount
Expand Down Expand Up @@ -73,6 +77,57 @@ func AdminChargeBilling(c *gin.Context) {
})
}

// AdminGetUserRealNameInfo
// @Summary Get user real name info
// @Description Get user real name info
// @Tags Account
// @Accept json
// @Produce json
// @Success 200 {object} map[string]interface{} "successfully retrieved user real name info"
// @Failure 401 {object} map[string]interface{} "authenticate error"
// @Failure 500 {object} map[string]interface{} "failed to get user real name info"
// @Router /admin/v1alpha1/real-name-info [get]
func AdminGetUserRealNameInfo(c *gin.Context) {
err := authenticateAdminRequest(c)
if err != nil {
c.JSON(http.StatusUnauthorized, helper.ErrorMessage{Error: fmt.Sprintf("authenticate error : %v", err)})
return
}
userUID, exist := c.GetQuery("userUID")
if !exist || userUID == "" {
c.JSON(http.StatusBadRequest, helper.ErrorMessage{Error: "empty userUID"})
return
}
userID, err := dao.DBClient.GetUserID(types.UserQueryOpts{UID: uuid.MustParse(userUID)})
if err != nil {
c.JSON(http.StatusInternalServerError, helper.ErrorMessage{Error: fmt.Sprintf("failed to get user ID: %v", err)})
return
}
ck := dao.DBClient.GetCockroach()

userRealNameInfo, err := ck.GetUserRealNameInfoByUserID(userID)

if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusInternalServerError, helper.ErrorMessage{Error: fmt.Sprintf("failed to get user real name info: %v", err)})
return
}

enterpriseRealNameInfo, err := ck.GetEnterpriseRealNameInfoByUserID(userID)

if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusInternalServerError, helper.ErrorMessage{Error: fmt.Sprintf("failed to get enterprise real name info: %v", err)})
return
}

isVerified := (userRealNameInfo != nil && userRealNameInfo.IsVerified) ||
(enterpriseRealNameInfo != nil && enterpriseRealNameInfo.IsVerified)

c.JSON(http.StatusOK, gin.H{
"userUID": userUID,
"isRealName": isVerified,
})
}

// ActiveBilling
// @Summary Active billing
// @Description Active billing
Expand Down
2 changes: 1 addition & 1 deletion service/account/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func UserUsage(c *gin.Context) {
// @Tags RechargeDiscount
// @Accept json
// @Produce json
// @Param request body helper.GetRechargeDiscountReq true "Get recharge discount request"
// @Param request body object true "Get recharge discount request"
// @Success 200 {object} map[string]interface{} "successfully get recharge discount"
// @Failure 400 {object} map[string]interface{} "failed to parse get recharge discount request"
// @Failure 401 {object} map[string]interface{} "authenticate error"
Expand Down
16 changes: 7 additions & 9 deletions service/account/dao/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dao

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -73,6 +72,7 @@ type Interface interface {
ReconcileActiveBilling(startTime, endTime time.Time) error
ArchiveHourlyBilling(hourStart, hourEnd time.Time) error
ActiveBilling(req resources.ActiveBilling) error
GetCockroach() *cockroach.Cockroach
}

type Account struct {
Expand All @@ -93,6 +93,10 @@ type Cockroach struct {
ck *cockroach.Cockroach
}

func (g *Cockroach) GetCockroach() *cockroach.Cockroach {
return g.ck
}

func (g *Cockroach) GetAccount(ops types.UserQueryOpts) (*types.Account, error) {
account, err := g.ck.GetAccount(&ops)
if err != nil {
Expand Down Expand Up @@ -1576,10 +1580,7 @@ func (m *Account) GetUserRealNameInfo(req *helper.GetRealNameInfoReq) (*types.Us
userRealNameInfo, err := m.ck.GetUserRealNameInfoByUserID(req.UserID)

if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, gorm.ErrRecordNotFound
}
return nil, fmt.Errorf("failed to get user real name info: %v", err)
return nil, err
}

return userRealNameInfo, nil
Expand All @@ -1590,10 +1591,7 @@ func (m *Account) GetEnterpriseRealNameInfo(req *helper.GetRealNameInfoReq) (*ty
enterpriseRealNameInfo, err := m.ck.GetEnterpriseRealNameInfoByUserID(req.UserID)

if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, gorm.ErrRecordNotFound
}
return nil, fmt.Errorf("failed to get enterprise real name info: %v", err)
return nil, err
}

return enterpriseRealNameInfo, nil
Expand Down
Loading
Loading