Skip to content

Commit

Permalink
Merge pull request #1 from tonybka/feature/tonybka/init-code
Browse files Browse the repository at this point in the history
Init code base
  • Loading branch information
tonybka authored Dec 18, 2022
2 parents bc7737a + 17c4623 commit c6976d8
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
11 changes: 11 additions & 0 deletions entity/base_aggregate_root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package entity

import "github.com/tonybka/go-base-ddd/event"

type BaseAggregateRoot struct {
BaseEntity
}

func (aggregate *BaseAggregateRoot) AddEvent(event event.IBaseDomainEvent) {

}
7 changes: 7 additions & 0 deletions entity/base_entity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package entity

import "github.com/google/uuid"

type BaseEntity struct {
ID uuid.UUID
}
4 changes: 4 additions & 0 deletions event/base_domain_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package event

type IBaseDomainEvent struct {
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tonybka/go-base-ddd

go 1.18

require github.com/google/uuid v1.3.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
51 changes: 51 additions & 0 deletions gorm/custom_type_uuidv1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gorm

import (
"database/sql/driver"

"github.com/google/uuid"
)

type CustomTypeUUIDv1 uuid.UUID

// NewCustomTypeUUIDv1FromString -> parse string to CustomTypeUUIDv1
func NewCustomTypeUUIDv1FromString(s string) (CustomTypeUUIDv1, error) {
id, err := uuid.Parse(s)
return CustomTypeUUIDv1(id), err
}

//String -> String Representation of Binary16
func (my CustomTypeUUIDv1) String() string {
return uuid.UUID(my).String()
}

//GormDataType -> sets type to binary(16)
func (my CustomTypeUUIDv1) GormDataType() string {
return "binary(16)"
}

func (my CustomTypeUUIDv1) MarshalJSON() ([]byte, error) {
s := uuid.UUID(my)
str := "\"" + s.String() + "\""
return []byte(str), nil
}

func (my *CustomTypeUUIDv1) UnmarshalJSON(by []byte) error {
s, err := uuid.ParseBytes(by)
*my = CustomTypeUUIDv1(s)
return err
}

// Scan --> tells GORM how to receive from the database
func (my *CustomTypeUUIDv1) Scan(value interface{}) error {

bytes, _ := value.([]byte)
parseByte, err := uuid.FromBytes(bytes)
*my = CustomTypeUUIDv1(parseByte)
return err
}

// Value -> tells GORM how to save into the database
func (my CustomTypeUUIDv1) Value() (driver.Value, error) {
return uuid.UUID(my).MarshalBinary()
}
8 changes: 8 additions & 0 deletions value_object/string_value_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package valueobject

import "fmt"

type IStringValueObject interface {
fmt.Stringer
Equals(value IStringValueObject) bool
}

0 comments on commit c6976d8

Please sign in to comment.