adding get by id
This commit is contained in:
parent
b79701e87c
commit
adf2d1f379
|
|
@ -18,6 +18,7 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBackboneController(bu usecase.BackboneUseCase, rg *gin.RouterGroup) *BackboneController {
|
func NewBackboneController(bu usecase.BackboneUseCase, rg *gin.RouterGroup) *BackboneController {
|
||||||
|
|
@ -60,3 +61,17 @@ func (bc *BackboneController) CreateBackbone() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Backbone has been created", nil)
|
common.SingleResponses(c, "Backbone has been created", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bc *BackboneController) GetBackboneByID() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
backbone, err := bc.bu.GetByID(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Success", backbone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevicePortController(du usecase.DevicePortUseCase, rg *gin.RouterGroup) *DevicePortController {
|
func NewDevicePortController(du usecase.DevicePortUseCase, rg *gin.RouterGroup) *DevicePortController {
|
||||||
|
|
@ -60,3 +61,17 @@ func (dc *DevicePortController) CreateDevicePort() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Device Port has been created", nil)
|
common.SingleResponses(c, "Device Port has been created", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *DevicePortController) GetDevicePortByID() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
devicePort, err := dc.du.GetByID(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Success", devicePort)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeviceController(du usecase.DeviceUseCase, rg *gin.RouterGroup) *DeviceController {
|
func NewDeviceController(du usecase.DeviceUseCase, rg *gin.RouterGroup) *DeviceController {
|
||||||
|
|
@ -60,3 +61,17 @@ func (dc *DeviceController) GetAllDevices() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Success", devices)
|
common.SingleResponses(c, "Success", devices)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *DeviceController) GetDeviceByID() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
device, err := dc.du.GetByID(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Success", device)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFishboneController(fu usecase.FishboneUseCase, rg *gin.RouterGroup) *FishboneController {
|
func NewFishboneController(fu usecase.FishboneUseCase, rg *gin.RouterGroup) *FishboneController {
|
||||||
|
|
@ -60,3 +61,17 @@ func (fc *FishboneController) CreateFishbone() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Fishbone has been created", nil)
|
common.SingleResponses(c, "Fishbone has been created", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fc *FishboneController) GetFishboneByID() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
fishbone, err := fc.fu.GetByID(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Success", fishbone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTowerController(tu usecase.TowerUseCase, rg *gin.RouterGroup) *TowerController {
|
func NewTowerController(tu usecase.TowerUseCase, rg *gin.RouterGroup) *TowerController {
|
||||||
|
|
@ -60,3 +61,17 @@ func (tc *TowerController) CreateTower() gin.HandlerFunc {
|
||||||
common.SingleResponses(c, "Tower has been created", nil)
|
common.SingleResponses(c, "Tower has been created", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tc *TowerController) GetTowerByID() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
tower, err := tc.tu.GetByID(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SingleResponses(c, "Success", tower)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ 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(backbone entity.Backbone) error
|
||||||
|
|
||||||
|
GetByID(id string) (entity.Backbone, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type backboneRepo struct {
|
type backboneRepo struct {
|
||||||
|
|
@ -46,3 +48,12 @@ func (r *backboneRepo) Update(backbone entity.Backbone) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *backboneRepo) GetByID(id string) (entity.Backbone, error) {
|
||||||
|
var backbone entity.Backbone
|
||||||
|
err := r.db.Where("id = ?", id).First(&backbone).Error
|
||||||
|
if err != nil {
|
||||||
|
return backbone, err
|
||||||
|
}
|
||||||
|
return backbone, nil
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ 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(devicePort entity.DevicePort) error
|
||||||
|
|
||||||
|
GetByID(id string) (entity.DevicePort, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicePortRepo struct {
|
type devicePortRepo struct {
|
||||||
|
|
@ -46,3 +48,13 @@ func (r *devicePortRepo) Update(devicePort entity.DevicePort) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *devicePortRepo) GetByID(id string) (entity.DevicePort, error) {
|
||||||
|
var devicePort entity.DevicePort
|
||||||
|
err := r.db.Where("id = ?", id).First(&devicePort).Error
|
||||||
|
if err != nil {
|
||||||
|
return devicePort, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return devicePort, nil
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ 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(device entity.Device) error
|
||||||
|
|
||||||
|
GetByID(id string) (entity.Device, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicesRepo struct {
|
type devicesRepo struct {
|
||||||
|
|
@ -45,3 +47,12 @@ func (r *devicesRepo) Update(device entity.Device) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *devicesRepo) GetByID(id string) (entity.Device, error) {
|
||||||
|
var device entity.Device
|
||||||
|
err := r.db.Where("id = ?", id).First(&device).Error
|
||||||
|
if err != nil {
|
||||||
|
return device, err
|
||||||
|
}
|
||||||
|
return device, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ 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(fishbone entity.Fishbone) error
|
||||||
|
|
||||||
|
GetByID(id string) (entity.Fishbone, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fishboneRepo struct {
|
type fishboneRepo struct {
|
||||||
|
|
@ -46,3 +48,12 @@ func (r *fishboneRepo) Update(fishbone entity.Fishbone) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *fishboneRepo) GetByID(id string) (entity.Fishbone, error) {
|
||||||
|
var fishbone entity.Fishbone
|
||||||
|
err := r.db.Where("id = ?", id).First(&fishbone).Error
|
||||||
|
if err != nil {
|
||||||
|
return fishbone, err
|
||||||
|
}
|
||||||
|
return fishbone, nil
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ 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(tower entity.Tower) error
|
||||||
|
GetByID(id string) (entity.Tower, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type towerRepo struct {
|
type towerRepo struct {
|
||||||
|
|
@ -46,3 +47,12 @@ func (r *towerRepo) Update(tower entity.Tower) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *towerRepo) GetByID(id string) (entity.Tower, error) {
|
||||||
|
var tower entity.Tower
|
||||||
|
err := r.db.Where("id = ?", id).First(&tower).Error
|
||||||
|
if err != nil {
|
||||||
|
return tower, err
|
||||||
|
}
|
||||||
|
return tower, nil
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,8 @@ import (
|
||||||
type BackboneUseCase interface {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type backboneUseCase struct {
|
type backboneUseCase struct {
|
||||||
|
|
@ -54,3 +56,11 @@ func (u *backboneUseCase) GetAllBackbone() ([]entity.Backbone, error) {
|
||||||
}
|
}
|
||||||
return backbones, nil
|
return backbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *backboneUseCase) GetByID(id string) (entity.Backbone, error) {
|
||||||
|
backbone, err := u.backboneRepo.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return backbone, err
|
||||||
|
}
|
||||||
|
return backbone, nil
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,8 @@ import (
|
||||||
type DevicePortUseCase interface {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type devicePortUseCase struct {
|
type devicePortUseCase struct {
|
||||||
|
|
@ -51,3 +53,12 @@ func (u *devicePortUseCase) GetAllDevicePort() ([]entity.DevicePort, error) {
|
||||||
}
|
}
|
||||||
return devicePorts, nil
|
return devicePorts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *devicePortUseCase) GetByID(id string) (entity.DevicePort, error) {
|
||||||
|
devicePort, err := u.devicePortRepo.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return devicePort, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return devicePort, nil
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,8 @@ import (
|
||||||
type DeviceUseCase interface {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type deviceUseCase struct {
|
type deviceUseCase struct {
|
||||||
|
|
@ -56,3 +58,11 @@ func (u *deviceUseCase) GetAllDevices() ([]entity.Device, error) {
|
||||||
}
|
}
|
||||||
return devices, nil
|
return devices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *deviceUseCase) GetByID(id string) (entity.Device, error) {
|
||||||
|
device, err := u.deviceRepo.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return device, err
|
||||||
|
}
|
||||||
|
return device, nil
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fishboneUsecase struct {
|
type fishboneUsecase struct {
|
||||||
|
|
@ -53,3 +54,11 @@ func (u *fishboneUsecase) GetAllFishbone() ([]entity.Fishbone, error) {
|
||||||
}
|
}
|
||||||
return fishbones, nil
|
return fishbones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *fishboneUsecase) GetByID(id string) (entity.Fishbone, error) {
|
||||||
|
fishbone, err := u.fishboneRepo.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return fishbone, err
|
||||||
|
}
|
||||||
|
return fishbone, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type towerUsecase struct {
|
type towerUsecase struct {
|
||||||
|
|
@ -53,3 +54,12 @@ func (u *towerUsecase) GetAll() ([]entity.Tower, error) {
|
||||||
}
|
}
|
||||||
return towers, nil
|
return towers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (u *towerUsecase) GetByID(id string) (entity.Tower, error) {
|
||||||
|
tower, err := u.towerRepo.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return tower, err
|
||||||
|
}
|
||||||
|
return tower, nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue