pre-dev: initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of base-entity, results of the extraction of the attributes from the
|
||||
original entity.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
create several types according to the needs
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type Basic struct {
|
||||
Code string `json:"code" gorm:"uniqueIndex;not null;size:10"`
|
||||
Name string `json:"name" gorm:"not null;size:100"`
|
||||
}
|
||||
|
||||
type Default struct {
|
||||
Type_Code TypeCode `json:"type" gorm:"not null;size:10"`
|
||||
Status_Code StatusCode `json:"status" gorm:"not null;size:10"`
|
||||
}
|
||||
|
||||
type Extra struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type StatusCode string
|
||||
type TypeCode string
|
||||
|
||||
const (
|
||||
SCActive StatusCode = "active" // prefixed with SC that stands for StatusCode
|
||||
SCInactive StatusCode = "inactive"
|
||||
|
||||
TCPrimary TypeCode = "prim" // prefixed with TC that stands for TypeCode
|
||||
TCScondary TypeCode = "seco"
|
||||
TCTertiary TypeCode = "tert"
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of struct to define an entity both in the application and database.
|
||||
Uses the base struct from the core package for the standard attributes.
|
||||
|
||||
The sampel is part of the the workaround sample on how to avoid the
|
||||
circle-depency. The child is used to define the relationship for the database.
|
||||
|
||||
TODO:
|
||||
- replace 'child' with the name of the package, ie: myentity
|
||||
- replace 'Child' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package child
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
eb "simrs-vx/internal/domain/main-entities/child/base"
|
||||
ep "simrs-vx/internal/domain/main-entities/parent"
|
||||
)
|
||||
|
||||
type Child struct {
|
||||
ecore.Main
|
||||
eb.Basic
|
||||
Parent_Id int `json:"parent_id"`
|
||||
Pareng ep.Parent `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"`
|
||||
eb.Default
|
||||
eb.Extra
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of a case-entity that utilized the base according to the needs.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
replace 'child' with the name of the package, ie: myentity
|
||||
replace 'Child' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package child
|
||||
|
||||
import (
|
||||
eb "simrs-vx/internal/domain/main-entities/child/base"
|
||||
)
|
||||
|
||||
type Child struct {
|
||||
Id int `json:"id"` // in many cases the usage of
|
||||
eb.Basic
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of base-entity, results of the extraction of the attributes from the
|
||||
original entity.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
create several types according to the needs
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type Basic struct {
|
||||
Code string `json:"code" gorm:"uniqueIndex;not null;size:10"`
|
||||
Name string `json:"name" gorm:"not null;size:100"`
|
||||
}
|
||||
|
||||
type Default struct {
|
||||
Type_Code TypeCode `json:"type" gorm:"not null;size:10"`
|
||||
Status_Code StatusCode `json:"status" gorm:"not null;size:10"`
|
||||
}
|
||||
|
||||
type Extra struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type StatusCode string
|
||||
type TypeCode string
|
||||
|
||||
const (
|
||||
SCActive StatusCode = "active" // prefixed with SC that stands for StatusCode
|
||||
SCInactive StatusCode = "inactive"
|
||||
|
||||
TCPrimary TypeCode = "prim" // prefixed with TC that stands for TypeCode
|
||||
TCScondary TypeCode = "seco"
|
||||
TCTertiary TypeCode = "tert"
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of struct to define an entity both in the application and database.
|
||||
Uses the base struct from the core package for the standard attributes.
|
||||
|
||||
The sampel shows a workaround on how to avoid the circle-depency which is a
|
||||
common problem when it involves the parent-child relationship. By default,
|
||||
the relationship is defined in the child entity, and when the parent entity
|
||||
needs to use the child as an attribute (array for example), the circle-depency
|
||||
happens.
|
||||
|
||||
To avoid this problem, the parent will have a case-entity like 'full' entity,
|
||||
which embeds the 'base' and the 'child' structs.
|
||||
|
||||
TODO:
|
||||
- replace 'parent' with the name of the package, ie: myentity
|
||||
- replace 'Parent' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package parent
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
eb "simrs-vx/internal/domain/main-entities/parent/base"
|
||||
)
|
||||
|
||||
type Parent struct {
|
||||
ecore.Main
|
||||
eb.Basic
|
||||
eb.Default
|
||||
eb.Extra
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of a case-entity that utilized the base according to the needs. In this
|
||||
sample, it imports the child entity, and uses it as an attribute. And by
|
||||
separating this entity from the original entity, it avoids the circle dependency.
|
||||
|
||||
TODO:
|
||||
replace 'parent' with the name of the package, ie: patient
|
||||
replace 'Parent' with the name of the entity, ie: Patient
|
||||
*/
|
||||
package parent
|
||||
|
||||
import (
|
||||
ec "simrs-vx/internal/domain/main-entities/child"
|
||||
eb "simrs-vx/internal/domain/main-entities/parent/base"
|
||||
// ec "simrs-vx/internal/domain/main-entities/child/minimal" // can use other case
|
||||
)
|
||||
|
||||
type Parent struct {
|
||||
Id int `json:"id"`
|
||||
eb.Basic
|
||||
eb.Default
|
||||
Childs []ec.Child `json:"childs" gorm:"foreignKey:Parent_Id;references:Id"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of a case-entity that utilized the base according to the needs.
|
||||
|
||||
TODO:
|
||||
replace 'parent' with the name of the package, ie: patient
|
||||
replace 'Parent' with the name of the entity, ie: Patient
|
||||
*/
|
||||
package parent
|
||||
|
||||
import (
|
||||
eb "simrs-vx/internal/domain/main-entities/parent/base"
|
||||
)
|
||||
|
||||
type Parent struct {
|
||||
Id int `json:"id"`
|
||||
eb.Basic
|
||||
eb.Default
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of base-entity, results of the extraction of the attributes from the
|
||||
original entity.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
create several types according to the needs
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type Basic struct {
|
||||
Code string `json:"code" gorm:"uniqueIndex;not null;size:10"`
|
||||
Name string `json:"name" gorm:"not null;size:100"`
|
||||
}
|
||||
|
||||
type Default struct {
|
||||
Type_Code TypeCode `json:"type" gorm:"not null;size:10"`
|
||||
Status_Code StatusCode `json:"status" gorm:"not null;size:10"`
|
||||
}
|
||||
|
||||
type Extra struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains functions.
|
||||
*/
|
||||
package base
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (b *Basic) ExtractName() []string {
|
||||
return strings.Split(b.Name, " ")
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
*/
|
||||
package base // adjust this
|
||||
|
||||
type StatusCode string
|
||||
type TypeCode string
|
||||
|
||||
const (
|
||||
SCActive StatusCode = "active" // prefixed with SC that stands for StatusCode
|
||||
SCInactive StatusCode = "inactive"
|
||||
|
||||
TCPrimary TypeCode = "prim" // prefixed with TC that stands for TypeCode
|
||||
TCScondary TypeCode = "seco"
|
||||
TCTertiary TypeCode = "tert"
|
||||
)
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of struct to define an entity both in the application and database.
|
||||
Uses the base struct from the core package for the standard attributes.
|
||||
|
||||
The original attributes are extracted and grouped into several parts (structs),
|
||||
which later embeded. The extracted attributes are stored into the subdirectory
|
||||
'base'.
|
||||
|
||||
The extraction is done to cover several cases regarding the eficiency the of
|
||||
the data retreiving by using only needed attributes. Each case has its own
|
||||
directory with the same struct name with the main entity that embeds the
|
||||
needed attributes from the 'base'.
|
||||
|
||||
NOTES:
|
||||
Make sure to use 'case-sensitive' option when doing search-replace
|
||||
|
||||
TODO:
|
||||
- replace 'separated' with the name of the package, ie: myentity
|
||||
- replace 'Separated' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package separated
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
eb "simrs-vx/internal/domain/main-entities/separated/base"
|
||||
)
|
||||
|
||||
type Separated struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
eb.Basic
|
||||
eb.Default
|
||||
eb.Extra
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of a case-entity that utilized the base according to the needs.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
replace 'separated' with the name of the package, ie: myentity
|
||||
replace 'Separated' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package separated
|
||||
|
||||
import (
|
||||
eb "simrs-vx/internal/domain/main-entities/separated/base"
|
||||
)
|
||||
|
||||
type Separated struct {
|
||||
Id int `json:"id"`
|
||||
eb.Basic
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of a case-entity that utilized the base according to the needs.
|
||||
|
||||
NOTE:
|
||||
Make sure to use 'case-sensitive' option when searching
|
||||
|
||||
TODO:
|
||||
replace 'separated' with the name of the package, ie: myentity
|
||||
replace 'Separated' with the name of the entity, ie: MyEntity
|
||||
*/
|
||||
package separated
|
||||
|
||||
import (
|
||||
eb "simrs-vx/internal/domain/main-entities/separated/base"
|
||||
)
|
||||
|
||||
type Separated struct {
|
||||
Id int `json:"id"` // in many cases the usage of
|
||||
eb.Basic
|
||||
eb.Default
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package single
|
||||
|
||||
type Createdto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Updatedto struct {
|
||||
Id uint `json:"id"`
|
||||
Createdto
|
||||
}
|
||||
|
||||
type Deletedto struct {
|
||||
Id uint `json:"id"`
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Sample of struct to define an entity both in the application and database.
|
||||
Uses the base struct from the core package for the standard
|
||||
attributes.
|
||||
|
||||
NOTES:
|
||||
Make sure to use 'case-sensitive' option when doing search-replace
|
||||
|
||||
TODO:
|
||||
- replace 'single' with the name of the package, ie: 'patient'
|
||||
- replace 'Single' with the name of the entity, ie: 'Patient'
|
||||
*/
|
||||
package single
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
)
|
||||
|
||||
type Single struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"uniqueIndex;not null;size:10"`
|
||||
Name string `json:"name" gorm:"not null;size:100"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package actor
|
||||
|
||||
type Actor struct {
|
||||
CreatedBy_User_Id uint `json:"createdBy_user_id"`
|
||||
UpdatedBy_User_Id uint `json:"updatedBy_user_id"`
|
||||
DeletedBy_User_Id uint `json:"deletedBy_user_id"`
|
||||
}
|
||||
|
||||
type Owner struct {
|
||||
OwnedBy_User_Id uint `json:"ownedBy_user_id"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package core
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Base struct {
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
DeteledAt gorm.DeletedAt `json:"deletedAt,omitempty"`
|
||||
}
|
||||
|
||||
//
|
||||
type Main struct {
|
||||
Id uint `json:"id" gorm:"primaryKey"` // depends on the system architecture
|
||||
Base
|
||||
}
|
||||
|
||||
type TinyMain struct {
|
||||
Id uint8 `json:"id" gorm:"primaryKey"`
|
||||
Base
|
||||
}
|
||||
|
||||
type SmallMain struct {
|
||||
Id uint16 `json:"id" gorm:"primaryKey"`
|
||||
Base
|
||||
}
|
||||
|
||||
// Mainly for transaction
|
||||
type BigMain struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey"`
|
||||
Base
|
||||
}
|
||||
Reference in New Issue
Block a user