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,
|
||||
Period: command.Period,
|
||||
Modified_by: command.Modified_by,
|
||||
Modified_at: time.Now(),
|
||||
}
|
||||
|
||||
return r.Repository.UpdateLicense(id , license)
|
||||
|
|
|
@ -47,6 +47,7 @@ func (r *UpdateOwnerHandler) Handle(id uint , command c.UpdateOwnerCommand)(*m.O
|
|||
LastName: command.LastName,
|
||||
NationalCode: command.NationalCode,
|
||||
Modified_by: command.Modified_by,
|
||||
Modified_at: time.Now(),
|
||||
}
|
||||
|
||||
return r.Repository.UpdateOwner(id , owner)
|
||||
|
|
|
@ -49,6 +49,7 @@ func (r *UpdatePlanHandler) Handle (id uint , command c.UpdatePlanCommand)(*m.Pl
|
|||
Partnership: command.Partnership,
|
||||
PercentageOfOwner: command.PercentageOfOwner,
|
||||
Modified_by: command.Modified_by,
|
||||
Modified_at: time.Now(),
|
||||
}
|
||||
|
||||
return r.Repository.UpdatePlan(id , plan)
|
||||
|
|
|
@ -51,6 +51,8 @@ func (r *UpdateStoreHandler) Handle (id uint ,command c.UpdateStoreCommand)(*m.S
|
|||
return nil,err
|
||||
}
|
||||
|
||||
|
||||
|
||||
store := &m.Store{
|
||||
Owner_id: command.Owner_id,
|
||||
Name: command.Name,
|
||||
|
@ -62,9 +64,12 @@ func (r *UpdateStoreHandler) Handle (id uint ,command c.UpdateStoreCommand)(*m.S
|
|||
StorageAddress: command.StorageAddress,
|
||||
License_id: command.License_id,
|
||||
Modified_by: command.Modified_by,
|
||||
Modified_at: time.Now(),
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return r.Repository.UpdateStore(id ,store )
|
||||
}
|
||||
|
||||
|
|
12
main.go
12
main.go
|
@ -2,10 +2,20 @@ package main
|
|||
|
||||
import (
|
||||
db "netina/database"
|
||||
|
||||
"netina/router"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func main(){
|
||||
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"
|
||||
|
||||
type CreateLicenseCommand struct {
|
||||
Plan_id uint
|
||||
Period time.Time
|
||||
Modified_by string
|
||||
Plan_id uint `validate:"required"`
|
||||
Period time.Time `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
||||
|
||||
type UpdateLicenseCommand struct {
|
||||
Plan_id uint
|
||||
Period time.Time
|
||||
Modified_by string
|
||||
Plan_id uint `validate:"required"`
|
||||
Period time.Time `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package models
|
||||
|
||||
type CreateOwnerCommand struct {
|
||||
PhoneNumber string
|
||||
FirstName string
|
||||
LastName string
|
||||
NationalCode string
|
||||
Modified_by string
|
||||
PhoneNumber string `validate:"required"`
|
||||
FirstName string `validate:"required"`
|
||||
LastName string `validate:"required"`
|
||||
NationalCode string `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
||||
type UpdateOwnerCommand struct {
|
||||
PhoneNumber string
|
||||
FirstName string
|
||||
LastName string
|
||||
NationalCode string
|
||||
Modified_by string
|
||||
PhoneNumber string `validate:"required"`
|
||||
FirstName string `validate:"required"`
|
||||
LastName string `validate:"required"`
|
||||
NationalCode string `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
|
|
@ -3,19 +3,19 @@ package models
|
|||
import "time"
|
||||
|
||||
type CreatePlanCommand struct {
|
||||
Price uint
|
||||
Priod time.Time
|
||||
Partnership bool
|
||||
PercentageOfOwner uint
|
||||
Modified_by string
|
||||
Price uint `validate:"required"`
|
||||
Priod time.Time `validate:"required"`
|
||||
Partnership bool `validate:"required"`
|
||||
PercentageOfOwner uint `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
||||
|
||||
|
||||
type UpdatePlanCommand struct {
|
||||
Price uint
|
||||
Priod time.Time
|
||||
Partnership bool
|
||||
PercentageOfOwner uint
|
||||
Modified_by string
|
||||
Price uint `validate:"required"`
|
||||
Priod time.Time `validate:"required"`
|
||||
Partnership bool `validate:"required"`
|
||||
PercentageOfOwner uint `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
|
@ -1,27 +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
|
||||
Owner_id uint `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Address string `validate:"required"`
|
||||
PhoneNumber string `validate:"required"`
|
||||
WebAddress string `validate:"required"`
|
||||
ApiAddress string `validate:"required"`
|
||||
StorageAddress string `validate:"required"`
|
||||
AdminPanelAddress string `validate:"required"`
|
||||
License_id uint `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
||||
|
||||
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
|
||||
Owner_id uint `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Address string `validate:"required"`
|
||||
PhoneNumber string `validate:"required"`
|
||||
WebAddress string `validate:"required"`
|
||||
ApiAddress string `validate:"required"`
|
||||
StorageAddress string `validate:"required"`
|
||||
AdminPanelAddress string `validate:"required"`
|
||||
License_id uint `validate:"required"`
|
||||
Modified_by string `validate:"required"`
|
||||
}
|
|
@ -1,38 +1,87 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"netina/commands"
|
||||
models "netina/models"
|
||||
cm "netina/models/commands"
|
||||
"netina/queries"
|
||||
license_repository "netina/repositories/license"
|
||||
"netina/validation"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type LicenseService struct {
|
||||
CommandRepo license_repository.LicenseCommandRepository
|
||||
QueryRepo license_repository.LicenseQueryRepository
|
||||
CommandRepo license_repository.LicenseCommandRepository
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"netina/commands"
|
||||
models "netina/models"
|
||||
cm "netina/models/commands"
|
||||
"netina/queries"
|
||||
owner_repository "netina/repositories/owner"
|
||||
"netina/validation"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type OwnerService struct {
|
||||
CommandRepo owner_repository.OwnerCommandRepository
|
||||
QueryRepo owner_repository.OwnerQueryRepository
|
||||
CommandRepo owner_repository.OwnerCommandRepository
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"netina/commands"
|
||||
models "netina/models"
|
||||
cm "netina/models/commands"
|
||||
"netina/queries"
|
||||
plan_repository "netina/repositories/plan"
|
||||
"netina/validation"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type PlanService struct {
|
||||
CommandRepo plan_repository.PlanCommandRepository
|
||||
QueryRepo plan_repository.PlanQueryRepository
|
||||
CommandRepo plan_repository.PlanCommandRepository
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"netina/commands"
|
||||
models "netina/models"
|
||||
cm "netina/models/commands"
|
||||
"netina/queries"
|
||||
store_repository "netina/repositories/store"
|
||||
"netina/validation"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type StoreService struct {
|
||||
CommandRepo store_repository.StoreCommandRepository
|
||||
QueryRepo store_repository.StoreQueryRepository
|
||||
CommandRepo store_repository.StoreCommandRepository
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
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