Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Vitanov committed Jul 11, 2024
1 parent 7b0e6aa commit 588a45f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 45 deletions.
8 changes: 4 additions & 4 deletions core/app_delete_data_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions core/interfaces/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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)
CreateSurveyResponse(surveyResponse model.SurveyResponse) (*model.SurveyResponse, error)
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)
Expand Down
20 changes: 10 additions & 10 deletions core/interfaces/mocks/Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions core/model/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions driven/core/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions driven/storage/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}},
}

Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 588a45f

Please sign in to comment.