From 588a45feb16e0660c31fc4d6efb876bf9539c2bb Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Thu, 11 Jul 2024 12:30:05 +0300 Subject: [PATCH] resolve comments --- core/app_delete_data_logic.go | 8 ++++---- core/application.go | 2 +- core/application_test.go | 2 +- core/interfaces/driven.go | 4 ++-- core/interfaces/mocks/Storage.go | 20 ++++++++++---------- core/model/surveys.go | 12 ------------ driven/core/adapter.go | 7 ++----- driven/storage/adapter.go | 10 +++------- main.go | 4 +--- 9 files changed, 24 insertions(+), 45 deletions(-) diff --git a/core/app_delete_data_logic.go b/core/app_delete_data_logic.go index 20cecb3..1e6383a 100644 --- a/core/app_delete_data_logic.go +++ b/core/app_delete_data_logic.go @@ -144,20 +144,20 @@ func (d deleteDataLogic) processDelete() { d.logger.Infof("accounts for deletion - %s", accountsIDs) //delete the data - d.deleteAppOrgUsersData(appOrgSection.AppID, appOrgSection.OrgID, accountsIDs) + d.deleteAppOrgUsersData(accountsIDs) } } -func (d deleteDataLogic) deleteAppOrgUsersData(appID string, orgID string, accountsIDs []string) { +func (d deleteDataLogic) deleteAppOrgUsersData(accountsIDs []string) { // delete survey responses - err := d.storage.DeleteSurveyResponsesWithIDs(appID, orgID, accountsIDs) + err := d.storage.DeleteSurveyResponsesWithIDs(accountsIDs) if err != nil { d.logger.Errorf("error deleting the survey responses - %s", err) return } // delete surveys - err = d.storage.DeleteSurveysWithIDs(appID, orgID, accountsIDs) + err = d.storage.DeleteSurveysWithIDs(accountsIDs) if err != nil { d.logger.Errorf("error deleting the surveys - %s", err) return diff --git a/core/application.go b/core/application.go index 1334372..d9352ae 100644 --- a/core/application.go +++ b/core/application.go @@ -19,7 +19,7 @@ import ( "application/core/model" corebb "application/driven/core" - "github.com/rokwire/core-auth-library-go/v2/authutils" + "github.com/rokwire/core-auth-library-go/v3/authutils" "github.com/rokwire/logging-library-go/v2/errors" "github.com/rokwire/logging-library-go/v2/logs" "github.com/rokwire/logging-library-go/v2/logutils" diff --git a/core/application_test.go b/core/application_test.go index 767e262..77b7bfd 100644 --- a/core/application_test.go +++ b/core/application_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/mock" - "github.com/rokwire/core-auth-library-go/v2/authutils" + "github.com/rokwire/core-auth-library-go/v3/authutils" "github.com/rokwire/logging-library-go/v2/logs" ) diff --git a/core/interfaces/driven.go b/core/interfaces/driven.go index 88c26e5..7c36ecb 100644 --- a/core/interfaces/driven.go +++ b/core/interfaces/driven.go @@ -37,7 +37,7 @@ type Storage interface { CreateSurvey(survey model.Survey) (*model.Survey, error) UpdateSurvey(survey model.Survey, admin bool) error DeleteSurvey(id string, orgID string, appID string, creatorID string, admin bool) error - DeleteSurveysWithIDs(appID string, orgID string, accountsIDs []string) error + DeleteSurveysWithIDs(accountsIDs []string) error GetSurveyResponse(id string, orgID string, appID string, userID string) (*model.SurveyResponse, error) GetSurveyResponses(orgID *string, appID *string, userID *string, surveyIDs []string, surveyTypes []string, startDate *time.Time, endDate *time.Time, limit *int, offset *int) ([]model.SurveyResponse, error) @@ -45,7 +45,7 @@ type Storage interface { UpdateSurveyResponse(surveyResponse model.SurveyResponse) error DeleteSurveyResponse(id string, orgID string, appID string, userID string) error DeleteSurveyResponses(orgID string, appID string, userID string, surveyIDs []string, surveyTypes []string, startDate *time.Time, endDate *time.Time) error - DeleteSurveyResponsesWithIDs(appID string, orgID string, accountsIDs []string) error + DeleteSurveyResponsesWithIDs(accountsIDs []string) error GetAlertContacts(orgID string, appID string) ([]model.AlertContact, error) GetAlertContact(id string, orgID string, appID string) (*model.AlertContact, error) diff --git a/core/interfaces/mocks/Storage.go b/core/interfaces/mocks/Storage.go index 0995ba1..ce2a1bd 100644 --- a/core/interfaces/mocks/Storage.go +++ b/core/interfaces/mocks/Storage.go @@ -197,17 +197,17 @@ func (_m *Storage) DeleteSurveyResponses(orgID string, appID string, userID stri return r0 } -// DeleteSurveyResponsesWithIDs provides a mock function with given fields: appID, orgID, accountsIDs -func (_m *Storage) DeleteSurveyResponsesWithIDs(appID string, orgID string, accountsIDs []string) error { - ret := _m.Called(appID, orgID, accountsIDs) +// DeleteSurveyResponsesWithIDs provides a mock function with given fields: accountsIDs +func (_m *Storage) DeleteSurveyResponsesWithIDs(accountsIDs []string) error { + ret := _m.Called(accountsIDs) if len(ret) == 0 { panic("no return value specified for DeleteSurveyResponsesWithIDs") } var r0 error - if rf, ok := ret.Get(0).(func(string, string, []string) error); ok { - r0 = rf(appID, orgID, accountsIDs) + if rf, ok := ret.Get(0).(func([]string) error); ok { + r0 = rf(accountsIDs) } else { r0 = ret.Error(0) } @@ -215,17 +215,17 @@ func (_m *Storage) DeleteSurveyResponsesWithIDs(appID string, orgID string, acco return r0 } -// DeleteSurveysWithIDs provides a mock function with given fields: appID, orgID, accountsIDs -func (_m *Storage) DeleteSurveysWithIDs(appID string, orgID string, accountsIDs []string) error { - ret := _m.Called(appID, orgID, accountsIDs) +// DeleteSurveysWithIDs provides a mock function with given fields: accountsIDs +func (_m *Storage) DeleteSurveysWithIDs(accountsIDs []string) error { + ret := _m.Called(accountsIDs) if len(ret) == 0 { panic("no return value specified for DeleteSurveysWithIDs") } var r0 error - if rf, ok := ret.Get(0).(func(string, string, []string) error); ok { - r0 = rf(appID, orgID, accountsIDs) + if rf, ok := ret.Get(0).(func([]string) error); ok { + r0 = rf(accountsIDs) } else { r0 = ret.Error(0) } diff --git a/core/model/surveys.go b/core/model/surveys.go index aea6439..3b3eec5 100644 --- a/core/model/surveys.go +++ b/core/model/surveys.go @@ -165,15 +165,3 @@ type DeletedMembership struct { AccountID string `json:"account_id"` Context *map[string]interface{} `json:"context,omitempty"` } - -// CoreAccount represents an account in the Core BB -type CoreAccount struct { - ID string `json:"id" bson:"id"` - Profile CoreProfile `json:"profile" bson:"profile"` -} //@name CoreAccount - -// CoreProfile represents a profile in the Core BB -type CoreProfile struct { - FirstName string `json:"first_name" bson:"first_name"` - LastName string `json:"last_name" bson:"last_name"` -} //@name CoreProfile diff --git a/driven/core/adapter.go b/driven/core/adapter.go index 15f7b21..7baeb7b 100644 --- a/driven/core/adapter.go +++ b/driven/core/adapter.go @@ -32,14 +32,11 @@ type Adapter struct { logger logs.Logger coreURL string serviceAccountManager *authservice.ServiceAccountManager - - appID string - orgID string } // NewCoreAdapter creates a new adapter for Core API -func NewCoreAdapter(coreURL string, orgID string, appID string, serviceAccountManager *authservice.ServiceAccountManager) *Adapter { - return &Adapter{coreURL: coreURL, appID: appID, orgID: orgID, serviceAccountManager: serviceAccountManager} +func NewCoreAdapter(coreURL string, serviceAccountManager *authservice.ServiceAccountManager) *Adapter { + return &Adapter{coreURL: coreURL, serviceAccountManager: serviceAccountManager} } // LoadDeletedMemberships loads deleted memberships diff --git a/driven/storage/adapter.go b/driven/storage/adapter.go index 242d63c..dde6746 100644 --- a/driven/storage/adapter.go +++ b/driven/storage/adapter.go @@ -252,11 +252,9 @@ func (a *Adapter) DeleteConfig(id string) error { } // DeleteSurveyResponsesWithIDs Deletes survey responses -func (a Adapter) DeleteSurveyResponsesWithIDs(appID string, orgID string, accountsIDs []string) error { +func (a Adapter) DeleteSurveyResponsesWithIDs(accountsIDs []string) error { filter := bson.D{ - primitive.E{Key: "app_id", Value: appID}, - primitive.E{Key: "org_id", Value: orgID}, - primitive.E{Key: "creator_id", Value: bson.M{"$in": accountsIDs}}, + primitive.E{Key: "user_id", Value: bson.M{"$in": accountsIDs}}, } _, err := a.db.surveyResponses.DeleteMany(nil, filter, nil) @@ -267,10 +265,8 @@ func (a Adapter) DeleteSurveyResponsesWithIDs(appID string, orgID string, accoun } // DeleteSurveysWithIDs Deletes surveys -func (a Adapter) DeleteSurveysWithIDs(appID string, orgID string, accountsIDs []string) error { +func (a Adapter) DeleteSurveysWithIDs(accountsIDs []string) error { filter := bson.D{ - primitive.E{Key: "app_id", Value: appID}, - primitive.E{Key: "org_id", Value: orgID}, primitive.E{Key: "creator_id", Value: bson.M{"$in": accountsIDs}}, } diff --git a/main.go b/main.go index 9a71b32..a5e0f89 100644 --- a/main.go +++ b/main.go @@ -68,8 +68,6 @@ func main() { // Service registration baseURL := envLoader.GetAndLogEnvVar(envPrefix+"BASE_URL", true, false) coreBBBaseURL := envLoader.GetAndLogEnvVar(envPrefix+"CORE_BB_BASE_URL", true, false) - appID := envLoader.GetAndLogEnvVar(envPrefix+"APP_ID", true, false) - orgID := envLoader.GetAndLogEnvVar(envPrefix+"ORG_ID", true, false) authService := authservice.AuthService{ ServiceID: serviceID, @@ -143,7 +141,7 @@ func main() { } //core adapter - coreAdapter := corebb.NewCoreAdapter(coreBBBaseURL, orgID, appID, serviceAccountManager) + coreAdapter := corebb.NewCoreAdapter(coreBBBaseURL, serviceAccountManager) // Application application := core.NewApplication(Version, Build, storageAdapter, notificationsAdapter,