Adding approval process

This commit is contained in:
2023-07-03 17:26:43 -04:00
parent a43264189f
commit b1b010deee
15 changed files with 640 additions and 71 deletions

View File

@@ -0,0 +1,59 @@
package persistence
import (
"github.com/google/uuid"
svc "go.fixergrid.net/servicedemon/pkg/registrar/internal/services"
)
type FakeRepo struct {
apps []*svc.Application
}
func NewFakeRepo() *FakeRepo {
return &FakeRepo{
apps: make([]*svc.Application, 0),
}
}
func (repo FakeRepo) IsRegistered(name string) bool {
for _, app := range repo.apps {
if name == app.Name && app.State == "registered" {
return true
}
}
return false
}
func (repo FakeRepo) PendingApprovalCount() int {
count := 0
for _, app := range repo.apps {
if app.State == "pending_approval" {
count += 1
}
}
return count
}
func (repo *FakeRepo) StartAppRegistration(name string) uuid.UUID {
repo.apps = append(repo.apps, &svc.Application{
Name: name,
State: "pending_approval",
})
return uuid.New()
}
func (repo *FakeRepo) ApproveApp(id uuid.UUID) (svc.Application, error) {
var app *svc.Application
for _, application := range repo.apps {
if application.ID == id {
application.State = "registered"
}
}
if app == nil {
return svc.Application{}, svc.ErrApplicationNotFound
}
return *app, nil
}