-
Notifications
You must be signed in to change notification settings - Fork 555
feat:store notes.txt in db and fetch from db #3183
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
Changes from 6 commits
fc7b04f
46d6228
ac0b96b
635f830
74d83e6
f766d46
1ca9704
7a479bd
d06a98e
4dcd6e2
504124d
3f4d69d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,8 @@ type InstalledAppRepository interface { | |
| GetAllIntalledAppsByAppStoreId(appStoreId int) ([]InstalledAppAndEnvDetails, error) | ||
| GetAllInstalledAppsByChartRepoId(chartRepoId int) ([]InstalledAppAndEnvDetails, error) | ||
| GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId int, envId int) (*InstalledAppVersions, error) | ||
| FetchNotesFromdb(installedAppId int) (*InstalledApps, error) | ||
| GetInstalledAppVersionByAppStoreId(appStoreId int) ([]*InstalledAppVersions, error) | ||
|
|
||
| DeleteInstalledApp(model *InstalledApps) (*InstalledApps, error) | ||
| DeleteInstalledAppVersion(model *InstalledAppVersions) (*InstalledAppVersions, error) | ||
| GetInstalledAppVersionByInstalledAppId(id int) ([]*InstalledAppVersions, error) | ||
|
|
@@ -93,6 +93,7 @@ type InstalledApps struct { | |
| DeploymentAppType string `sql:"deployment_app_type"` | ||
| Status appStoreBean.AppstoreDeploymentStatus `sql:"status"` | ||
| DeploymentAppDeleteRequest bool `sql:"deployment_app_delete_request"` | ||
| Notes string `json:"notes"` | ||
| App app.App | ||
| Environment repository.Environment | ||
| sql.AuditLog | ||
|
|
@@ -189,6 +190,13 @@ func (impl InstalledAppRepositoryImpl) UpdateInstalledAppVersion(model *Installe | |
| } | ||
| return model, nil | ||
| } | ||
| func (impl InstalledAppRepositoryImpl) FetchNotesFromdb(installedAppId int) (*InstalledApps, error) { | ||
|
||
| model := &InstalledApps{} | ||
| err := impl.dbConnection.Model(model). | ||
| Column("installed_apps.*", "App"). | ||
| Where("installed_apps.id = ?", installedAppId).Where("installed_apps.active = true").Select() | ||
| return model, err | ||
| } | ||
|
|
||
| func (impl InstalledAppRepositoryImpl) GetInstalledApp(id int) (*InstalledApps, error) { | ||
| model := &InstalledApps{} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ type AppStoreDeploymentService interface { | |
| GetInstalledAppVersion(id int, userId int32) (*appStoreBean.InstallAppVersionDTO, error) | ||
| InstallAppByHelm(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ctx context.Context) (*appStoreBean.InstallAppVersionDTO, error) | ||
| UpdateProjectHelmApp(updateAppRequest *appStoreBean.UpdateProjectHelmAppDTO) error | ||
| AppStoreDeployOperationNotesUpdate(installAppId int, notes string) (bool, error) | ||
| } | ||
|
|
||
| type DeploymentServiceTypeConfig struct { | ||
|
|
@@ -280,6 +281,33 @@ func (impl AppStoreDeploymentServiceImpl) GetGitOpsRepoName(appName string) stri | |
| return repoName | ||
| } | ||
|
|
||
| func (impl AppStoreDeploymentServiceImpl) AppStoreDeployOperationNotesUpdate(installAppId int, notes string) (bool, error) { | ||
|
||
| dbConnection := impl.installedAppRepository.GetConnection() | ||
| tx, err := dbConnection.Begin() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| // Rollback tx on error. | ||
| defer tx.Rollback() | ||
| installedApp, err := impl.installedAppRepository.GetInstalledApp(installAppId) | ||
| if err != nil { | ||
| impl.logger.Errorw("error while fetching from db", "error", err) | ||
| return false, err | ||
| } | ||
| installedApp.Notes = notes | ||
| _, err = impl.installedAppRepository.UpdateInstalledApp(installedApp, tx) | ||
| if err != nil { | ||
| impl.logger.Errorw("error while fetching from db", "error", err) | ||
| return false, err | ||
| } | ||
| err = tx.Commit() | ||
| if err != nil { | ||
| impl.logger.Errorw("error while commit db transaction to db", "error", err) | ||
| return false, err | ||
| } | ||
| return true, nil | ||
| } | ||
|
|
||
| func (impl AppStoreDeploymentServiceImpl) AppStoreDeployOperationStatusUpdate(installAppId int, status appStoreBean.AppstoreDeploymentStatus) (bool, error) { | ||
| dbConnection := impl.installedAppRepository.GetConnection() | ||
| tx, err := dbConnection.Begin() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ type InstalledAppService interface { | |
| MarkGitOpsInstalledAppsDeletedIfArgoAppIsDeleted(installedAppId int, envId int) error | ||
| CheckAppExistsByInstalledAppId(installedAppId int) error | ||
| FindNotesForArgoApplication(installedAppId, envId int) (string, string, error) | ||
| FetchNotesFromdb(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error) | ||
| } | ||
|
|
||
| type InstalledAppServiceImpl struct { | ||
|
|
@@ -783,6 +784,33 @@ func (impl *InstalledAppServiceImpl) FindAppDetailsForAppstoreApplication(instal | |
| } | ||
| return appDetail, nil | ||
| } | ||
| func (impl *InstalledAppServiceImpl) FetchNotesFromdb(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error) { | ||
| installedApp, err := impl.installedAppRepository.FetchNotesFromdb(installedAppId) | ||
| appName := installedApp.App.AppName | ||
| if err != nil { | ||
| impl.logger.Errorw("error fetching notes from db", "err", err) | ||
| return "", err | ||
| } | ||
| isValidAuth := checkNotesAuth(token, appName, envId) | ||
| if !isValidAuth { | ||
| impl.logger.Errorw("unauthorized user", "isValidAuth", isValidAuth) | ||
| return "", nil | ||
|
||
| } | ||
|
|
||
| if installedApp.Notes == "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put comments
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| notes, _, err := impl.FindNotesForArgoApplication(installedAppId, envId) | ||
| if err != nil { | ||
| impl.logger.Errorw("error fetching notes", "err", err) | ||
| return "", err | ||
| } | ||
| if notes == "" { | ||
| impl.logger.Errorw("error fetching notes", "err", err) | ||
| } | ||
| return notes, err | ||
| } | ||
|
|
||
| return installedApp.Notes, nil | ||
| } | ||
| func (impl *InstalledAppServiceImpl) FindNotesForArgoApplication(installedAppId, envId int) (string, string, error) { | ||
| installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId) | ||
| if err != nil { | ||
|
|
@@ -829,7 +857,13 @@ func (impl *InstalledAppServiceImpl) FindNotesForArgoApplication(installedAppId, | |
| impl.logger.Errorw("error in fetching notes", "err", err) | ||
| return notes, appName, err | ||
| } | ||
| _, err = impl.appStoreDeploymentService.AppStoreDeployOperationNotesUpdate(installedAppId, notes) | ||
| if err != nil { | ||
| impl.logger.Errorw("error in updating notes in db ", "err", err) | ||
| return notes, appName, err | ||
| } | ||
| } | ||
|
|
||
| return notes, appName, 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.
change the function name, fetchChartNotes
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.
done