Skip to content

Commit

Permalink
feat: change conditionID column nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
barabobBOB committed May 1, 2024
1 parent 6db15cb commit d270a10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/domain/sospost/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type WriteSOSPostRequest struct {
CareType CareType `json:"careType" validate:"required,oneof=foster visiting"`
CarerGender CarerGender `json:"carerGender" validate:"required,oneof=male female all"`
RewardType RewardType `json:"rewardType" validate:"required,oneof=fee gifticon negotiable"`
ConditionIDs []int `json:"conditionIds" validate:"required,gte=1"`
ConditionIDs []int `json:"conditionIds" validate:"required"`
PetIDs []int64 `json:"petIds" validate:"required,gte=1"`
}

Expand Down Expand Up @@ -165,7 +165,7 @@ type UpdateSOSPostRequest struct {
CareType CareType `json:"careType" validate:"required,oneof=foster visiting"`
CarerGender CarerGender `json:"carerGender" validate:"required,oneof=male female all"`
RewardType RewardType `json:"rewardType" validate:"required,oneof=fee gifticon negotiable"`
ConditionIDs []int `json:"conditionIds" validate:"required,gte=1"`
ConditionIDs []int `json:"conditionIds" validate:"required"`
PetIDs []int `json:"petIds" validate:"required,gte=1"`
}

Expand Down
8 changes: 6 additions & 2 deletions internal/postgres/sos_post_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ func readSOSPostRows(rows *sql.Rows, page, size int) (*sospost.SOSPostInfoList,
} else {
sosPost.Media = media.ViewListForSOSPost{}
}
if err := json.Unmarshal(conditionsData, &sosPost.Conditions); err != nil {
return nil, pnd.FromPostgresError(err)
if len(conditionsData) > 0 {
if err := json.Unmarshal(conditionsData, &sosPost.Conditions); err != nil {
return nil, pnd.FromPostgresError(err)
}
} else {
sosPost.Conditions = soscondition.ViewListForSOSPost{}
}
sosPostList.Items = append(sosPostList.Items, sosPost)
}
Expand Down

0 comments on commit d270a10

Please sign in to comment.