-
Notifications
You must be signed in to change notification settings - Fork 271
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(api): register router #446
base: golang
Are you sure you want to change the base?
Conversation
model/cloud_storage_user_files.go
Outdated
func (c *CloudStorageUserFilesMgr) FindUserStorageFiles(ctx context.Context, userUUID string, limit, offset int) (result []CloudStorageFiles, err error) { | ||
err = c.db.WithContext(ctx).Model(&CloudStorageUserFiles{}). | ||
Where( | ||
&CloudStorageUserFiles{ | ||
UserUUID: userUUID, | ||
IsDelete: 0, | ||
}, | ||
).Joins(" INNER JOIN cloud_storage_files csf ON cloud_storage_user_files.file_uuid = csf.file_uuid"). | ||
Offset(offset). | ||
Limit(limit). | ||
Scan(&result).Error | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should adjust the database access logic into the DAO layer
model/cloud_storage_configs.go
Outdated
func (c *CloudStorageConfigMgr) FindOne(ctx context.Context, userUUID string) (result CloudStorageConfigs, err error) { | ||
err = c.db.WithContext(ctx).Model(&CloudStorageConfigs{}). | ||
Where( | ||
&CloudStorageConfigs{ | ||
UserUUID: userUUID, | ||
IsDelete: 0, | ||
}, | ||
). | ||
Find(&result).Error | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should adjust the database access logic into the DAO layer
userStorageInfo, err := cloudStorageConfigModel.FindOne(ctx, userUUID) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
if userStorageInfo.TotalUsage == 0 { | ||
return nil, 0, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put the logic to get userStorageInfo in cloudStorageConfigDAO.
If you need to query cloudStorageConfig
separately in a service, this part of the logic will be repeated, which violates the DRY principle.
After pulling this logic out, you need to check userStorageInfo
in the service layer and then get cloudStorageConfigs
No description provided.