fix: app by id, views with computed objects (#583)

* feat: read app by id if my events

* fix: handlers if no sublist

* fix: removed app

* fix: removed project

* fix: removed app

* fix: removed app

* fix: app by id with projectid
This commit is contained in:
Fabi
2020-08-13 08:28:18 +02:00
committed by GitHub
parent 2f404be7c6
commit 5c4fef296f
18 changed files with 71 additions and 14 deletions

View File

@@ -9,9 +9,11 @@ import (
"github.com/jinzhu/gorm"
)
func ApplicationByID(db *gorm.DB, table, appID string) (*model.ApplicationView, error) {
func ApplicationByID(db *gorm.DB, table, projectID, appID string) (*model.ApplicationView, error) {
app := new(model.ApplicationView)
query := repository.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID)
projectIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
appIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyAppID, Value: appID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, appIDQuery)
err := query(db, app)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DGdfx", "Errors.Application.NotFound")

View File

@@ -130,6 +130,32 @@ func ApplicationViewsToModel(roles []*ApplicationView) []*model.ApplicationView
return result
}
func (a *ApplicationView) AppendEventIfMyApp(event *models.Event) (err error) {
view := new(ApplicationView)
switch event.Type {
case es_model.ApplicationAdded:
err = view.SetData(event)
case es_model.ApplicationChanged,
es_model.OIDCConfigAdded,
es_model.OIDCConfigChanged,
es_model.ApplicationDeactivated,
es_model.ApplicationReactivated:
err := view.SetData(event)
if err != nil {
return err
}
case es_model.ApplicationRemoved:
return view.SetData(event)
case es_model.ProjectRemoved:
return a.AppendEvent(event)
default:
return nil
}
if view.ID == a.ID {
return a.AppendEvent(event)
}
return nil
}
func (a *ApplicationView) AppendEvent(event *models.Event) (err error) {
a.Sequence = event.Sequence
a.ChangeDate = event.CreationDate
@@ -156,6 +182,8 @@ func (a *ApplicationView) AppendEvent(event *models.Event) (err error) {
a.State = int32(model.AppStateInactive)
case es_model.ApplicationReactivated:
a.State = int32(model.AppStateActive)
case es_model.ApplicationRemoved, es_model.ProjectRemoved:
a.State = int32(model.AppStateRemoved)
}
return err
}