fix: return emtpy project if no project in view (#379)

* fix: return emtpy project if no project in view

* fix: new project if nil

* fix: easier to read
This commit is contained in:
Silvan 2020-07-07 19:28:19 +02:00 committed by GitHub
parent 837d7cc770
commit 5081ff21b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -40,6 +40,9 @@ func (repo *ProjectRepo) ProjectByID(ctx context.Context, id string) (*proj_mode
if err != nil && !caos_errs.IsNotFound(err) {
return nil, err
}
if caos_errs.IsNotFound(err) {
project = new(model.ProjectView)
}
events, err := repo.ProjectEvents.ProjectEventsByID(ctx, id, project.Sequence)
if err != nil {

View File

@ -24,7 +24,7 @@ func ProjectByID(db *gorm.DB, table, projectID string) (*model.ProjectView, erro
func ProjectsByResourceOwner(db *gorm.DB, table, orgID string) ([]*model.ProjectView, error) {
projects := make([]*model.ProjectView, 0)
queries := []*proj_model.ProjectViewSearchQuery{
&proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals},
{Key: proj_model.ProjectViewSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, model.ProjectSearchRequest{Queries: queries})
_, err := query(db, &projects)