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(api): register router #446

Open
wants to merge 6 commits into
base: golang
Choose a base branch
from
Open

Conversation

berryhe
Copy link

@berryhe berryhe commented Dec 13, 2021

No description provided.

hyrious
hyrious previously approved these changes Dec 13, 2021
Comment on lines 58 to 70
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
}
Copy link

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

Comment on lines 58 to 68
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
}
Copy link

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

Comment on lines +15 to +22
userStorageInfo, err := cloudStorageConfigModel.FindOne(ctx, userUUID)
if err != nil {
return nil, 0, err
}

if userStorageInfo.TotalUsage == 0 {
return nil, 0, nil
}
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants