[FEATURE] adding update and fixing on get by id
This commit is contained in:
parent
0727b724ca
commit
54d191dcb4
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"users_management/m/utils/common"
|
"users_management/m/utils/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackboneController struct {
|
type BackboneController struct {
|
||||||
|
|
@ -18,7 +19,8 @@ func (bc *BackboneController) Route() {
|
||||||
rg := bc.rg.Group("/backbone")
|
rg := bc.rg.Group("/backbone")
|
||||||
rg.GET("", bc.GetBackbone())
|
rg.GET("", bc.GetBackbone())
|
||||||
rg.POST("", bc.CreateBackbone())
|
rg.POST("", bc.CreateBackbone())
|
||||||
rg.GET("/:id", bc.GetBackboneByID())
|
rg.GET("/:uuid", bc.GetBackboneByID())
|
||||||
|
rg.PUT("/:uuid", bc.UpdateBackbone())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBackboneController(bu usecase.BackboneUseCase, rg *gin.RouterGroup) *BackboneController {
|
func NewBackboneController(bu usecase.BackboneUseCase, rg *gin.RouterGroup) *BackboneController {
|
||||||
|
|
@ -64,8 +66,13 @@ func (bc *BackboneController) CreateBackbone() gin.HandlerFunc {
|
||||||
|
|
||||||
func (bc *BackboneController) GetBackboneByID() gin.HandlerFunc {
|
func (bc *BackboneController) GetBackboneByID() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("uuid")
|
||||||
backbone, err := bc.bu.GetByID(id)
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
backbone, err := bc.bu.GetByID(uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
|
@ -75,3 +82,31 @@ func (bc *BackboneController) GetBackboneByID() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", backbone)
|
common.SingleResponses(c, "Success", backbone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bc *BackboneController) UpdateBackbone() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("uuid")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var backboneDTO req.UpdateBackboneDTO
|
||||||
|
err = c.ShouldBindJSON(&backboneDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bc.bu.UpdateBackbone(uuid, backboneDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Backbone has been updated", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"users_management/m/utils/common"
|
"users_management/m/utils/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DevicePortController struct {
|
type DevicePortController struct {
|
||||||
|
|
@ -18,7 +19,8 @@ func (dc *DevicePortController) Route() {
|
||||||
rg := dc.rg.Group("/device-port")
|
rg := dc.rg.Group("/device-port")
|
||||||
rg.GET("", dc.GetDevicePort())
|
rg.GET("", dc.GetDevicePort())
|
||||||
rg.POST("", dc.CreateDevicePort())
|
rg.POST("", dc.CreateDevicePort())
|
||||||
rg.GET("/:id", dc.GetDevicePortByID())
|
rg.GET("/:uuid", dc.GetDevicePortByID())
|
||||||
|
rg.PUT("/:uuid", dc.UpdateDevicePort())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevicePortController(du usecase.DevicePortUseCase, rg *gin.RouterGroup) *DevicePortController {
|
func NewDevicePortController(du usecase.DevicePortUseCase, rg *gin.RouterGroup) *DevicePortController {
|
||||||
|
|
@ -64,8 +66,13 @@ func (dc *DevicePortController) CreateDevicePort() gin.HandlerFunc {
|
||||||
|
|
||||||
func (dc *DevicePortController) GetDevicePortByID() gin.HandlerFunc {
|
func (dc *DevicePortController) GetDevicePortByID() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("uuid")
|
||||||
devicePort, err := dc.du.GetByID(id)
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
devicePort, err := dc.du.GetByID(uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
|
@ -75,3 +82,31 @@ func (dc *DevicePortController) GetDevicePortByID() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", devicePort)
|
common.SingleResponses(c, "Success", devicePort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *DevicePortController) UpdateDevicePort() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("uuid")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var devicePortDTO req.UpdateDevicePort
|
||||||
|
err = c.ShouldBindJSON(&devicePortDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dc.du.UpdateDevicePort(uuid, devicePortDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Device Port has been updated", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"users_management/m/utils/common"
|
"users_management/m/utils/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeviceController struct {
|
type DeviceController struct {
|
||||||
|
|
@ -18,7 +19,8 @@ func (dc *DeviceController) Route() {
|
||||||
rg := dc.rg.Group("/devices")
|
rg := dc.rg.Group("/devices")
|
||||||
rg.POST("", dc.CreateDevice())
|
rg.POST("", dc.CreateDevice())
|
||||||
rg.GET("", dc.GetAllDevices())
|
rg.GET("", dc.GetAllDevices())
|
||||||
rg.GET("/:id", dc.GetDeviceByID())
|
rg.GET("/:uuid", dc.GetDeviceByID())
|
||||||
|
rg.PUT("/:uuid", dc.UpdateDevice())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeviceController(du usecase.DeviceUseCase, rg *gin.RouterGroup) *DeviceController {
|
func NewDeviceController(du usecase.DeviceUseCase, rg *gin.RouterGroup) *DeviceController {
|
||||||
|
|
@ -65,8 +67,12 @@ func (dc *DeviceController) GetAllDevices() gin.HandlerFunc {
|
||||||
func (dc *DeviceController) GetDeviceByID() gin.HandlerFunc {
|
func (dc *DeviceController) GetDeviceByID() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
device, err := dc.du.GetByID(id)
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil{
|
||||||
|
common.ErrorResponses(c, http.StatusBadGateway, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
device, err := dc.du.GetByID(uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
|
|
@ -75,3 +81,31 @@ func (dc *DeviceController) GetDeviceByID() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", device)
|
common.SingleResponses(c, "Success", device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *DeviceController) UpdateDevice() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var deviceDTO req.UpdateDeviceDTO
|
||||||
|
err = c.ShouldBindJSON(&deviceDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dc.du.UpdateDevice(uuid, deviceDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Device has been updated", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"users_management/m/utils/common"
|
"users_management/m/utils/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FishboneController struct {
|
type FishboneController struct {
|
||||||
|
|
@ -18,7 +19,8 @@ func (fc *FishboneController) Route() {
|
||||||
rg := fc.rg.Group("/fishbone")
|
rg := fc.rg.Group("/fishbone")
|
||||||
rg.GET("", fc.GetFishbone())
|
rg.GET("", fc.GetFishbone())
|
||||||
rg.POST("", fc.CreateFishbone())
|
rg.POST("", fc.CreateFishbone())
|
||||||
rg.GET("/:id", fc.GetFishboneByID())
|
rg.GET("/:uuid", fc.GetFishboneByID())
|
||||||
|
rg.PUT("/:uuid", fc.UpdateFishbone())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFishboneController(fu usecase.FishboneUseCase, rg *gin.RouterGroup) *FishboneController {
|
func NewFishboneController(fu usecase.FishboneUseCase, rg *gin.RouterGroup) *FishboneController {
|
||||||
|
|
@ -64,8 +66,13 @@ func (fc *FishboneController) CreateFishbone() gin.HandlerFunc {
|
||||||
|
|
||||||
func (fc *FishboneController) GetFishboneByID() gin.HandlerFunc {
|
func (fc *FishboneController) GetFishboneByID() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("uuid")
|
||||||
fishbone, err := fc.fu.GetByID(id)
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil{
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fishbone, err := fc.fu.GetByID(uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
|
@ -75,3 +82,31 @@ func (fc *FishboneController) GetFishboneByID() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", fishbone)
|
common.SingleResponses(c, "Success", fishbone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fc *FishboneController) UpdateFishbone() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("uuid")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var fishboneDTO req.UpdateFishboneDTO
|
||||||
|
err = c.ShouldBindJSON(&fishboneDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fc.fu.UpdateFishbone(uuid, fishboneDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Fishbone has been updated", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"users_management/m/utils/common"
|
"users_management/m/utils/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TowerController struct {
|
type TowerController struct {
|
||||||
|
|
@ -18,7 +19,8 @@ func (tc *TowerController) Route() {
|
||||||
rg := tc.rg.Group("/tower")
|
rg := tc.rg.Group("/tower")
|
||||||
rg.GET("", tc.GetTower())
|
rg.GET("", tc.GetTower())
|
||||||
rg.POST("", tc.CreateTower())
|
rg.POST("", tc.CreateTower())
|
||||||
rg.GET("/:id", tc.GetTowerByID())
|
rg.GET("/:uuid", tc.GetTowerByID())
|
||||||
|
rg.PUT("/:uuid", tc.UpdateTower())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTowerController(tu usecase.TowerUseCase, rg *gin.RouterGroup) *TowerController {
|
func NewTowerController(tu usecase.TowerUseCase, rg *gin.RouterGroup) *TowerController {
|
||||||
|
|
@ -64,8 +66,13 @@ func (tc *TowerController) CreateTower() gin.HandlerFunc {
|
||||||
|
|
||||||
func (tc *TowerController) GetTowerByID() gin.HandlerFunc {
|
func (tc *TowerController) GetTowerByID() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("uuid")
|
||||||
tower, err := tc.tu.GetByID(id)
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tower, err := tc.tu.GetByID(uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
|
@ -75,3 +82,29 @@ func (tc *TowerController) GetTowerByID() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", tower)
|
common.SingleResponses(c, "Success", tower)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tc *TowerController) UpdateTower() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("uuid")
|
||||||
|
uuid, err := uuid.Parse(id)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
var towerUpdateDTO req.UpdateTowerDTO
|
||||||
|
err = c.ShouldBindJSON(&towerUpdateDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tc.tu.UpdateTower(uuid, towerUpdateDTO)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Tower has been updated", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,3 +7,9 @@ type BackboneDTO struct {
|
||||||
DeviceEndID uuid.UUID `json:"dev_end_id"`
|
DeviceEndID uuid.UUID `json:"dev_end_id"`
|
||||||
CoreAmount int `json:"core_amount"`
|
CoreAmount int `json:"core_amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateBackboneDTO struct {
|
||||||
|
DeviceStartID *uuid.UUID `json:"dev_start_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
DeviceEndID *uuid.UUID `json:"dev_end_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
CoreAmount *int `json:"core_amount,omitempty" validate:"omitempty,min=1"`
|
||||||
|
}
|
||||||
|
|
@ -6,3 +6,8 @@ type DevicePort struct {
|
||||||
DeviceID uuid.UUID `json:"device_id"`
|
DeviceID uuid.UUID `json:"device_id"`
|
||||||
PortNumber int `json:"port_number"`
|
PortNumber int `json:"port_number"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateDevicePort struct {
|
||||||
|
DeviceID *uuid.UUID `json:"device_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
PortNumber *int `json:"port_number,omitempty" validate:"omitempty,min=1"`
|
||||||
|
}
|
||||||
|
|
@ -9,3 +9,12 @@ type DeviceDTO struct {
|
||||||
PortAmount int `json:"port_amount" validate:"required"`
|
PortAmount int `json:"port_amount" validate:"required"`
|
||||||
Status string `json:"status" validate:"required,oneof=active inactive maintenance"`
|
Status string `json:"status" validate:"required,oneof=active inactive maintenance"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateDeviceDTO struct {
|
||||||
|
DeviceCode *string `json:"device_code,omitempty" validate:"omitempty,min=3"`
|
||||||
|
DeviceType *string `json:"device_type,omitempty" validate:"omitempty,min=3"`
|
||||||
|
Longitude *float64 `json:"longitude,omitempty" validate:"omitempty,longitude"`
|
||||||
|
Latitude *float64 `json:"latitude,omitempty" validate:"omitempty,latitude"`
|
||||||
|
PortAmount *int `json:"port_amount,omitempty" validate:"omitempty,min=1"`
|
||||||
|
Status *string `json:"status,omitempty" validate:"omitempty,oneof=active inactive maintenance"`
|
||||||
|
}
|
||||||
|
|
@ -8,3 +8,10 @@ type FishboneDTO struct {
|
||||||
DeviceEndID uuid.UUID `json:"dev_end_id"`
|
DeviceEndID uuid.UUID `json:"dev_end_id"`
|
||||||
CoreAmount int `json:"core_amount"`
|
CoreAmount int `json:"core_amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateFishboneDTO struct {
|
||||||
|
BackboneID *uuid.UUID `json:"bb_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
DeviceStartID *uuid.UUID `json:"dev_start_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
DeviceEndID *uuid.UUID `json:"dev_end_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
CoreAmount *int `json:"core_amount,omitempty" validate:"omitempty,min=1"`
|
||||||
|
}
|
||||||
|
|
@ -8,3 +8,10 @@ type TowerDTO struct {
|
||||||
Longitude float64 `json:"longitude"`
|
Longitude float64 `json:"longitude"`
|
||||||
Latitude float64 `json:"latitude"`
|
Latitude float64 `json:"latitude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateTowerDTO struct {
|
||||||
|
DeviceID *string `json:"device_id,omitempty" validate:"omitempty,min=3"`
|
||||||
|
TowerCode *string `json:"tower_code,omitempty" validate:"omitempty,alphanum"`
|
||||||
|
Longitude *float64 `json:"longitude,omitempty" validate:"omitempty,longitude"`
|
||||||
|
Latitude *float64 `json:"latitude,omitempty" validate:"omitempty,latitude"`
|
||||||
|
}
|
||||||
|
|
@ -3,15 +3,16 @@ package repository
|
||||||
import (
|
import (
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackboneRepo interface {
|
type BackboneRepo interface {
|
||||||
Post(backbone entity.Backbone) error
|
Post(backbone entity.Backbone) error
|
||||||
GetAll() ([]entity.Backbone, error)
|
GetAll() ([]entity.Backbone, error)
|
||||||
Update(backbone entity.Backbone) error
|
Update(id uuid.UUID, updates map[string]interface{}) error
|
||||||
|
|
||||||
GetByID(id string) (entity.Backbone, error)
|
GetByID(id uuid.UUID) (entity.Backbone, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type backboneRepo struct {
|
type backboneRepo struct {
|
||||||
|
|
@ -41,15 +42,15 @@ func (r *backboneRepo) GetAll() ([]entity.Backbone, error) {
|
||||||
return backbones, nil
|
return backbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *backboneRepo) Update(backbone entity.Backbone) error {
|
func (r *backboneRepo) Update(id uuid.UUID, updates map[string]interface{}) error {
|
||||||
err := r.db.Save(&backbone).Error
|
err := r.db.Model(&entity.Backbone{}).Where("id = ?", id).Updates(updates).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *backboneRepo) GetByID(id string) (entity.Backbone, error) {
|
func (r *backboneRepo) GetByID(id uuid.UUID) (entity.Backbone, error) {
|
||||||
var backbone entity.Backbone
|
var backbone entity.Backbone
|
||||||
err := r.db.Where("id = ?", id).First(&backbone).Error
|
err := r.db.Where("id = ?", id).First(&backbone).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@ package repository
|
||||||
import (
|
import (
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DevicePortRepo interface {
|
type DevicePortRepo interface {
|
||||||
Post(devicePort entity.DevicePort) error
|
Post(devicePort entity.DevicePort) error
|
||||||
GetAll() ([]entity.DevicePort, error)
|
GetAll() ([]entity.DevicePort, error)
|
||||||
Update(devicePort entity.DevicePort) error
|
Update(id uuid.UUID, updates map[string]interface{}) error
|
||||||
|
|
||||||
GetByID(id string) (entity.DevicePort, error)
|
GetByID(id uuid.UUID) (entity.DevicePort, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicePortRepo struct {
|
type devicePortRepo struct {
|
||||||
|
|
@ -41,15 +42,15 @@ func (r *devicePortRepo) GetAll() ([]entity.DevicePort, error) {
|
||||||
return devicePorts, nil
|
return devicePorts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *devicePortRepo) Update(devicePort entity.DevicePort) error {
|
func (r *devicePortRepo) Update(id uuid.UUID,updates map[string]interface{}) error {
|
||||||
err := r.db.Save(&devicePort).Error
|
err := r.db.Model(&entity.DevicePort{}).Where("id = ?", id).Updates(updates).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *devicePortRepo) GetByID(id string) (entity.DevicePort, error) {
|
func (r *devicePortRepo) GetByID(id uuid.UUID) (entity.DevicePort, error) {
|
||||||
var devicePort entity.DevicePort
|
var devicePort entity.DevicePort
|
||||||
err := r.db.Where("id = ?", id).First(&devicePort).Error
|
err := r.db.Where("id = ?", id).First(&devicePort).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@ package repository
|
||||||
import (
|
import (
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DevicesRepo interface {
|
type DevicesRepo interface {
|
||||||
Post(device entity.Device) error
|
Post(device entity.Device) error
|
||||||
GetAll() ([]entity.Device, error)
|
GetAll() ([]entity.Device, error)
|
||||||
Update(device entity.Device) error
|
Update(id uuid.UUID,updates map[string]interface{}) error
|
||||||
|
|
||||||
GetByID(id string) (entity.Device, error)
|
GetByID(id uuid.UUID) (entity.Device, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicesRepo struct {
|
type devicesRepo struct {
|
||||||
|
|
@ -40,15 +41,15 @@ func (r *devicesRepo) GetAll() ([]entity.Device, error) {
|
||||||
}
|
}
|
||||||
return devices, nil
|
return devices, nil
|
||||||
}
|
}
|
||||||
func (r *devicesRepo) Update(device entity.Device) error {
|
func (r *devicesRepo) Update(id uuid.UUID,updates map[string]interface{}) error {
|
||||||
err := r.db.Save(&device).Error
|
err := r.db.Model(&entity.Device{}).Where("id = ?", id).Updates(updates).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *devicesRepo) GetByID(id string) (entity.Device, error) {
|
func (r *devicesRepo) GetByID(id uuid.UUID) (entity.Device, error) {
|
||||||
var device entity.Device
|
var device entity.Device
|
||||||
err := r.db.Where("id = ?", id).First(&device).Error
|
err := r.db.Where("id = ?", id).First(&device).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@ package repository
|
||||||
import (
|
import (
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FishboneRepo interface {
|
type FishboneRepo interface {
|
||||||
Post(fishbone entity.Fishbone) error
|
Post(fishbone entity.Fishbone) error
|
||||||
GetAll() ([]entity.Fishbone, error)
|
GetAll() ([]entity.Fishbone, error)
|
||||||
Update(fishbone entity.Fishbone) error
|
Update(id uuid.UUID,updates map[string]interface{}) error
|
||||||
|
|
||||||
GetByID(id string) (entity.Fishbone, error)
|
GetByID(id uuid.UUID) (entity.Fishbone, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fishboneRepo struct {
|
type fishboneRepo struct {
|
||||||
|
|
@ -41,15 +42,15 @@ func (r *fishboneRepo) GetAll() ([]entity.Fishbone, error) {
|
||||||
return fishbones, nil
|
return fishbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *fishboneRepo) Update(fishbone entity.Fishbone) error {
|
func (r *fishboneRepo) Update(id uuid.UUID,updates map[string]interface{}) error {
|
||||||
err := r.db.Save(&fishbone).Error
|
err := r.db.Model(&entity.Fishbone{}).Where("id = ?", id).Updates(updates).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *fishboneRepo) GetByID(id string) (entity.Fishbone, error) {
|
func (r *fishboneRepo) GetByID(id uuid.UUID) (entity.Fishbone, error) {
|
||||||
var fishbone entity.Fishbone
|
var fishbone entity.Fishbone
|
||||||
err := r.db.Where("id = ?", id).First(&fishbone).Error
|
err := r.db.Where("id = ?", id).First(&fishbone).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@ package repository
|
||||||
import (
|
import (
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TowerRepo interface {
|
type TowerRepo interface {
|
||||||
Post(tower entity.Tower) error
|
Post(tower entity.Tower) error
|
||||||
GetAll() ([]entity.Tower, error)
|
GetAll() ([]entity.Tower, error)
|
||||||
Update(tower entity.Tower) error
|
Update(id uuid.UUID,updates map[string]interface{}) error
|
||||||
GetByID(id string) (entity.Tower, error)
|
GetByID(id uuid.UUID) (entity.Tower, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type towerRepo struct {
|
type towerRepo struct {
|
||||||
|
|
@ -40,15 +41,15 @@ func (r *towerRepo) GetAll() ([]entity.Tower, error) {
|
||||||
return towers, nil
|
return towers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *towerRepo) Update(tower entity.Tower) error {
|
func (r *towerRepo) Update(id uuid.UUID,updates map[string]interface{}) error {
|
||||||
err := r.db.Save(&tower).Error
|
err := r.db.Model(&entity.Tower{}).Where("id = ?", id).Updates(updates).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *towerRepo) GetByID(id string) (entity.Tower, error) {
|
func (r *towerRepo) GetByID(id uuid.UUID) (entity.Tower, error) {
|
||||||
var tower entity.Tower
|
var tower entity.Tower
|
||||||
err := r.db.Where("id = ?", id).First(&tower).Error
|
err := r.db.Where("id = ?", id).First(&tower).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ type BackboneUseCase interface {
|
||||||
CreateBackbone(backbone req.BackboneDTO) error
|
CreateBackbone(backbone req.BackboneDTO) error
|
||||||
GetAllBackbone() ([]entity.Backbone, error)
|
GetAllBackbone() ([]entity.Backbone, error)
|
||||||
|
|
||||||
GetByID(id string) (entity.Backbone, error)
|
GetByID(id uuid.UUID) (entity.Backbone, error)
|
||||||
|
UpdateBackbone(id uuid.UUID, backbone req.UpdateBackboneDTO) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type backboneUseCase struct {
|
type backboneUseCase struct {
|
||||||
|
|
@ -57,10 +58,35 @@ func (u *backboneUseCase) GetAllBackbone() ([]entity.Backbone, error) {
|
||||||
return backbones, nil
|
return backbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *backboneUseCase) GetByID(id string) (entity.Backbone, error) {
|
func (u *backboneUseCase) GetByID(id uuid.UUID) (entity.Backbone, error) {
|
||||||
backbone, err := u.backboneRepo.GetByID(id)
|
backbone, err := u.backboneRepo.GetByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return backbone, err
|
return backbone, err
|
||||||
}
|
}
|
||||||
return backbone, nil
|
return backbone, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *backboneUseCase) UpdateBackbone(id uuid.UUID, backbone req.UpdateBackboneDTO) error {
|
||||||
|
err := u.validate.Struct(backbone)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("validation error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
updates := make(map[string]interface{})
|
||||||
|
|
||||||
|
if backbone.DeviceStartID != nil {
|
||||||
|
updates["DeviceStartID"] = backbone.DeviceStartID
|
||||||
|
}
|
||||||
|
|
||||||
|
if backbone.DeviceEndID != nil {
|
||||||
|
updates["DeviceEndID"] = backbone.DeviceEndID
|
||||||
|
}
|
||||||
|
|
||||||
|
if backbone.CoreAmount != nil {
|
||||||
|
updates["CoreAmount"] = backbone.CoreAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
updates["UpdatedAt"] = time.Now()
|
||||||
|
|
||||||
|
return u.backboneRepo.Update(id, updates)
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,8 @@ type DevicePortUseCase interface {
|
||||||
CreateDevicePort(devicePort req.DevicePort) error
|
CreateDevicePort(devicePort req.DevicePort) error
|
||||||
GetAllDevicePort() ([]entity.DevicePort, error)
|
GetAllDevicePort() ([]entity.DevicePort, error)
|
||||||
|
|
||||||
GetByID(id string) (entity.DevicePort, error)
|
GetByID(id uuid.UUID) (entity.DevicePort, error)
|
||||||
|
UpdateDevicePort(id uuid.UUID, devicePort req.UpdateDevicePort) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicePortUseCase struct {
|
type devicePortUseCase struct {
|
||||||
|
|
@ -54,7 +55,7 @@ func (u *devicePortUseCase) GetAllDevicePort() ([]entity.DevicePort, error) {
|
||||||
return devicePorts, nil
|
return devicePorts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *devicePortUseCase) GetByID(id string) (entity.DevicePort, error) {
|
func (u *devicePortUseCase) GetByID(id uuid.UUID) (entity.DevicePort, error) {
|
||||||
devicePort, err := u.devicePortRepo.GetByID(id)
|
devicePort, err := u.devicePortRepo.GetByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return devicePort, err
|
return devicePort, err
|
||||||
|
|
@ -62,3 +63,24 @@ func (u *devicePortUseCase) GetByID(id string) (entity.DevicePort, error) {
|
||||||
|
|
||||||
return devicePort, nil
|
return devicePort, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *devicePortUseCase) UpdateDevicePort(id uuid.UUID, devicePort req.UpdateDevicePort) error {
|
||||||
|
err := u.validate.Struct(devicePort)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
updates := make(map[string]interface{})
|
||||||
|
|
||||||
|
if devicePort.DeviceID != nil {
|
||||||
|
updates["DeviceID"] = *devicePort.DeviceID
|
||||||
|
}
|
||||||
|
|
||||||
|
if devicePort.PortNumber != nil {
|
||||||
|
updates["PortNumber"] = *devicePort.PortNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
updates["UpdatedAt"] = time.Now()
|
||||||
|
|
||||||
|
return u.devicePortRepo.Update(id, updates)
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,8 @@ type DeviceUseCase interface {
|
||||||
CreateDevice(device req.DeviceDTO) error
|
CreateDevice(device req.DeviceDTO) error
|
||||||
GetAllDevices() ([]entity.Device, error)
|
GetAllDevices() ([]entity.Device, error)
|
||||||
|
|
||||||
GetByID(id string) (entity.Device, error)
|
GetByID(id uuid.UUID) (entity.Device, error)
|
||||||
|
UpdateDevice(id uuid.UUID, device req.UpdateDeviceDTO) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type deviceUseCase struct {
|
type deviceUseCase struct {
|
||||||
|
|
@ -59,10 +60,43 @@ func (u *deviceUseCase) GetAllDevices() ([]entity.Device, error) {
|
||||||
return devices, nil
|
return devices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *deviceUseCase) GetByID(id string) (entity.Device, error) {
|
func (u *deviceUseCase) GetByID(id uuid.UUID) (entity.Device, error) {
|
||||||
device, err := u.deviceRepo.GetByID(id)
|
device, err := u.deviceRepo.GetByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return device, err
|
return device, err
|
||||||
}
|
}
|
||||||
return device, nil
|
return device, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *deviceUseCase) UpdateDevice(id uuid.UUID, device req.UpdateDeviceDTO) error {
|
||||||
|
err := u.validate.Struct(device)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("validation error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
updates := map[string]interface{}{}
|
||||||
|
|
||||||
|
if device.DeviceCode != nil {
|
||||||
|
updates["DeviceCode"] = *device.DeviceCode
|
||||||
|
}
|
||||||
|
if device.DeviceType != nil {
|
||||||
|
updates["DeviceType"] = *device.DeviceType
|
||||||
|
}
|
||||||
|
if device.Longitude != nil {
|
||||||
|
updates["Longitude"] = *device.Longitude
|
||||||
|
}
|
||||||
|
if device.Latitude != nil {
|
||||||
|
updates["Latitude"] = *device.Latitude
|
||||||
|
}
|
||||||
|
if device.PortAmount != nil {
|
||||||
|
updates["PortAmount"] = *device.PortAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(updates) == 0 {
|
||||||
|
return fmt.Errorf("no update data")
|
||||||
|
}
|
||||||
|
|
||||||
|
updates["UpdatedAt"] = time.Now()
|
||||||
|
|
||||||
|
return u.deviceRepo.Update(id, updates)
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package usecase
|
package usecase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
"users_management/m/model/dto/req"
|
"users_management/m/model/dto/req"
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
@ -13,7 +14,9 @@ import (
|
||||||
type FishboneUseCase interface {
|
type FishboneUseCase interface {
|
||||||
CreateFishbone(fishbone req.FishboneDTO) error
|
CreateFishbone(fishbone req.FishboneDTO) error
|
||||||
GetAllFishbone() ([]entity.Fishbone, error)
|
GetAllFishbone() ([]entity.Fishbone, error)
|
||||||
GetByID(id string) (entity.Fishbone, error)
|
GetByID(id uuid.UUID) (entity.Fishbone, error)
|
||||||
|
|
||||||
|
UpdateFishbone(id uuid.UUID, fishbone req.UpdateFishboneDTO) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type fishboneUsecase struct {
|
type fishboneUsecase struct {
|
||||||
|
|
@ -55,10 +58,39 @@ func (u *fishboneUsecase) GetAllFishbone() ([]entity.Fishbone, error) {
|
||||||
return fishbones, nil
|
return fishbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *fishboneUsecase) GetByID(id string) (entity.Fishbone, error) {
|
func (u *fishboneUsecase) GetByID(id uuid.UUID) (entity.Fishbone, error) {
|
||||||
fishbone, err := u.fishboneRepo.GetByID(id)
|
fishbone, err := u.fishboneRepo.GetByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fishbone, err
|
return fishbone, err
|
||||||
}
|
}
|
||||||
return fishbone, nil
|
return fishbone, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *fishboneUsecase) UpdateFishbone(id uuid.UUID, fishbone req.UpdateFishboneDTO) error {
|
||||||
|
err := u.validate.Struct(fishbone)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
updates := make(map[string]interface{})
|
||||||
|
|
||||||
|
if fishbone.BackboneID != nil {
|
||||||
|
updates["BackboneID"] = *fishbone.BackboneID
|
||||||
|
}
|
||||||
|
if fishbone.DeviceStartID != nil {
|
||||||
|
updates["DeviceStartID"] = *fishbone.DeviceStartID
|
||||||
|
}
|
||||||
|
if fishbone.DeviceEndID != nil {
|
||||||
|
updates["DeviceEndID"] = *fishbone.DeviceEndID
|
||||||
|
}
|
||||||
|
if fishbone.CoreAmount != nil {
|
||||||
|
updates["CoreAmount"] = *fishbone.CoreAmount
|
||||||
|
}
|
||||||
|
if len(updates) == 0 {
|
||||||
|
return errors.New("no fields to update")
|
||||||
|
}
|
||||||
|
|
||||||
|
updates["UpdatedAt"] = time.Now()
|
||||||
|
|
||||||
|
return u.fishboneRepo.Update(id, updates)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package usecase
|
package usecase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
"users_management/m/model/dto/req"
|
"users_management/m/model/dto/req"
|
||||||
"users_management/m/model/entity"
|
"users_management/m/model/entity"
|
||||||
|
|
@ -13,7 +14,8 @@ import (
|
||||||
type TowerUseCase interface {
|
type TowerUseCase interface {
|
||||||
Post(tower req.TowerDTO) error
|
Post(tower req.TowerDTO) error
|
||||||
GetAll() ([]entity.Tower, error)
|
GetAll() ([]entity.Tower, error)
|
||||||
GetByID(id string) (entity.Tower, error)
|
GetByID(id uuid.UUID) (entity.Tower, error)
|
||||||
|
UpdateTower(id uuid.UUID, tower req.UpdateTowerDTO) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type towerUsecase struct {
|
type towerUsecase struct {
|
||||||
|
|
@ -56,10 +58,40 @@ func (u *towerUsecase) GetAll() ([]entity.Tower, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (u *towerUsecase) GetByID(id string) (entity.Tower, error) {
|
func (u *towerUsecase) GetByID(id uuid.UUID) (entity.Tower, error) {
|
||||||
tower, err := u.towerRepo.GetByID(id)
|
tower, err := u.towerRepo.GetByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tower, err
|
return tower, err
|
||||||
}
|
}
|
||||||
return tower, nil
|
return tower, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *towerUsecase) UpdateTower(id uuid.UUID, tower req.UpdateTowerDTO) error {
|
||||||
|
err := u.validate.Struct(tower)
|
||||||
|
if err != nil {
|
||||||
|
return err // Return validation error
|
||||||
|
}
|
||||||
|
updates := make(map[string]interface{})
|
||||||
|
|
||||||
|
if tower.DeviceID != nil {
|
||||||
|
updates["DeviceID"] = *tower.DeviceID
|
||||||
|
}
|
||||||
|
if tower.TowerCode != nil {
|
||||||
|
updates["TowerCode"] = *tower.TowerCode
|
||||||
|
}
|
||||||
|
if tower.Longitude != nil {
|
||||||
|
updates["Longitude"] = *tower.Longitude
|
||||||
|
}
|
||||||
|
if tower.Latitude != nil {
|
||||||
|
updates["Latitude"] = *tower.Latitude
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no fields are updated, return an error
|
||||||
|
if len(updates) == 0 {
|
||||||
|
return errors.New("no fields to update")
|
||||||
|
}
|
||||||
|
|
||||||
|
updates["UpdatedAt"] = time.Now()
|
||||||
|
|
||||||
|
return u.towerRepo.Update(id, updates)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue