Skip to content

Commit

Permalink
InvocationRepository: return array of values instead of pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
dermetfan committed Jun 21, 2022
1 parent 79820a5 commit f9fa035
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/application/component/web/main.go
Expand Up @@ -389,7 +389,7 @@ func (self *Web) ActionIdRunGet(w http.ResponseWriter, req *http.Request) {

wg.Add(len(invocations))
for i, invocation := range invocations {
entries[i].Invocation = invocation
entries[i].Invocation = &invocation

go func(i int, id uuid.UUID) {
defer wg.Done()
Expand Down Expand Up @@ -720,7 +720,7 @@ func (self *Web) RunGet(w http.ResponseWriter, req *http.Request) {

wg.Add(len(invocations) * 2)
for i, invocation := range invocations {
entries[i].Invocation = invocation
entries[i].Invocation = &invocation

go func(i int, id uuid.UUID) {
defer wg.Done()
Expand Down
12 changes: 6 additions & 6 deletions src/application/service/invocation.go
Expand Up @@ -19,10 +19,10 @@ type InvocationService interface {
withQuerier(config.PgxIface, InvocationServiceCyclicDependencies) InvocationService

GetById(uuid.UUID) (*domain.Invocation, error)
GetByActionId(uuid.UUID, *repository.Page) ([]*domain.Invocation, error)
GetByActionId(uuid.UUID, *repository.Page) ([]domain.Invocation, error)
GetLatestByActionId(uuid.UUID) (*domain.Invocation, error)
GetAll(*repository.Page) ([]*domain.Invocation, error)
GetByInputFactIds([]*uuid.UUID, bool, *bool, *repository.Page) ([]*domain.Invocation, error)
GetAll(*repository.Page) ([]domain.Invocation, error)
GetByInputFactIds([]*uuid.UUID, bool, *bool, *repository.Page) ([]domain.Invocation, error)
GetInputFactIdsById(uuid.UUID) (map[string]uuid.UUID, error)
GetOutputById(uuid.UUID) (domain.OutputDefinition, error)
Save(*domain.Invocation, map[string]*domain.Fact) error
Expand Down Expand Up @@ -92,7 +92,7 @@ func (self invocationService) GetById(id uuid.UUID) (invocation *domain.Invocati
return
}

func (self invocationService) GetByActionId(id uuid.UUID, page *repository.Page) (invocations []*domain.Invocation, err error) {
func (self invocationService) GetByActionId(id uuid.UUID, page *repository.Page) (invocations []domain.Invocation, err error) {
self.logger.Trace().Str("id", id.String()).Int("offset", page.Offset).Int("limit", page.Limit).Msgf("Getting Invocation by Action ID")
invocations, err = self.invocationRepository.GetByActionId(id, page)
err = errors.WithMessagef(err, "Could not select existing Invocation by Action ID %q with offset %d and limit %d", id, page.Offset, page.Limit)
Expand All @@ -106,14 +106,14 @@ func (self invocationService) GetLatestByActionId(id uuid.UUID) (invocation *dom
return
}

func (self invocationService) GetAll(page *repository.Page) (invocations []*domain.Invocation, err error) {
func (self invocationService) GetAll(page *repository.Page) (invocations []domain.Invocation, err error) {
self.logger.Trace().Int("offset", page.Offset).Int("limit", page.Limit).Msg("Getting all Invocations")
invocations, err = self.invocationRepository.GetAll(page)
err = errors.WithMessagef(err, "Could not select existing Invocations with offset %d and limit %d", page.Offset, page.Limit)
return
}

func (self invocationService) GetByInputFactIds(factIds []*uuid.UUID, recursive bool, ok *bool, page *repository.Page) (invocations []*domain.Invocation, err error) {
func (self invocationService) GetByInputFactIds(factIds []*uuid.UUID, recursive bool, ok *bool, page *repository.Page) (invocations []domain.Invocation, err error) {
self.logger.Trace().Int("offset", page.Offset).Int("limit", page.Limit).Interface("input-fact-ids", factIds).Bool("recursive", recursive).Interface("ok", ok).Msg("Getting Invocations by input Fact IDs")
invocations, err = self.invocationRepository.GetByInputFactIds(factIds, recursive, ok, page)
errMsg := "Could not select Invocations by input fact IDs %q (recursively: %t, ok: "
Expand Down
6 changes: 3 additions & 3 deletions src/domain/repository/invocation.go
Expand Up @@ -11,11 +11,11 @@ type InvocationRepository interface {
WithQuerier(config.PgxIface) InvocationRepository

GetById(uuid.UUID) (*domain.Invocation, error)
GetByActionId(uuid.UUID, *Page) ([]*domain.Invocation, error)
GetByActionId(uuid.UUID, *Page) ([]domain.Invocation, error)
GetLatestByActionId(uuid.UUID) (*domain.Invocation, error)
GetInputFactIdsById(uuid.UUID) (map[string]uuid.UUID, error)
GetAll(*Page) ([]*domain.Invocation, error)
GetByInputFactIds([]*uuid.UUID, bool, *bool, *Page) ([]*domain.Invocation, error)
GetAll(*Page) ([]domain.Invocation, error)
GetByInputFactIds([]*uuid.UUID, bool, *bool, *Page) ([]domain.Invocation, error)
Save(*domain.Invocation, map[string]*domain.Fact) error
End(uuid.UUID) error
}
12 changes: 6 additions & 6 deletions src/infrastructure/persistence/invocation.go
Expand Up @@ -36,8 +36,8 @@ func (self *invocationRepository) GetById(id uuid.UUID) (*domain.Invocation, err
return invocation.(*domain.Invocation), err
}

func (self *invocationRepository) GetByActionId(id uuid.UUID, page *repository.Page) ([]*domain.Invocation, error) {
invocations := make([]*domain.Invocation, page.Limit)
func (self *invocationRepository) GetByActionId(id uuid.UUID, page *repository.Page) ([]domain.Invocation, error) {
invocations := make([]domain.Invocation, page.Limit)
return invocations, fetchPage(
self.db, page, &invocations,
`*`, `invocation WHERE action_id = $1`, `created_at DESC`,
Expand Down Expand Up @@ -85,16 +85,16 @@ func (self *invocationRepository) GetInputFactIdsById(id uuid.UUID) (inputFactId
return
}

func (self *invocationRepository) GetAll(page *repository.Page) ([]*domain.Invocation, error) {
invocations := make([]*domain.Invocation, page.Limit)
func (self *invocationRepository) GetAll(page *repository.Page) ([]domain.Invocation, error) {
invocations := make([]domain.Invocation, page.Limit)
return invocations, fetchPage(
self.db, page, &invocations,
`*`, `invocation`, `created_at DESC`,
)
}

// `ok`: Allows to filter for successful or failed invocations.
func (self *invocationRepository) GetByInputFactIds(factIds []*uuid.UUID, recursive bool, ok *bool, page *repository.Page) ([]*domain.Invocation, error) {
func (self *invocationRepository) GetByInputFactIds(factIds []*uuid.UUID, recursive bool, ok *bool, page *repository.Page) ([]domain.Invocation, error) {
joins := ``
for i := range factIds {
iStr := strconv.Itoa(i + 1)
Expand Down Expand Up @@ -153,7 +153,7 @@ func (self *invocationRepository) GetByInputFactIds(factIds []*uuid.UUID, recurs
from = `(SELECT invocation.* FROM invocation ` + joins + whereOk + `) AS invocation`
}

invocations := make([]*domain.Invocation, page.Limit)
invocations := make([]domain.Invocation, page.Limit)
return invocations, fetchPage(
self.db, page, &invocations,
`invocation.*`, from, `created_at`,
Expand Down

0 comments on commit f9fa035

Please sign in to comment.