Compare commits
2 Commits
4277b4cca2
...
41d5fda851
Author | SHA1 | Date |
---|---|---|
|
41d5fda851 | |
|
3e5b6d54e4 |
|
@ -45,6 +45,7 @@ func (r *UpdateLicenseHandler) Handle (id uint , command c.UpdateLicenseCommand)
|
||||||
Plan_id: command.Plan_id,
|
Plan_id: command.Plan_id,
|
||||||
Period: command.Period,
|
Period: command.Period,
|
||||||
Modified_by: command.Modified_by,
|
Modified_by: command.Modified_by,
|
||||||
|
Modified_at: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Repository.UpdateLicense(id , license)
|
return r.Repository.UpdateLicense(id , license)
|
||||||
|
|
|
@ -47,6 +47,7 @@ func (r *UpdateOwnerHandler) Handle(id uint , command c.UpdateOwnerCommand)(*m.O
|
||||||
LastName: command.LastName,
|
LastName: command.LastName,
|
||||||
NationalCode: command.NationalCode,
|
NationalCode: command.NationalCode,
|
||||||
Modified_by: command.Modified_by,
|
Modified_by: command.Modified_by,
|
||||||
|
Modified_at: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Repository.UpdateOwner(id , owner)
|
return r.Repository.UpdateOwner(id , owner)
|
||||||
|
|
|
@ -49,6 +49,7 @@ func (r *UpdatePlanHandler) Handle (id uint , command c.UpdatePlanCommand)(*m.Pl
|
||||||
Partnership: command.Partnership,
|
Partnership: command.Partnership,
|
||||||
PercentageOfOwner: command.PercentageOfOwner,
|
PercentageOfOwner: command.PercentageOfOwner,
|
||||||
Modified_by: command.Modified_by,
|
Modified_by: command.Modified_by,
|
||||||
|
Modified_at: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Repository.UpdatePlan(id , plan)
|
return r.Repository.UpdatePlan(id , plan)
|
||||||
|
|
|
@ -51,6 +51,8 @@ func (r *UpdateStoreHandler) Handle (id uint ,command c.UpdateStoreCommand)(*m.S
|
||||||
return nil,err
|
return nil,err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
store := &m.Store{
|
store := &m.Store{
|
||||||
Owner_id: command.Owner_id,
|
Owner_id: command.Owner_id,
|
||||||
Name: command.Name,
|
Name: command.Name,
|
||||||
|
@ -62,9 +64,12 @@ func (r *UpdateStoreHandler) Handle (id uint ,command c.UpdateStoreCommand)(*m.S
|
||||||
StorageAddress: command.StorageAddress,
|
StorageAddress: command.StorageAddress,
|
||||||
License_id: command.License_id,
|
License_id: command.License_id,
|
||||||
Modified_by: command.Modified_by,
|
Modified_by: command.Modified_by,
|
||||||
|
Modified_at: time.Now(),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return r.Repository.UpdateStore(id ,store )
|
return r.Repository.UpdateStore(id ,store )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
main.go
12
main.go
|
@ -2,10 +2,20 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
db "netina/database"
|
db "netina/database"
|
||||||
|
|
||||||
|
"netina/router"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
db.Create_tables()
|
db.Create_tables()
|
||||||
}
|
e := echo.New()
|
||||||
|
router.OwnerRoutes(e)
|
||||||
|
router.LicenseRoutes(e)
|
||||||
|
router.PlanRoutes(e)
|
||||||
|
router.StoreRoutes(e)
|
||||||
|
e.Logger.Fatal(e.Start(":8000"))
|
||||||
|
}
|
|
@ -3,15 +3,15 @@ package models
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type CreateLicenseCommand struct {
|
type CreateLicenseCommand struct {
|
||||||
Plan_id uint
|
Plan_id uint `validate:"required"`
|
||||||
Period time.Time
|
Period time.Time `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type UpdateLicenseCommand struct {
|
type UpdateLicenseCommand struct {
|
||||||
Plan_id uint
|
Plan_id uint `validate:"required"`
|
||||||
Period time.Time
|
Period time.Time `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type CreateOwnerCommand struct {
|
type CreateOwnerCommand struct {
|
||||||
PhoneNumber string
|
PhoneNumber string `validate:"required"`
|
||||||
FirstName string
|
FirstName string `validate:"required"`
|
||||||
LastName string
|
LastName string `validate:"required"`
|
||||||
NationalCode string
|
NationalCode string `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateOwnerCommand struct {
|
type UpdateOwnerCommand struct {
|
||||||
PhoneNumber string
|
PhoneNumber string `validate:"required"`
|
||||||
FirstName string
|
FirstName string `validate:"required"`
|
||||||
LastName string
|
LastName string `validate:"required"`
|
||||||
NationalCode string
|
NationalCode string `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,19 @@ package models
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type CreatePlanCommand struct {
|
type CreatePlanCommand struct {
|
||||||
Price uint
|
Price uint `validate:"required"`
|
||||||
Priod time.Time
|
Priod time.Time `validate:"required"`
|
||||||
Partnership bool
|
Partnership bool `validate:"required"`
|
||||||
PercentageOfOwner uint
|
PercentageOfOwner uint `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type UpdatePlanCommand struct {
|
type UpdatePlanCommand struct {
|
||||||
Price uint
|
Price uint `validate:"required"`
|
||||||
Priod time.Time
|
Priod time.Time `validate:"required"`
|
||||||
Partnership bool
|
Partnership bool `validate:"required"`
|
||||||
PercentageOfOwner uint
|
PercentageOfOwner uint `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
|
@ -1,27 +1,27 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type CreateStoreCommand struct {
|
type CreateStoreCommand struct {
|
||||||
Owner_id uint
|
Owner_id uint `validate:"required"`
|
||||||
Name string
|
Name string `validate:"required"`
|
||||||
Address string
|
Address string `validate:"required"`
|
||||||
PhoneNumber string
|
PhoneNumber string `validate:"required"`
|
||||||
WebAddress string
|
WebAddress string `validate:"required"`
|
||||||
ApiAddress string
|
ApiAddress string `validate:"required"`
|
||||||
StorageAddress string
|
StorageAddress string `validate:"required"`
|
||||||
AdminPanelAddress string
|
AdminPanelAddress string `validate:"required"`
|
||||||
License_id uint
|
License_id uint `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateStoreCommand struct {
|
type UpdateStoreCommand struct {
|
||||||
Owner_id uint
|
Owner_id uint `validate:"required"`
|
||||||
Name string
|
Name string `validate:"required"`
|
||||||
Address string
|
Address string `validate:"required"`
|
||||||
PhoneNumber string
|
PhoneNumber string `validate:"required"`
|
||||||
WebAddress string
|
WebAddress string `validate:"required"`
|
||||||
ApiAddress string
|
ApiAddress string `validate:"required"`
|
||||||
StorageAddress string
|
StorageAddress string `validate:"required"`
|
||||||
AdminPanelAddress string
|
AdminPanelAddress string `validate:"required"`
|
||||||
License_id uint
|
License_id uint `validate:"required"`
|
||||||
Modified_by string
|
Modified_by string `validate:"required"`
|
||||||
}
|
}
|
|
@ -1,38 +1,87 @@
|
||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"netina/commands"
|
"netina/commands"
|
||||||
models "netina/models"
|
|
||||||
cm "netina/models/commands"
|
cm "netina/models/commands"
|
||||||
"netina/queries"
|
"netina/queries"
|
||||||
license_repository "netina/repositories/license"
|
license_repository "netina/repositories/license"
|
||||||
|
"netina/validation"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type LicenseService struct {
|
type LicenseService struct {
|
||||||
CommandRepo license_repository.LicenseCommandRepository
|
CommandRepo license_repository.LicenseCommandRepository
|
||||||
QueryRepo license_repository.LicenseQueryRepository
|
QueryRepo license_repository.LicenseQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LicenseService) CreateLicense(c echo.Context) error {
|
||||||
|
license := new(cm.CreateLicenseCommand)
|
||||||
|
if err := c.Bind(license); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(license); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *LicenseService) CreateLicnese(cmd cm.CreateLicenseCommand) error {
|
|
||||||
handler := commands.CreateLicenseHandler{Repository: s.CommandRepo}
|
handler := commands.CreateLicenseHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(cmd)
|
if err := handler.Handle(*license); err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusCreated, license)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *LicenseService) GetLicense(id uint)(*models.License , error){
|
func (s *LicenseService) GetLicense(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid license ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := queries.GetLicenseHandler{Repository: s.QueryRepo}
|
handler := queries.GetLicenseHandler{Repository: s.QueryRepo}
|
||||||
return handler.Handle(id)
|
license, err := handler.Handle(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, license)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LicenseService) UpdateLicense(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid license ID"})
|
||||||
|
}
|
||||||
|
|
||||||
|
license := new(cm.UpdateLicenseCommand)
|
||||||
|
if err := c.Bind(license); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(license); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *LicenseService) UpdateOwner(id uint,cmd cm.UpdateLicenseCommand)(*models.License ,error) {
|
|
||||||
handler := commands.UpdateLicenseHandler{Repository: s.CommandRepo}
|
handler := commands.UpdateLicenseHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id,cmd)
|
updatedLicense, err := handler.Handle(uint(id), *license)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, updatedLicense)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *LicenseService) RemoveOwner(id uint) error {
|
func (s *LicenseService) RemoveLicense(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid license ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := commands.RemoveLicenseHandler{Repository: s.CommandRepo}
|
handler := commands.RemoveLicenseHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id)
|
if err := handler.Handle(uint(id)); err != nil {
|
||||||
}
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
|
@ -1,39 +1,86 @@
|
||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"netina/commands"
|
"netina/commands"
|
||||||
models "netina/models"
|
|
||||||
cm "netina/models/commands"
|
cm "netina/models/commands"
|
||||||
"netina/queries"
|
"netina/queries"
|
||||||
owner_repository "netina/repositories/owner"
|
owner_repository "netina/repositories/owner"
|
||||||
|
"netina/validation"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type OwnerService struct {
|
type OwnerService struct {
|
||||||
CommandRepo owner_repository.OwnerCommandRepository
|
CommandRepo owner_repository.OwnerCommandRepository
|
||||||
QueryRepo owner_repository.OwnerQueryRepository
|
QueryRepo owner_repository.OwnerQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *OwnerService) CreateOwner(c echo.Context) error {
|
||||||
|
owner := new(cm.CreateOwnerCommand)
|
||||||
|
if err := c.Bind(owner); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(owner); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *OwnerService) CreateOwner(cmd cm.CreateOwnerCommand) error {
|
|
||||||
handler := commands.CreateOwnerHandler{Repository: s.CommandRepo}
|
handler := commands.CreateOwnerHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(cmd)
|
if err := handler.Handle(*owner); err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusCreated, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *OwnerService) GetOwner(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid owner ID"})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *OwnerService) GetOwner(id uint)(*models.Owner , error){
|
|
||||||
handler := queries.GetOwnerHandler{Repository: s.QueryRepo}
|
handler := queries.GetOwnerHandler{Repository: s.QueryRepo}
|
||||||
return handler.Handle(id)
|
owner, err := handler.Handle(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *OwnerService) UpdateOwner(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid owner ID"})
|
||||||
|
}
|
||||||
|
|
||||||
|
owner := new(cm.UpdateOwnerCommand)
|
||||||
|
if err := c.Bind(owner); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(owner); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *OwnerService) UpdateOwner(id uint,cmd cm.UpdateOwnerCommand)(*models.Owner ,error) {
|
|
||||||
handler := commands.UpdateOwnerHandler{Repository: s.CommandRepo}
|
handler := commands.UpdateOwnerHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id,cmd)
|
if _, err := handler.Handle(uint(id), *owner); err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *OwnerService) RemoveOwner(id uint) error {
|
func (s *OwnerService) RemoveOwner(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid owner ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := commands.RemoveOwnerHandler{Repository: s.CommandRepo}
|
handler := commands.RemoveOwnerHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id)
|
if err := handler.Handle(uint(id)); err != nil {
|
||||||
}
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
|
@ -1,38 +1,87 @@
|
||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"netina/commands"
|
"netina/commands"
|
||||||
models "netina/models"
|
|
||||||
cm "netina/models/commands"
|
cm "netina/models/commands"
|
||||||
"netina/queries"
|
"netina/queries"
|
||||||
plan_repository "netina/repositories/plan"
|
plan_repository "netina/repositories/plan"
|
||||||
|
"netina/validation"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type PlanService struct {
|
type PlanService struct {
|
||||||
CommandRepo plan_repository.PlanCommandRepository
|
CommandRepo plan_repository.PlanCommandRepository
|
||||||
QueryRepo plan_repository.PlanQueryRepository
|
QueryRepo plan_repository.PlanQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PlanService) CreatePlan(c echo.Context) error {
|
||||||
|
plan := new(cm.CreatePlanCommand)
|
||||||
|
if err := c.Bind(plan); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(plan); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *PlanService) Createplan(cmd cm.CreatePlanCommand) error {
|
|
||||||
handler := commands.CreatePlanHandler{Repository: s.CommandRepo}
|
handler := commands.CreatePlanHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(cmd)
|
if err := handler.Handle(*plan); err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusCreated, plan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *PlanService) GetPlan(id uint)(*models.Plan , error){
|
func (s *PlanService) GetPlan(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid plan ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := queries.GetPlanHandler{Repository: s.QueryRepo}
|
handler := queries.GetPlanHandler{Repository: s.QueryRepo}
|
||||||
return handler.Handle(id)
|
plan, err := handler.Handle(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, plan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PlanService) UpdatePlan(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid plan ID"})
|
||||||
|
}
|
||||||
|
|
||||||
|
plan := new(cm.UpdatePlanCommand)
|
||||||
|
if err := c.Bind(plan); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(plan); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *PlanService) Updateplan(id uint,cmd cm.UpdatePlanCommand)(*models.Plan ,error) {
|
|
||||||
handler := commands.UpdatePlanHandler{Repository: s.CommandRepo}
|
handler := commands.UpdatePlanHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id,cmd)
|
updatedPlan, err := handler.Handle(uint(id), *plan)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, updatedPlan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *PlanService) Removeplan(id uint) error {
|
func (s *PlanService) RemovePlan(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid plan ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := commands.RemovePlanHandler{Repository: s.CommandRepo}
|
handler := commands.RemovePlanHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id)
|
if err := handler.Handle(uint(id)); err != nil {
|
||||||
}
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
|
@ -1,44 +1,101 @@
|
||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"netina/commands"
|
"netina/commands"
|
||||||
models "netina/models"
|
|
||||||
cm "netina/models/commands"
|
cm "netina/models/commands"
|
||||||
"netina/queries"
|
"netina/queries"
|
||||||
store_repository "netina/repositories/store"
|
store_repository "netina/repositories/store"
|
||||||
|
"netina/validation"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type StoreService struct {
|
type StoreService struct {
|
||||||
CommandRepo store_repository.StoreCommandRepository
|
CommandRepo store_repository.StoreCommandRepository
|
||||||
QueryRepo store_repository.StoreQueryRepository
|
QueryRepo store_repository.StoreQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StoreService) CreateStore(c echo.Context) error {
|
||||||
|
store := new(cm.CreateStoreCommand)
|
||||||
|
if err := c.Bind(store); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(store); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *StoreService) Createstore(cmd cm.CreateStoreCommand) error {
|
|
||||||
handler := commands.CreateStoreHandler{Repository: s.CommandRepo}
|
handler := commands.CreateStoreHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(cmd)
|
if err := handler.Handle(*store); err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusCreated, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StoreService) GetStore(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid store ID"})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *StoreService) GetStore(id uint)(*models.Store , error){
|
|
||||||
handler := queries.GetStoreHandler{Repository: s.QueryRepo}
|
handler := queries.GetStoreHandler{Repository: s.QueryRepo}
|
||||||
return handler.Handle(id)
|
store, err := handler.Handle(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *StoreService) GetStoresList(id uint)([]models.Store , error){
|
func (s *StoreService) GetStoresList(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid store ID"})
|
||||||
|
}
|
||||||
handler := queries.GetStoreListHandler{Repository: s.QueryRepo}
|
handler := queries.GetStoreListHandler{Repository: s.QueryRepo}
|
||||||
return handler.Handle(id)
|
stores, err := handler.Handle(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, stores)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StoreService) UpdateStore(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid store ID"})
|
||||||
|
}
|
||||||
|
|
||||||
|
store := new(cm.UpdateStoreCommand)
|
||||||
|
if err := c.Bind(store); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||||
|
}
|
||||||
|
if err := validation.ValidateStruct(store); err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
func(s *StoreService) Updatestore(id uint,cmd cm.UpdateStoreCommand)(*models.Store ,error) {
|
|
||||||
handler := commands.UpdateStoreHandler{Repository: s.CommandRepo}
|
handler := commands.UpdateStoreHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id,cmd)
|
updatedStore, err := handler.Handle(uint(id), *store)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, updatedStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *StoreService) Removestore(id uint) error {
|
func (s *StoreService) RemoveStore(c echo.Context) error {
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid store ID"})
|
||||||
|
}
|
||||||
|
|
||||||
handler := commands.RemoveStoreHandler{Repository: s.CommandRepo}
|
handler := commands.RemoveStoreHandler{Repository: s.CommandRepo}
|
||||||
return handler.Handle(id)
|
if err := handler.Handle(uint(id)); err != nil {
|
||||||
}
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue