Skip to content

Commit

Permalink
Merge pull request #933 from weichou1229/issue-931-2
Browse files Browse the repository at this point in the history
feat: Allow store reading value as null
  • Loading branch information
cloudxxx8 authored Oct 7, 2024
2 parents c49e7a4 + 11f0ae7 commit 4ed9aff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dtos/reading.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func ToReadingModel(r BaseReading) models.Reading {
} else {
readingModel = models.SimpleReading{
BaseReading: br,
Value: *r.Value,
Value: r.Value,
}
}
return readingModel
Expand Down Expand Up @@ -370,7 +370,7 @@ func FromReadingModelToDTO(reading models.Reading) BaseReading {
ValueType: r.ValueType,
Units: r.Units,
Tags: r.Tags,
SimpleReading: SimpleReading{Value: &r.Value},
SimpleReading: SimpleReading{Value: r.Value},
}
}

Expand Down
4 changes: 2 additions & 2 deletions dtos/reading_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_ToReadingModel(t *testing.T) {
Units: TestUnit,
Tags: testTags,
},
Value: TestValue,
Value: &TestSimpleValue,
}
tests := []struct {
name string
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestFromReadingModelToDTO(t *testing.T) {
Units: TestUnit,
Tags: testTags,
},
Value: TestValue,
Value: &TestSimpleValue,
}
expectedDTO := BaseReading{
Id: TestUUID,
Expand Down
3 changes: 2 additions & 1 deletion dtos/requests/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func TestAddEvent_UnmarshalCBOR(t *testing.T) {

func Test_AddEventReqToEventModels(t *testing.T) {
valid := eventRequestData()
testReadingValue := "45"
s := models.SimpleReading{
BaseReading: models.BaseReading{
Id: ExampleUUID,
Expand All @@ -290,7 +291,7 @@ func Test_AddEventReqToEventModels(t *testing.T) {
Origin: TestOriginTime,
ValueType: common.ValueTypeUint8,
},
Value: TestReadingValue,
Value: &testReadingValue,
}
expectedEventModel := models.Event{
Id: ExampleUUID,
Expand Down
2 changes: 1 addition & 1 deletion models/reading.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type BinaryReading struct {

type SimpleReading struct {
BaseReading `json:",inline"`
Value string
Value *string
}

type ObjectReading struct {
Expand Down

0 comments on commit 4ed9aff

Please sign in to comment.