Skip to content

Commit

Permalink
feat(dp): Use mutable installation params for mutable cbsd API (#12891)
Browse files Browse the repository at this point in the history
Previously same models were used for both mutable and read API,
but users should only be able to edit certain fields (antenna gain).

Signed-off-by: Kuba Marciniszyn <kuba@freedomfi.com>
  • Loading branch information
jkmar committed Jun 2, 2022
1 parent da4855c commit 48a2260
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 168 deletions.
30 changes: 4 additions & 26 deletions dp/cloud/go/services/dp/builders/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func NewCbsdProtoPayloadBuilder() *CbsdProtoPayloadBuilder {
DesiredState: registered,
CbsdCategory: catB,
SingleStepEnabled: false,
InstallationParam: &protos.InstallationParam{},
},
}
}
Expand Down Expand Up @@ -441,7 +442,7 @@ type CbsdModelPayloadBuilder struct {

func NewCbsdModelPayloadBuilder() *CbsdModelPayloadBuilder {
return &CbsdModelPayloadBuilder{Payload: &models.Cbsd{
Capabilities: &models.Capabilities{
Capabilities: models.Capabilities{
MaxPower: to_pointer.Float(20),
MinPower: to_pointer.Float(10),
NumberOfAntennas: 2,
Expand Down Expand Up @@ -496,7 +497,7 @@ type MutableCbsdModelBuilder struct {

func NewMutableCbsdModelPayloadBuilder() *MutableCbsdModelBuilder {
return &MutableCbsdModelBuilder{Payload: &models.MutableCbsd{
Capabilities: &models.Capabilities{
Capabilities: models.Capabilities{
MaxPower: to_pointer.Float(20),
MinPower: to_pointer.Float(10),
NumberOfAntennas: 2,
Expand Down Expand Up @@ -530,22 +531,11 @@ func (b *MutableCbsdModelBuilder) WithFccId(id string) *MutableCbsdModelBuilder
}

func (b *MutableCbsdModelBuilder) WithEmptyInstallationParam() *MutableCbsdModelBuilder {
b.Payload.InstallationParam = &models.InstallationParam{}
return b
}

func (b *MutableCbsdModelBuilder) WithHeightType(heightType string) *MutableCbsdModelBuilder {
if b.Payload.InstallationParam == nil {
b.Payload.InstallationParam = &models.InstallationParam{}
}
b.Payload.InstallationParam.HeightType = to_pointer.String(heightType)
b.Payload.InstallationParam = models.MutableInstallationParam{}
return b
}

func (b *MutableCbsdModelBuilder) WithAntennaGain(gain float64) *MutableCbsdModelBuilder {
if b.Payload.InstallationParam == nil {
b.Payload.InstallationParam = &models.InstallationParam{}
}
b.Payload.InstallationParam.AntennaGain = to_pointer.Float(gain)
return b
}
Expand Down Expand Up @@ -579,18 +569,6 @@ func (b *MutableCbsdModelBuilder) WithSingleStepEnabled(enabled *bool) *MutableC
return b
}

func (b *MutableCbsdModelBuilder) WithIndoorDeployment(indoor *bool) *MutableCbsdModelBuilder {
if b.Payload.InstallationParam == nil {
b.Payload.InstallationParam = &models.InstallationParam{}
}
if indoor == nil {
b.Payload.InstallationParam.IndoorDeployment = nil
} else {
b.Payload.InstallationParam.IndoorDeployment = to_pointer.Bool(*indoor)
}
return b
}

func (b *MutableCbsdModelBuilder) WithMinPower(power *float64) *MutableCbsdModelBuilder {
if power == nil {
b.Payload.Capabilities.MinPower = nil
Expand Down
68 changes: 26 additions & 42 deletions dp/cloud/go/services/dp/obsidian/models/cbsd_swaggergen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 8 additions & 23 deletions dp/cloud/go/services/dp/obsidian/models/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ func CbsdToBackend(m *MutableCbsd) *protos.CbsdData {
BandwidthMhz: m.FrequencyPreferences.BandwidthMhz,
FrequenciesMhz: m.FrequencyPreferences.FrequenciesMhz,
},
DesiredState: m.DesiredState,
InstallationParam: getProtoInstallationParam(m.InstallationParam),
DesiredState: m.DesiredState,
InstallationParam: &protos.InstallationParam{
AntennaGain: to_pointer.FloatToDoubleValue(m.InstallationParam.AntennaGain),
},
}
}

func CbsdFromBackend(details *protos.CbsdDetails) *Cbsd {
return &Cbsd{
Capabilities: &Capabilities{
Capabilities: Capabilities{
MaxPower: &details.Data.Capabilities.MaxPower,
MinPower: &details.Data.Capabilities.MinPower,
NumberOfAntennas: details.Data.Capabilities.NumberOfAntennas,
Expand All @@ -63,7 +65,7 @@ func CbsdFromBackend(details *protos.CbsdDetails) *Cbsd {
UserID: details.Data.UserId,
SingleStepEnabled: details.Data.SingleStepEnabled,
CbsdCategory: details.Data.CbsdCategory,
InstallationParam: getModelInstallationParam(details.Data.GetInstallationParam()),
InstallationParam: getModelInstallationParam(details.Data.InstallationParam),
}
}

Expand All @@ -88,11 +90,8 @@ func getGrant(grant *protos.GrantDetails) *Grant {
}
}

func getModelInstallationParam(params *protos.InstallationParam) *InstallationParam {
if params == nil {
return nil
}
return &InstallationParam{
func getModelInstallationParam(params *protos.InstallationParam) InstallationParam {
return InstallationParam{
AntennaGain: to_pointer.DoubleValueToFloat(params.AntennaGain),
Heightm: to_pointer.DoubleValueToFloat(params.HeightM),
HeightType: to_pointer.StringValueToString(params.HeightType),
Expand All @@ -102,20 +101,6 @@ func getModelInstallationParam(params *protos.InstallationParam) *InstallationPa
}
}

func getProtoInstallationParam(params *InstallationParam) *protos.InstallationParam {
if params == nil {
return nil
}
return &protos.InstallationParam{
AntennaGain: to_pointer.FloatToDoubleValue(params.AntennaGain),
HeightM: to_pointer.FloatToDoubleValue(params.Heightm),
HeightType: to_pointer.StringToStringValue(params.HeightType),
IndoorDeployment: to_pointer.BoolToBoolValue(params.IndoorDeployment),
LatitudeDeg: to_pointer.FloatToDoubleValue(params.LatitudeDeg),
LongitudeDeg: to_pointer.FloatToDoubleValue(params.LongitudeDeg),
}
}

type LogInterface struct {
Body string `json:"log_message"`
FccID string `json:"fcc_id"`
Expand Down
2 changes: 1 addition & 1 deletion dp/cloud/go/services/dp/obsidian/models/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestCbsdFromBackendWithoutInstallationParam(t *testing.T) {
details := b.NewDetailedProtoCbsdBuilder(
b.NewCbsdProtoPayloadBuilder()).Details
data := models.CbsdFromBackend(details)
assert.Nil(t, data.InstallationParam)
assert.Empty(t, data.InstallationParam)
}

func TestCbsdFromBackendWithInstallationParam(t *testing.T) {
Expand Down
64 changes: 26 additions & 38 deletions dp/cloud/go/services/dp/obsidian/models/mutable_cbsd_swaggergen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48a2260

Please sign in to comment.