Skip to content

Commit

Permalink
chore: change uuid to type string
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Oct 18, 2021
1 parent 8172a56 commit 56370cf
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 177 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/imroc/req v0.3.0
github.com/lib/pq v1.10.3
github.com/savannahghi/converterandformatter v0.0.9
github.com/savannahghi/enumutils v0.0.3
github.com/savannahghi/feedlib v0.0.4
Expand Down
36 changes: 19 additions & 17 deletions pkg/onboarding/domain/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/savannahghi/feedlib"
"gorm.io/datatypes"
)

Expand All @@ -12,7 +13,7 @@ import (
// e.g CCC clinics, Pharmacies.
type Facility struct {
// ID is the Global facility ID(GCID)
ID uuid.UUID
ID *string
// unique within this structure
Name string
// MFL Code for Kenyan facilities, globally unique
Expand Down Expand Up @@ -42,7 +43,7 @@ type Facility struct {
//
// Client and Staff cannot exist without being a user
type User struct {
ID uuid.UUID // globally unique ID
ID *string // globally unique ID

Username string // @handle, also globally unique; nickname

Expand Down Expand Up @@ -82,6 +83,7 @@ type User struct {

TermsAccepted bool
AcceptedTermsID string // foreign key to version of terms they accepted
Flavour feedlib.Flavour
}

// AuthCredentials is the authentication credentials for a given user
Expand All @@ -95,7 +97,7 @@ type AuthCredentials struct {

// UserPIN is used to store users' PINs and their entire change history.
type UserPIN struct {
UserID string // TODO: At the DB, this should be indexed
UserID *string // TODO: At the DB, this should be indexed

HashedPIN string
ValidFrom time.Time
Expand Down Expand Up @@ -129,7 +131,7 @@ type Identifier struct {
//It is a linkage model e.g to tie together all of a person's identifiers
// and their health record ID
type ClientProfile struct {
ID uuid.UUID // globally unique identifier; synthetic i.e has no encoded meaning
ID *string // globally unique identifier; synthetic i.e has no encoded meaning

// every client is a user first
// biodata is linked to the user record
Expand All @@ -148,7 +150,7 @@ type ClientProfile struct {
// (implement reverse relation lookup)
Identifiers []*Identifier

Addresses []*Address
Addresses []*UserAddress

RelatedPersons []*RelatedPerson // e.g next of kin

Expand All @@ -162,9 +164,9 @@ type ClientProfile struct {
ClientCounselled bool
}

// Address are value objects for user address e.g postal code
type Address struct {
ID string
// UserAddress are value objects for user UserAddress e.g postal code
type UserAddress struct {
ID *string

Type string // TODO: enum; postal, physical or both
Text string // actual address, can be multi-line
Expand All @@ -178,7 +180,7 @@ type Address struct {
//
// It servers as Next of Kin details
type RelatedPerson struct {
ID string
ID *string

Active bool
RelatedTo string // TODO: FK to client
Expand All @@ -188,9 +190,9 @@ type RelatedPerson struct {
OtherName string // TODO: optional
Gender string // TODO: enum

DateOfBirth *time.Time // TODO: optional
Addresses []*Address // TODO: optional
Contacts []*Contact // TODO: optional
DateOfBirth *time.Time // TODO: optional
Addresses []*UserAddress // TODO: optional
Contacts []*Contact // TODO: optional
}

// ClientProfileRegistrationPayload holds the registration input we need to register a client
Expand All @@ -200,13 +202,13 @@ type ClientProfileRegistrationPayload struct {
// every client is a user first
// biodata is linked to the user record
// the client record is for bridging to other identifiers e.g patient record IDs
UserID uuid.UUID // TODO: Foreign key to User
UserID *string // TODO: Foreign key to User

ClientType string // TODO: enum; e.g PMTCT, OVC

PrimaryIdentifier *Identifier // TODO: optional, default set if not givemn

Addresses []*Address
Addresses []*UserAddress

FacilityID uuid.UUID

Expand All @@ -219,7 +221,7 @@ type ClientProfileRegistrationPayload struct {

// Contact hold contact information/details for users
type Contact struct {
ID string
ID *string

Type string // TODO enum

Expand All @@ -235,7 +237,7 @@ type Contact struct {
// Metric reprents the metrics data structure input
type Metric struct {
// ensures we don't re-save the same metric; opaque; globally unique
MetricID uuid.UUID
MetricID *string

// TODO Metric types should be a controlled list i.e enum
Type MetricType
Expand Down Expand Up @@ -269,5 +271,5 @@ type StaffProfile struct {
// there is nothing special about super-admin; just the set of roles they have
Roles []string // TODO: roles are an enum (controlled list), known to both FE and BE

Addresses []*Address
Addresses []*UserAddress
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// This mock struct should be separate from our own internal methods.
type GormMock struct {
GetOrCreateFacilityFn func(ctx context.Context, facility *gorm.Facility) (*gorm.Facility, error)
RetrieveFacilityFn func(ctx context.Context, id *uuid.UUID, isActive bool) (*gorm.Facility, error)
RetrieveFacilityFn func(ctx context.Context, id *string, isActive bool) (*gorm.Facility, error)
RetrieveFacilityByMFLCodeFn func(ctx context.Context, MFLCode string, isActive bool) (*gorm.Facility, error)
GetFacilitiesFn func(ctx context.Context) ([]gorm.Facility, error)
DeleteFacilityFn func(ctx context.Context, mfl_code string) (bool, error)
Expand All @@ -28,7 +28,7 @@ type GormMock struct {
func NewGormMock() *GormMock {
return &GormMock{
GetOrCreateFacilityFn: func(ctx context.Context, facility *gorm.Facility) (*gorm.Facility, error) {
id := uuid.New()
id := uuid.New().String()
name := "Kanairo One"
code := "KN001"
county := "Kanairo"
Expand All @@ -43,8 +43,8 @@ func NewGormMock() *GormMock {
}, nil
},

RetrieveFacilityFn: func(ctx context.Context, id *uuid.UUID, isActive bool) (*gorm.Facility, error) {
facilityID := uuid.New()
RetrieveFacilityFn: func(ctx context.Context, id *string, isActive bool) (*gorm.Facility, error) {
facilityID := uuid.New().String()
name := "Kanairo One"
code := "KN001"
county := "Kanairo"
Expand All @@ -60,7 +60,7 @@ func NewGormMock() *GormMock {
},
GetFacilitiesFn: func(ctx context.Context) ([]gorm.Facility, error) {
var facilities []gorm.Facility
facilityID := uuid.New()
facilityID := uuid.New().String()
name := "Kanairo One"
code := "KN001"
county := "Kanairo"
Expand All @@ -82,7 +82,7 @@ func NewGormMock() *GormMock {

CollectMetricsFn: func(ctx context.Context, metrics *gorm.Metric) (*gorm.Metric, error) {
now := time.Now()
metricID := uuid.New()
metricID := uuid.New().String()
return &gorm.Metric{
MetricID: &metricID,
Type: domain.EngagementMetrics,
Expand All @@ -93,7 +93,7 @@ func NewGormMock() *GormMock {
},

RetrieveFacilityByMFLCodeFn: func(ctx context.Context, MFLCode string, isActive bool) (*gorm.Facility, error) {
facilityID := uuid.New()
facilityID := uuid.New().String()
name := "Kanairo One"
code := "KN001"
county := "Kanairo"
Expand All @@ -116,7 +116,7 @@ func (gm *GormMock) GetOrCreateFacility(ctx context.Context, facility *gorm.Faci
}

// RetrieveFacility mocks the implementation of `gorm's` RetrieveFacility method.
func (gm *GormMock) RetrieveFacility(ctx context.Context, id *uuid.UUID, isActive bool) (*gorm.Facility, error) {
func (gm *GormMock) RetrieveFacility(ctx context.Context, id *string, isActive bool) (*gorm.Facility, error) {
return gm.RetrieveFacilityFn(ctx, id, isActive)
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/onboarding/infrastructure/database/postgres/gorm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ import (
"fmt"
"log"
"strconv"

"github.com/google/uuid"
)

// Query contains all the db query methods
type Query interface {
RetrieveFacility(ctx context.Context, id *uuid.UUID, isActive bool) (*Facility, error)
RetrieveFacility(ctx context.Context, id *string, isActive bool) (*Facility, error)
RetrieveFacilityByMFLCode(ctx context.Context, MFLCode string, isActive bool) (*Facility, error)
GetFacilities(ctx context.Context) ([]Facility, error)
}

// RetrieveFacility fetches a single facility
func (db *PGInstance) RetrieveFacility(ctx context.Context, id *uuid.UUID, isActive bool) (*Facility, error) {
func (db *PGInstance) RetrieveFacility(ctx context.Context, id *string, isActive bool) (*Facility, error) {
var facility Facility
active := strconv.FormatBool(isActive)
err := db.DB.Where(&Facility{FacilityID: id, Active: active}).Find(&facility).Error
Expand All @@ -32,7 +30,7 @@ func (db *PGInstance) RetrieveFacilityByMFLCode(ctx context.Context, MFLCode str
var facility Facility
active := strconv.FormatBool(isActive)
if err := db.DB.Where(&Facility{Code: MFLCode, Active: active}).First(&facility).Error; err != nil {
return nil, fmt.Errorf("failed to get facility by MFL Code %v: %v", MFLCode, err)
return nil, fmt.Errorf("failed to get facility by MFL Code %v and status %v: %v", MFLCode, active, err)
}
return &facility, nil
}
Expand Down
Loading

0 comments on commit 56370cf

Please sign in to comment.