Added create contact ednpoint
This commit is contained in:
@@ -4,15 +4,54 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
|
||||
type Device struct {
|
||||
gorm.Model
|
||||
DeviceID string `json:"deviceId"`
|
||||
DeviceName string
|
||||
DeviceID string `json:"deviceId"`
|
||||
DeviceName string `json:"deviceName"`
|
||||
IMEI string `json:"imei"`
|
||||
IMSI string `json:"imsi"`
|
||||
DeviceConfiguration string `gorm:"type:json"`
|
||||
CompanyID uint
|
||||
DeviceInfos []DeviceInfo
|
||||
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
|
||||
CompanyID uint `json:"companyId"`
|
||||
DeviceInfos *[]DeviceInfo `json:"deviceInfos"`
|
||||
}
|
||||
|
||||
type DeviceResponse struct {
|
||||
BaseModel
|
||||
DeviceID string `json:"deviceId"`
|
||||
DeviceName string `json:"deviceName"`
|
||||
IMEI string `json:"imei"`
|
||||
IMSI string `json:"imsi"`
|
||||
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
|
||||
CompanyID uint `json:"companyId"`
|
||||
DeviceInfos *[]DeviceInfo `json:"deviceInfos"`
|
||||
}
|
||||
|
||||
func ConvertDeviceToResponse(devices []Device) []DeviceResponse {
|
||||
var deviceResponses []DeviceResponse
|
||||
for _, device := range devices {
|
||||
if device.DeviceInfos == nil {
|
||||
emptySlice := make([]DeviceInfo, 0)
|
||||
device.DeviceInfos = &emptySlice
|
||||
}
|
||||
|
||||
deviceResponse := DeviceResponse{
|
||||
BaseModel: BaseModel{
|
||||
ID: device.ID,
|
||||
CreatedAt: device.CreatedAt,
|
||||
UpdatedAt: device.UpdatedAt,
|
||||
},
|
||||
DeviceID: device.DeviceID,
|
||||
DeviceName: device.DeviceName,
|
||||
IMEI: device.IMEI,
|
||||
IMSI: device.IMSI,
|
||||
DeviceConfiguration: device.DeviceConfiguration,
|
||||
CompanyID: device.CompanyID,
|
||||
DeviceInfos: device.DeviceInfos,
|
||||
}
|
||||
deviceResponses = append(deviceResponses, deviceResponse)
|
||||
}
|
||||
return deviceResponses
|
||||
}
|
||||
|
||||
func (Device) Update() (bool, error) {
|
||||
@@ -30,3 +69,4 @@ func (d *Device) Delete(db *gorm.DB) (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user