diff --git a/commands/license_handler.go b/commands/license_handler.go new file mode 100644 index 0000000..2ea163d --- /dev/null +++ b/commands/license_handler.go @@ -0,0 +1,48 @@ +package commands + +import ( + "netina/models" + l "netina/repositories/license" + "time" +) + + +type CreateLicenseHandler struct { + Repository l.LicenseCommandRepository +} + + +func(r *CreateLicenseHandler) Handle (command models.CreateLicenseCommand) error { + license := &models.License{ + Plan_id: command.Plan_id, + Period: command.Period, + Created_at: time.Now(), + Modified_by: command.Modified_by, + } + + return r.Repository.CreateLicense(license) +} + + +type UpdateLicenseHandler struct { + Repository l.LicenseCommandRepository +} + + +func (r *UpdateLicenseHandler) Handle (id uint , command models.UpdateLicenseCommand) (*models.License , error) { + license := &models.License{ + Plan_id: command.Plan_id, + Period: command.Period, + Modified_by: command.Modified_by, + } + + return r.Repository.UpdateLicense(id , license) +} + + type RemoveLicenseHandler struct { + Repository l.LicenseCommandRepository + } + + func ( r *RemoveLicenseHandler) Handle (id uint) error { + return r.Repository.RemoveLicense(id) + } \ No newline at end of file diff --git a/commands/owner_handler.go b/commands/owner_handler.go new file mode 100644 index 0000000..f2ef433 --- /dev/null +++ b/commands/owner_handler.go @@ -0,0 +1,54 @@ +package commands + +import ( + "netina/models" + o "netina/repositories/owner" + "time" +) + + +type CreateOwnerHandler struct{ + Repository o.OwnerCommandRepository +} + +func (r *CreateOwnerHandler) Handle(command models.CreateOwnerCommand) error { + owner := &models.Owner{ + PhoneNumber: command.PhoneNumber, + FirstName: command.FirstName, + LastName: command.LastName, + NationalCode: command.NationalCode, + Created_at: time.Now(), + Modified_by: command.Modified_by, + } + + return r.Repository.CreateOwner(owner) +} + + +type UpdateOwnerHandler struct { + Repository o.OwnerCommandRepository +} + + +func (r *UpdateOwnerHandler) Handle(id uint , command models.UpdateOwnerCommand)(*models.Owner , error) { + owner := &models.Owner{ + PhoneNumber: command.PhoneNumber, + FirstName: command.FirstName, + LastName: command.LastName, + NationalCode: command.NationalCode, + Modified_by: command.Modified_by, + } + + return r.Repository.UpdateOwner(id , owner) +} + + +type RemoveOwnerCommand struct { + Repository o.OwnerCommandRepository +} + +func (r *RemoveOwnerCommand) Handle(id uint) error { + return r.Repository.RemoveOwner(id) +} + + diff --git a/commands/plan_handler.go b/commands/plan_handler.go new file mode 100644 index 0000000..619f6b5 --- /dev/null +++ b/commands/plan_handler.go @@ -0,0 +1,54 @@ +package commands + +import ( + "netina/models" + p "netina/repositories/plan" + "time" +) + +type CreatePlanHandler struct { + Repository p.PlanCommandRepository +} + + + +func (r *CreatePlanHandler) Handle(command models.CreatePlanCommand) error { + plan := &models.Plan{ + Price: command.Price, + Priod: command.Priod, + Partnership: command.Partnership, + PercentageOfOwner: command.PercentageOfOwner, + Created_at: time.Now(), + Modified_by: command.Modified_by, + } + + return r.Repository.CreatePlan(plan) +} + + +type UpdatePlanHandler struct { + Repository p.PlanCommandRepository +} + + +func (r *UpdatePlanHandler) Handle (id uint , command models.UpdatePlanCommand)(*models.Plan , error) { + plan := &models.Plan{ + Price: command.Price, + Priod: command.Priod, + Partnership: command.Partnership, + PercentageOfOwner: command.PercentageOfOwner, + Modified_by: command.Modified_by, + } + + return r.Repository.UpdatePlan(id , plan) +} + + +type RemovePlanHandler struct { + Repository p.PlanCommandRepository +} + + +func (r *RemovePlanHandler) Handle (id uint )error { + return r.Repository.RemovePlan(id) +} \ No newline at end of file diff --git a/commands/store_handler.go b/commands/store_handler.go new file mode 100644 index 0000000..cff0125 --- /dev/null +++ b/commands/store_handler.go @@ -0,0 +1,68 @@ +package commands + +import ( + "netina/models" + s "netina/repositories/store" + "time" +) + + +type CreateStoreHandler struct { + Repository s.StoreCommandRepository +} + + +func (r *CreateStoreHandler) Handle (command models.CreateStoreCommand)error { + store := &models.Store{ + Owner_id: command.Owner_id, + Name: command.Name, + Address: command.Address, + PhoneNumber: command.PhoneNumber, + WebAddress: command.WebAddress, + ApiAddress: command.ApiAddress, + AdminPanelAddress: command.AdminPanelAddress, + StorageAddress: command.StorageAddress, + License_id: command.License_id, + Modified_by: command.Modified_by, + Created_at: time.Now(), + } + + return r.Repository.CreateStore(store) +} + + + + +type UpdateStoreHandler struct { + Repository s.StoreCommandRepository +} + + +func (r *UpdateStoreHandler) Handle (id uint ,command models.UpdateStoreCommand)(*models.Store , error) { + store := &models.Store{ + Owner_id: command.Owner_id, + Name: command.Name, + Address: command.Address, + PhoneNumber: command.PhoneNumber, + WebAddress: command.WebAddress, + ApiAddress: command.ApiAddress, + AdminPanelAddress: command.AdminPanelAddress, + StorageAddress: command.StorageAddress, + License_id: command.License_id, + Modified_by: command.Modified_by, + + } + + return r.Repository.UpdateStore(id ,store ) +} + + + +type RemoveStoreHandler struct { + Repository s.StoreCommandRepository +} + + +func (r *RemoveStoreHandler) Handle (id uint) error { + return r.Repository.RemoveStore(id) +} \ No newline at end of file diff --git a/config/.env b/config/.env new file mode 100644 index 0000000..072321e --- /dev/null +++ b/config/.env @@ -0,0 +1,5 @@ +DB_HOST="localhost" +DB_PORT=5433 +DB_USER="postgres" +DB_PASSWORD="1" +DB_NAME="netina" \ No newline at end of file diff --git a/database/db.go b/database/db.go new file mode 100644 index 0000000..c444cef --- /dev/null +++ b/database/db.go @@ -0,0 +1,64 @@ +package database + +import ( + "fmt" + "netina/models" + "os" + "strconv" + + "github.com/joho/godotenv" + "gorm.io/driver/postgres" + "gorm.io/gorm" +) + +func Db() gorm.DB { + err := godotenv.Load("./config/.env") + if err != nil { + panic(err) + } + + host := os.Getenv("DB_HOST") + port, err := strconv.Atoi(os.Getenv("DB_PORT")) + if err != nil { + fmt.Println(os.Getenv("DB_PORT")) + panic(err) + } + user := os.Getenv("DB_USER") + password := os.Getenv("DB_PASSWORD") + dbname := os.Getenv("DB_NAME") + + dbc := fmt.Sprintf("host=%s port=%d user=%s "+ + "password=%s dbname=%s sslmode=disable", + host, port, user, password, dbname) + + db, err := gorm.Open(postgres.Open(dbc), &gorm.Config{}) + if err != nil { + panic(err) + } + + return *db +} + + +func Create_tables()error{ + db := Db() + + err := db.AutoMigrate(&models.Owner{}) + if err != nil { + return err + } + err = db.AutoMigrate(&models.Store{}) + if err != nil { + return err + } + err = db.AutoMigrate(&models.License{}) + if err != nil { + return err + } + err = db.AutoMigrate(&models.Plan{}) + if err != nil { + return err + } + + return nil +} diff --git a/go.mod b/go.mod index 75c9810..fc23994 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,19 @@ module netina go 1.21.4 + +require ( + github.com/joho/godotenv v1.5.1 + gorm.io/driver/postgres v1.5.7 + gorm.io/gorm v1.25.10 +) + +require ( + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgx/v5 v5.4.3 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/text v0.13.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..000df38 --- /dev/null +++ b/go.sum @@ -0,0 +1,34 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= +github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM= +gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA= +gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= +gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= diff --git a/main.go b/main.go index 06ab7d0..176cf29 100644 --- a/main.go +++ b/main.go @@ -1 +1,11 @@ package main + +import ( + db "netina/database" +) + + + +func main(){ + db.Create_tables() +} \ No newline at end of file diff --git a/models/Store.go b/models/Store.go new file mode 100644 index 0000000..ead5281 --- /dev/null +++ b/models/Store.go @@ -0,0 +1,22 @@ +package models + +import "time" + +type Store struct { + Store_id uint `gorm:"primaryKey"` + Owner_id uint + Owner Owner `gorm:"references:Owner_id"` + Name string + Address string + PhoneNumber string + WebAddress string + ApiAddress string + StorageAddress string + AdminPanelAddress string + License_id uint + License License `gorm:"references:License_id"` + Created_at time.Time + Modified_at time.Time + Modified_by string + Is_removed bool `gorm:"default:false"` +} \ No newline at end of file diff --git a/models/license.go b/models/license.go new file mode 100644 index 0000000..c776062 --- /dev/null +++ b/models/license.go @@ -0,0 +1,14 @@ +package models + +import "time" + +type License struct { + License_id uint `gorm:"primaryKey"` + Plan_id uint + Plan Plan `gorm:"references:Plan_id"` + Period time.Time + Created_at time.Time + Modified_at time.Time + Modified_by string + Is_removed bool `gorm:"default:false"` +} \ No newline at end of file diff --git a/models/license_commands.go b/models/license_commands.go new file mode 100644 index 0000000..db9ce59 --- /dev/null +++ b/models/license_commands.go @@ -0,0 +1,17 @@ +package models + +import "time" + +type CreateLicenseCommand struct { + Plan_id uint + Period time.Time + Modified_by string +} + + +type UpdateLicenseCommand struct { + Plan_id uint + Period time.Time + Modified_by string +} + diff --git a/models/models.go b/models/models.go deleted file mode 100644 index 5b07fff..0000000 --- a/models/models.go +++ /dev/null @@ -1,38 +0,0 @@ -package models - -import "time" - -type owner struct { - ID uint - PhoneNumber uint - FullName string - NationalCode string - Stores []uint - Created_at string - Is_removed bool -} - -type store struct { - ID uint - OwnerID uint - Name string - Address string - PhoneNumber uint - WebAddress string - ApiAddress string - StorageAddress string - AdminPanelAddress string - LicenseID string - Created_at string - Is_removed bool -} - -type License struct { - ID uint - Price uint - Period time.Time - Partnership bool - PercentageOfOwner uint - Created_at string - Is_removed bool -} diff --git a/models/owner.go b/models/owner.go new file mode 100644 index 0000000..a301c86 --- /dev/null +++ b/models/owner.go @@ -0,0 +1,15 @@ +package models + +import "time" + +type Owner struct { + Owner_id uint `gorm:"primaryKey"` + PhoneNumber string + FirstName string + LastName string + NationalCode string + Created_at time.Time + Modified_at time.Time + Modified_by string + Is_removed bool `gorm:"default:false"` +} diff --git a/models/owner_commands.go b/models/owner_commands.go new file mode 100644 index 0000000..fcb90fe --- /dev/null +++ b/models/owner_commands.go @@ -0,0 +1,17 @@ +package models + +type CreateOwnerCommand struct { + PhoneNumber string + FirstName string + LastName string + NationalCode string + Modified_by string +} + +type UpdateOwnerCommand struct { + PhoneNumber string + FirstName string + LastName string + NationalCode string + Modified_by string +} diff --git a/models/plan.go b/models/plan.go new file mode 100644 index 0000000..7667f81 --- /dev/null +++ b/models/plan.go @@ -0,0 +1,15 @@ +package models + +import "time" + +type Plan struct { + Plan_id uint `gorm:"primaryKey"` + Price uint + Priod time.Time + Partnership bool + PercentageOfOwner uint + Created_at time.Time + Modified_at time.Time + Modified_by string + Is_removed bool `gorm:"default:false"` +} \ No newline at end of file diff --git a/models/plan_commands.go b/models/plan_commands.go new file mode 100644 index 0000000..d36b520 --- /dev/null +++ b/models/plan_commands.go @@ -0,0 +1,21 @@ +package models + +import "time" + +type CreatePlanCommand struct { + Price uint + Priod time.Time + Partnership bool + PercentageOfOwner uint + Modified_by string +} + + + +type UpdatePlanCommand struct { + Price uint + Priod time.Time + Partnership bool + PercentageOfOwner uint + Modified_by string +} \ No newline at end of file diff --git a/models/store_commands.go b/models/store_commands.go new file mode 100644 index 0000000..562d545 --- /dev/null +++ b/models/store_commands.go @@ -0,0 +1,27 @@ +package models + +type CreateStoreCommand struct { + Owner_id uint + Name string + Address string + PhoneNumber string + WebAddress string + ApiAddress string + StorageAddress string + AdminPanelAddress string + License_id uint + Modified_by string +} + +type UpdateStoreCommand struct { + Owner_id uint + Name string + Address string + PhoneNumber string + WebAddress string + ApiAddress string + StorageAddress string + AdminPanelAddress string + License_id uint + Modified_by string +} \ No newline at end of file diff --git a/repositories/license/command_repository.go b/repositories/license/command_repository.go new file mode 100644 index 0000000..65dcd39 --- /dev/null +++ b/repositories/license/command_repository.go @@ -0,0 +1,57 @@ +package license_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type LicenseCommand interface{ + CreateLicense(o *models.License) error + UpdateLicense(id uint , o *models.License)(*models.License , error) + RemoveLicense(id uint)error +} + +type LicenseCommandRepository struct{ + DB *gorm.DB +} + + +func (r *LicenseCommandRepository) CreateLicense(License *models.License)error{ + if err := r.DB.Create(&License).Error ; err != nil { + return err + } + + return nil +} + + + +func (r *LicenseCommandRepository) UpdateLicense(id uint , license *models.License)(*models.License , error){ + var temp models.License + + if err := r.DB.Where("is_removed = ?" , false).Where("license_id = ?" , id).First(&temp).Error ; err != nil { + return nil , err + } + + temp.Period = license.Period + temp.Modified_at = license.Modified_at + temp.Modified_by = license.Modified_by + + + if err := r.DB.Save(&temp).Error; err != nil { + return nil , err + } + + return &temp , nil + +} + + +func (r *LicenseCommandRepository) RemoveLicense(id uint)error{ + if err := r.DB.Where("license_id = ?" , id).Error;err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/repositories/license/query_repository.go b/repositories/license/query_repository.go new file mode 100644 index 0000000..344f4cf --- /dev/null +++ b/repositories/license/query_repository.go @@ -0,0 +1,30 @@ +package license_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + + +type LicenseQuery interface{ + GetLicense(id uint)(*models.License , error) +} + + + +type LicenseQueryRepository struct{ + DB *gorm.DB +} + + + + +func (r *LicenseQueryRepository) GetLicense(id uint)(*models.License , error){ + var License models.License + if err := r.DB.Where("is_removed = ?" , false).Where("license_id = ?" , id).First(&License).Error; err != nil { + return nil , err + } + + return &License , nil +} \ No newline at end of file diff --git a/repositories/owner/command_repository.go b/repositories/owner/command_repository.go new file mode 100644 index 0000000..fa15869 --- /dev/null +++ b/repositories/owner/command_repository.go @@ -0,0 +1,59 @@ +package owner_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type OwnerCommand interface{ + CreateOwner(o *models.Owner) error + UpdateOwner(id uint , o *models.Owner)(*models.Owner , error) + RemoveOwner(id uint)error +} + +type OwnerCommandRepository struct{ + DB *gorm.DB +} + + +func (r *OwnerCommandRepository) CreateOwner(owner *models.Owner)error{ + if err := r.DB.Create(&owner).Error ; err != nil { + return err + } + + return nil +} + + + +func (r *OwnerCommandRepository) UpdateOwner(id uint , owner *models.Owner)(*models.Owner , error){ + var temp models.Owner + + if err := r.DB.Where("is_removed = ?" , false).Where("owner_id = ?" , id).First(&temp).Error ; err != nil { + return nil , err + } + + temp.FirstName = owner.FirstName + temp.LastName = owner.LastName + temp.Modified_at = owner.Modified_at + temp.Modified_by = owner.Modified_by + temp.PhoneNumber = owner.PhoneNumber + temp.NationalCode = owner.NationalCode + + if err := r.DB.Save(&temp).Error; err != nil { + return nil , err + } + + return &temp , nil + +} + + +func (r *OwnerCommandRepository) RemoveOwner(id uint)error{ + if err := r.DB.Where("owner_id = ?" , id).Error;err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/repositories/owner/query_repository.go b/repositories/owner/query_repository.go new file mode 100644 index 0000000..6761125 --- /dev/null +++ b/repositories/owner/query_repository.go @@ -0,0 +1,28 @@ +package owner_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type OwnerQuery interface { + GetOwner(id uint) (*models.Owner, error) +} + + + +type OwnerQueryRepository struct{ + DB *gorm.DB +} + + + +func (r *OwnerQueryRepository) GetOwner(id uint)(*models.Owner , error){ + var owner models.Owner + if err := r.DB.Where("is_removed = ?" , false).Where("owner_id = ?" , id).First(&owner).Error; err != nil { + return nil , err + } + + return &owner , nil +} \ No newline at end of file diff --git a/repositories/plan/command_repository.go b/repositories/plan/command_repository.go new file mode 100644 index 0000000..db391a3 --- /dev/null +++ b/repositories/plan/command_repository.go @@ -0,0 +1,66 @@ +package plan_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type PlanCommand interface{ + CreatePlan(o *models.Plan) error + GetPlan(id uint)(*models.Plan , error) + UpdatePlan(id uint , o *models.Plan)(*models.Plan , error) + RemovePlan(id uint)error +} + +type PlanCommandRepository struct{ + DB *gorm.DB +} + + +func (r *PlanCommandRepository) CreatePlan(plan *models.Plan)error{ + if err := r.DB.Create(&plan).Error ; err != nil { + return err + } + + return nil +} + +func (r *PlanCommandRepository) GetPlan(id uint)(*models.Plan , error){ + var Plan models.Plan + if err := r.DB.Where("is_removed = ?" , false).Where("plan_id = ?" , id).First(&Plan).Error; err != nil { + return nil , err + } + + return &Plan , nil +} + +func (r *PlanCommandRepository) UpdatePlan(id uint , plan *models.Plan)(*models.Plan , error){ + var temp models.Plan + + if err := r.DB.Where("is_removed = ?" , false).Where("plan_id = ?" , id).First(&temp).Error ; err != nil { + return nil , err + } + + temp.Partnership = plan.Partnership + temp.Modified_at = plan.Modified_at + temp.Modified_by = plan.Modified_by + temp.PercentageOfOwner = plan.PercentageOfOwner + temp.Price = plan.Price + + if err := r.DB.Save(&temp).Error; err != nil { + return nil , err + } + + return &temp , nil + +} + + +func (r *PlanCommandRepository) RemovePlan(id uint)error{ + if err := r.DB.Where("plan_id = ?" , id).Error;err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/repositories/plan/query_repository.go b/repositories/plan/query_repository.go new file mode 100644 index 0000000..1be767d --- /dev/null +++ b/repositories/plan/query_repository.go @@ -0,0 +1,26 @@ +package plan_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type PlanQuery interface{ + GetPlan(id uint)(*models.Plan , error) +} + +type PlanQueryRepository struct{ + DB *gorm.DB +} + + +func (r *PlanQueryRepository) GetPlan(id uint)(*models.Plan , error){ + var Plan models.Plan + if err := r.DB.Where("is_removed = ?" , false).Where("plan_id = ?" , id).First(&Plan).Error; err != nil { + return nil , err + } + + return &Plan , nil +} + diff --git a/repositories/store/command_repository.go b/repositories/store/command_repository.go new file mode 100644 index 0000000..081de2b --- /dev/null +++ b/repositories/store/command_repository.go @@ -0,0 +1,78 @@ +package store_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type StoreCommand interface{ + CreateStore(o *models.Store) error + UpdateStore(id uint , o *models.Store)(*models.Store , error) + RemoveStore(id uint)error +} + +type StoreCommandRepository struct{ + DB *gorm.DB +} + + +func (r *StoreCommandRepository) CreateStore(store *models.Store)error{ + if err := r.DB.Create(&store).Error ; err != nil { + return err + } + + return nil +} + +func (r *StoreCommandRepository) GetStore(id uint)(*models.Store , error){ + var store models.Store + if err := r.DB.Where("is_removed = ?" , false).Where("store_id = ?" , id).First(&store).Error; err != nil { + return nil , err + } + + return &store , nil +} + +func (r *StoreCommandRepository) GetStores(id uint)([]models.Store , error){ + var store []models.Store + if err := r.DB.Where("is_removed = ?" , false).Where("owner_id = ?" , id).Find(&store).Error; err != nil { + return nil , err + } + + return store , nil +} + +func (r *StoreCommandRepository) UpdateStore(id uint , store *models.Store)(*models.Store , error){ + var temp models.Store + + if err := r.DB.Where("is_removed = ?" , false).Where("store_id = ?" , id).First(&temp).Error ; err != nil { + return nil , err + } + + temp.Address = store.Address + temp.AdminPanelAddress = store.AdminPanelAddress + temp.ApiAddress = store.ApiAddress + temp.Modified_at = store.Modified_at + temp.Modified_by = store.Modified_by + temp.StorageAddress = store.StorageAddress + temp.Name = store.Name + temp.WebAddress = store.WebAddress + + + if err := r.DB.Save(&temp).Error; err != nil { + return nil , err + } + + return &temp , nil + +} + + +func (r *StoreCommandRepository) RemoveStore(id uint)error{ + if err := r.DB.Where("store_id = ?" , id).Error;err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/repositories/store/query_repository.go b/repositories/store/query_repository.go new file mode 100644 index 0000000..283af1a --- /dev/null +++ b/repositories/store/query_repository.go @@ -0,0 +1,36 @@ +package store_repository + +import ( + "netina/models" + + "gorm.io/gorm" +) + +type StoreQuery interface{ + GetStore(id uint)(*models.Store , error) + GetStores(id uint)([]models.Store , error) +} + +type StoreQueryRepository struct{ + DB *gorm.DB +} + + +func (r *StoreQueryRepository) GetStore(id uint)(*models.Store , error){ + var store models.Store + if err := r.DB.Where("is_removed = ?" , false).Where("store_id = ?" , id).First(&store).Error; err != nil { + return nil , err + } + + return &store , nil +} + +func (r *StoreQueryRepository) GetStores(id uint)([]models.Store , error){ + var store []models.Store + if err := r.DB.Where("is_removed = ?" , false).Where("owner_id = ?" , id).Find(&store).Error; err != nil { + return nil , err + } + + return store , nil +} + diff --git a/services/license.go b/services/license.go new file mode 100644 index 0000000..28ae6f5 --- /dev/null +++ b/services/license.go @@ -0,0 +1 @@ +package handlers \ No newline at end of file diff --git a/services/owner.go b/services/owner.go new file mode 100644 index 0000000..5ac8282 --- /dev/null +++ b/services/owner.go @@ -0,0 +1 @@ +package handlers diff --git a/services/plan.go b/services/plan.go new file mode 100644 index 0000000..28ae6f5 --- /dev/null +++ b/services/plan.go @@ -0,0 +1 @@ +package handlers \ No newline at end of file diff --git a/services/store.go b/services/store.go new file mode 100644 index 0000000..28ae6f5 --- /dev/null +++ b/services/store.go @@ -0,0 +1 @@ +package handlers \ No newline at end of file