Open
Conversation
hyrious
previously approved these changes
Dec 13, 2021
whg517
reviewed
Dec 15, 2021
model/cloud_storage_user_files.go
Outdated
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 | ||
| } |
There was a problem hiding this comment.
You should adjust the database access logic into the DAO layer
model/cloud_storage_configs.go
Outdated
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 | ||
| } |
There was a problem hiding this comment.
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 | ||
| } |
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.