Fix of User.ID serialization:

As @skolen mentioned out, the `ID` field of the embedded struct
    `Model` in the model `User` must be serialized so it can be included
    in the responses. In the previous commit we completely ignored the
    field with the tag `json:"-"` so we can compare the serialized
    request (where ID was 0) with the response of the API.

    To limit the omission of the `User.ID` field only for the case that
    its value is 0 we modify the tag to `json:",omitempty"`.
This commit is contained in:
smavros 2019-08-13 11:15:36 +02:00
parent 76658c3ed4
commit 0fb9bc9157

View file

@ -10,7 +10,7 @@ import (
// The type Model is exactly the same with gorm.Model (see jinzhu/gorm)
// except the json tags that are needed for serializing the models
type Model struct {
ID uint `json:"-" gorm:"unique;primary_key:true"`
ID uint `json:",omitempty" gorm:"unique;primary_key:true"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt *time.Time `json:"-" sql:"index"`