Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: implement create facility api logic #20

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Deployment

on: push
on:
push:
branches: [develop]

concurrency:
group: build_and_push_image
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/savannahghi/scalarutils v0.0.4
github.com/savannahghi/serverutils v0.0.6
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/tj/assert v0.0.3
github.com/vektah/gqlparser/v2 v2.1.0
go.opencensus.io v0.23.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ func (db *PGInstance) CreateFacility(ctx context.Context, facility *Facility) (*
if err != nil {
return nil, fmt.Errorf("failed to create a facility: %v", err)
}
facilityResp := &Facility{
Name: facility.Name,
Code: facility.Code,
Active: facility.Active,
County: facility.County,
Description: facility.Description,
}

return facilityResp, nil
return facility, nil
}
2 changes: 1 addition & 1 deletion pkg/onboarding/infrastructure/database/postgres/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres/gorm"
)

// OnboardingDb struct implements ther service's business specific calls to the database
// OnboardingDb struct implements the service's business specific calls to the database
type OnboardingDb struct {
create gorm.Create
query gorm.Query
Expand Down
4 changes: 3 additions & 1 deletion pkg/onboarding/infrastructure/database/postgres/pg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres/gorm"
)

// CreateFacility ...
// CreateFacility is responsible from creating a representation of a facility
// A facility here is the healthcare facility that are on the platform.
// A facility MFL CODE must be unique across the platform. I forms part of the unique identifiers
func (d *OnboardingDb) CreateFacility(ctx context.Context, facility *dto.FacilityInput) (*domain.Facility, error) {

facilityObj := &gorm.Facility{
Expand Down
13 changes: 12 additions & 1 deletion pkg/onboarding/infrastructure/infrastructure.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package infrastructure

import (
"log"

"github.com/savannahghi/firebasetools"
pg "github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres"
"github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres/gorm"
baseExt "github.com/savannahghi/onboarding/pkg/onboarding/application/extension"
libUtils "github.com/savannahghi/onboarding/pkg/onboarding/application/utils"
libInfra "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure"
Expand All @@ -13,6 +17,8 @@ const (
engagementService = "engagement"
)

// Infrastructure is an implementation of the infrastructure interface
// It combines each individual service implementation
type Infrastructure struct {
Create
libOnboardingUsecase.LoginUseCases
Expand Down Expand Up @@ -44,7 +50,12 @@ func NewInteractor() Interactor {
signup := libOnboardingUsecase.NewSignUpUseCases(i, profile, userPinUseCase, baseExtension)
engagementClient := libUtils.NewInterServiceClient(engagementService, baseExtension)
engagement := engagementSvc.NewServiceEngagementImpl(engagementClient, baseExtension)
create := NewServicServiceCreateeEngagementImpl()
postgres, err := gorm.NewPGInstance()
if err != nil {
log.Fatal(err)
}
db := pg.NewOnboardingDb(postgres, postgres)
create := NewServiceCreateImpl(*db)

return Interactor{
create,
Expand Down
24 changes: 15 additions & 9 deletions pkg/onboarding/infrastructure/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ import (

"github.com/savannahghi/onboarding-service/pkg/onboarding/application/dto"
"github.com/savannahghi/onboarding-service/pkg/onboarding/domain"
pg "github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres"
)

// Create represents a contract that contains all `create` ops to the database
//
// All the contracts for create operations are assembled here
type Create interface {
CreateFacility(ctx context.Context, facility *dto.FacilityInput) (*domain.Facility, error)
CreateFacility(ctx context.Context, facility dto.FacilityInput) (*domain.Facility, error)
}

// ServiceEngagementImpl represents engagement usecases
type ServiceCreate struct {
Create Create
// ServiceCreateImpl represents create contract implementation object
type ServiceCreateImpl struct {
onboarding pg.OnboardingDb
}

// NewServiceEngagementImpl returns new instance of ServiceEngagementImpl
func NewServicServiceCreateeEngagementImpl() *ServiceCreate {
return &ServiceCreate{}
// NewServiceCreateImpl returns new instance of ServiceCreateImpl
func NewServiceCreateImpl(on pg.OnboardingDb) Create {
return &ServiceCreateImpl{
onboarding: on,
}
}

func (f ServiceCreate) CreateFacility(ctx context.Context, facility *dto.FacilityInput) (*domain.Facility, error) {
return f.Create.CreateFacility(ctx, facility)
// CreateFacility is responsible from creating a representation of a facility
func (f ServiceCreateImpl) CreateFacility(ctx context.Context, facility dto.FacilityInput) (*domain.Facility, error) {
return f.onboarding.CreateFacility(ctx, &facility)
}
7 changes: 6 additions & 1 deletion pkg/onboarding/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/99designs/gqlgen/graphql/handler"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
infra "github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure"
postgres "github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres"
"github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres/gorm"
"github.com/savannahghi/onboarding-service/pkg/onboarding/presentation/graph"
Expand Down Expand Up @@ -69,7 +70,11 @@ func Router(ctx context.Context) (*mux.Router, error) {

openSourceUsecases := osusecases.NewUsecasesInteractor(infrastructure, baseExt, pinExt)

var facilityUseCase facility.UseCasesFacility
// initialize internal infrastructure
infra := infra.NewInteractor()

// Initialize facility usecase
facilityUseCase := facility.NewFacilityUsecase(infra)
pg, err := gorm.NewPGInstance()
if err != nil {
return nil, fmt.Errorf("can't instantiate repository in resolver: %v", err)
Expand Down
2 changes: 0 additions & 2 deletions pkg/onboarding/presentation/graph/facility.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ package graph

import (
"context"
"log"

"github.com/savannahghi/onboarding-service/pkg/onboarding/application/dto"
"github.com/savannahghi/onboarding-service/pkg/onboarding/domain"
"github.com/savannahghi/onboarding-service/pkg/onboarding/presentation/graph/generated"
)

func (r *mutationResolver) CreateFacility(ctx context.Context, input dto.FacilityInput) (*domain.Facility, error) {
log.Printf("\n\n\n\n\n\n\n\n\n\nthis is where we are %v", input)
return r.interactor.FacilityUsecase.CreateFacility(ctx, input)
}

Expand Down
85 changes: 39 additions & 46 deletions pkg/onboarding/presentation/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/onboarding/presentation/graph/types.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

type Facility {
facilityID: Int
ID: Int!
name: String!
code: String!
active: Boolean!
Expand Down
21 changes: 0 additions & 21 deletions pkg/onboarding/presentation/graph/types.resolvers.go

This file was deleted.

Loading