fix: empty project by id (#393)

* fix: check if project found in by id

* fix: check length of events
This commit is contained in:
Silvan 2020-07-08 14:26:35 +02:00 committed by GitHub
parent 4b58097cca
commit 59ac7f051f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,17 +34,21 @@ type ProjectRepo struct {
}
func (repo *ProjectRepo) ProjectByID(ctx context.Context, id string) (*proj_model.ProjectView, error) {
project, err := repo.View.ProjectByID(id)
if err != nil && !caos_errs.IsNotFound(err) {
return nil, err
project, viewErr := repo.View.ProjectByID(id)
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
return nil, viewErr
}
if caos_errs.IsNotFound(err) {
if caos_errs.IsNotFound(viewErr) {
project = new(model.ProjectView)
}
events, err := repo.ProjectEvents.ProjectEventsByID(ctx, id, project.Sequence)
if err != nil {
logging.Log("EVENT-V9x1V").WithError(err).Debug("error retrieving new events")
events, esErr := repo.ProjectEvents.ProjectEventsByID(ctx, id, project.Sequence)
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
return nil, caos_errs.ThrowNotFound(nil, "EVENT-8yfKu", "Errors.Project.NotFound")
}
if esErr != nil {
logging.Log("EVENT-V9x1V").WithError(viewErr).Debug("error retrieving new events")
return model.ProjectToModel(project), nil
}