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 enterprise real name info inquiry #5363

Merged
merged 1 commit into from
Feb 10, 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
17 changes: 17 additions & 0 deletions controllers/pkg/database/cockroach/accountv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,3 +1188,20 @@ func (c *Cockroach) GetUserRealNameInfoByUserID(userID string) (*types.UserRealN
}
return &userRealNameInfo, nil
}

func (c *Cockroach) GetEnterpriseRealNameInfoByUserID(userID string) (*types.EnterpriseRealNameInfo, error) {
// get user info
ops := &types.UserQueryOpts{ID: userID}
user, err := c.GetUserCr(ops)

if err != nil {
return nil, fmt.Errorf("failed to get user: %v", err)
}

// get user realname info
var enterpriseRealNameInfo types.EnterpriseRealNameInfo
if err := c.DB.Where(&types.EnterpriseRealNameInfo{UserUID: user.UserUID}).First(&enterpriseRealNameInfo).Error; err != nil {
return nil, fmt.Errorf("failed to get enterprise real name info: %w", err)
}
return &enterpriseRealNameInfo, nil
}
18 changes: 18 additions & 0 deletions controllers/pkg/types/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,21 @@ type UserRealNameInfo struct {
func (UserRealNameInfo) TableName() string {
return "UserRealNameInfo"
}

type EnterpriseRealNameInfo struct {
ID uuid.UUID `gorm:"column:id;type:uuid;default:gen_random_uuid();primary_key"`
UserUID uuid.UUID `gorm:"column:userUid;type:uuid;unique"`
EnterpriseName *string `gorm:"column:enterpriseName;type:text"`
EnterpriseQualification *string `gorm:"column:enterpriseQualification;type:text"`
LegalRepresentativePhone *string `gorm:"column:legalRepresentativePhone;type:text"`
IsVerified bool `gorm:"column:isVerified;type:boolean;default:false"`
VerificationStatus *string `gorm:"column:verificationStatus;type:text"`
CreatedAt time.Time `gorm:"column:createdAt;type:timestamp(3) with time zone;default:current_timestamp()"`
UpdatedAt time.Time `gorm:"column:updatedAt;type:timestamp(3) with time zone;autoUpdateTime"`
AdditionalInfo json.RawMessage `gorm:"column:additionalInfo;type:jsonb"`
SupportingMaterials json.RawMessage `gorm:"column:supportingMaterials;type:jsonb"`
}

func (EnterpriseRealNameInfo) TableName() string {
return "EnterpriseRealNameInfo"
}
24 changes: 16 additions & 8 deletions service/account/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,27 +1025,35 @@ func GetUserRealNameInfo(c *gin.Context) {
}

userRealNameInfo, err := dao.DBClient.GetUserRealNameInfo(req)

if err != nil {
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
}

if userRealNameInfo == nil {
c.JSON(http.StatusInternalServerError, helper.ErrorMessage{Error: "user real name info not found"})
enterpriseRealNameInfo, err := dao.DBClient.GetEnterpriseRealNameInfo(req)
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
}

if !userRealNameInfo.IsVerified {
c.JSON(http.StatusInternalServerError, helper.ErrorMessage{Error: "user real name info is not verified"})
isVerified := (userRealNameInfo != nil && userRealNameInfo.IsVerified) ||
(enterpriseRealNameInfo != nil && enterpriseRealNameInfo.IsVerified)

if !isVerified {
c.JSON(http.StatusOK, helper.GetRealNameInfoResp{
Data: helper.GetRealNameInfoRespData{
UserID: req.UserID,
IsRealName: false,
},
Message: "user is not verified",
})
return
}

// Return success response
c.JSON(http.StatusOK, helper.GetRealNameInfoResp{
Data: helper.GetRealNameInfoRespData{
UserID: req.UserID,
IsRealName: userRealNameInfo.IsVerified,
IsRealName: true,
},
Message: "successfully get user real name info",
})
Expand Down
4 changes: 2 additions & 2 deletions service/account/dao/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ func Init(ctx context.Context) error {
}

file := helper.ConfigPath
Cfg = &Config{} // Initialize Cfg regardless of file existence
if _, err := os.Stat(file); err == nil {
data, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("read config file error: %v", err)
}
fmt.Printf("config file found, use config file: \n%s\n", file)

Cfg = &Config{}
// json marshal
// json unmarshal
if err = json.Unmarshal(data, Cfg); err != nil {
return fmt.Errorf("unmarshal config file error: %v", err)
}
Expand Down
19 changes: 19 additions & 0 deletions service/account/dao/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dao

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -67,6 +68,7 @@ type Interface interface {
GetRechargeDiscount(req helper.AuthReq) (helper.RechargeDiscountResp, error)
ProcessPendingTaskRewards() error
GetUserRealNameInfo(req *helper.GetRealNameInfoReq) (*types.UserRealNameInfo, error)
GetEnterpriseRealNameInfo(req *helper.GetRealNameInfoReq) (*types.EnterpriseRealNameInfo, error)
ReconcileUnsettledLLMBilling(startTime, endTime time.Time) error
ReconcileActiveBilling(startTime, endTime time.Time) error
ArchiveHourlyBilling(hourStart, hourEnd time.Time) error
Expand Down Expand Up @@ -1574,12 +1576,29 @@ 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 userRealNameInfo, nil
}

func (m *Account) GetEnterpriseRealNameInfo(req *helper.GetRealNameInfoReq) (*types.EnterpriseRealNameInfo, error) {
// get enterprise info
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 enterpriseRealNameInfo, nil
}

func (m *Account) ReconcileActiveBilling(startTime, endTime time.Time) error {
ctx := context.Background()
billings := make(map[uuid.UUID]*billingBatch)
Expand Down
22 changes: 22 additions & 0 deletions service/account/dao/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,28 @@ func TestAccount_GetUserRealNameInfo(t *testing.T) {
t.Logf("userRealNameInfo = %+v", userRealNameInfo)
}

func TestAccount_GetEnterpriseRealNameInfo(t *testing.T) {
db, err := newAccountForTest("", os.Getenv("GLOBAL_COCKROACH_URI"), os.Getenv("LOCAL_COCKROACH_URI"))
if err != nil {
t.Fatalf("NewAccountInterface() error = %v", err)
return
}

enterpriseRealNameInfo, err := db.GetEnterpriseRealNameInfo(&helper.GetRealNameInfoReq{
AuthBase: helper.AuthBase{
Auth: &helper.Auth{
UserID: "E1xAJ0fy4k",
},
},
})

if err != nil {
t.Fatalf("GetUserRealNameInfo() error = %v", err)
return
}
t.Logf("enterpriseRealNameInfo = %+v", enterpriseRealNameInfo)
}

func init() {
// set env
os.Setenv("MONGO_URI", "")
Expand Down