Skip to content

Commit

Permalink
move function
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Oct 17, 2023
1 parent 49b24c1 commit fa97606
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions pkg/usecase/apiserver/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,6 @@ func (s *Service) createApplicationDatabase(ctx context.Context, app *domain.App
return nil
}

func (s *Service) deleteApplicationDatabase(ctx context.Context, app *domain.Application, envs []*domain.Environment) error {
if app.Config.BuildConfig.MariaDB() {
dbKey, ok := lo.Find(envs, func(e *domain.Environment) bool { return e.Key == domain.EnvMariaDBDatabaseKey })
if !ok {
return errors.New("failed to find mariadb name from env key")
}
err := s.mariaDBManager.Delete(ctx, domain.DeleteArgs{Database: dbKey.Value})
if err != nil {
return err
}
}

if app.Config.BuildConfig.MongoDB() {
dbKey, ok := lo.Find(envs, func(e *domain.Environment) bool { return e.Key == domain.EnvMongoDBDatabaseKey })
if !ok {
return errors.New("failed to find mongodb name from env key")
}
err := s.mongoDBManager.Delete(ctx, domain.DeleteArgs{Database: dbKey.Value})
if err != nil {
return err
}
}

return nil
}

type TopAppInfo struct {
App *domain.Application
LatestBuild *domain.Build
Expand Down Expand Up @@ -274,6 +248,32 @@ func (s *Service) UpdateApplication(ctx context.Context, id string, args *domain
return nil
}

func (s *Service) deleteApplicationDatabase(ctx context.Context, app *domain.Application, envs []*domain.Environment) error {
if app.Config.BuildConfig.MariaDB() {
dbKey, ok := lo.Find(envs, func(e *domain.Environment) bool { return e.Key == domain.EnvMariaDBDatabaseKey })
if !ok {
return errors.New("failed to find mariadb name from env key")
}
err := s.mariaDBManager.Delete(ctx, domain.DeleteArgs{Database: dbKey.Value})
if err != nil {
return err
}
}

if app.Config.BuildConfig.MongoDB() {
dbKey, ok := lo.Find(envs, func(e *domain.Environment) bool { return e.Key == domain.EnvMongoDBDatabaseKey })
if !ok {
return errors.New("failed to find mongodb name from env key")
}
err := s.mongoDBManager.Delete(ctx, domain.DeleteArgs{Database: dbKey.Value})
if err != nil {
return err
}
}

return nil
}

func (s *Service) DeleteApplication(ctx context.Context, id string) error {
err := s.isApplicationOwner(ctx, id)
if err != nil {
Expand Down

0 comments on commit fa97606

Please sign in to comment.