Mercurial > gemma
diff pkg/models/import.go @ 1469:286a3306f6bf bulkreview
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 30 Nov 2018 09:15:47 +0100 |
parents | 0e1d89241cda |
children | ccf4fc8a6402 |
line wrap: on
line diff
--- a/pkg/models/import.go Thu Nov 29 12:09:01 2018 +0100 +++ b/pkg/models/import.go Fri Nov 30 09:15:47 2018 +0100 @@ -15,6 +15,7 @@ import ( "encoding/json" + "errors" "time" ) @@ -36,8 +37,29 @@ Kind string `json:"kind"` Message string `json:"message"` } + + ReviewState string + + Review struct { + ID int64 `json:"id"` + State ReviewState `json:"state"` + } ) +var errInvalidReviewState = errors.New("state is wether 'accepted' nor 'declined'") + +func (rs *ReviewState) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + if s != "accepted" && s != "declined" { + return errInvalidReviewState + } + *rs = ReviewState(s) + return nil +} + func (it ImportTime) MarshalJSON() ([]byte, error) { return json.Marshal(it.Format("2006-01-02T15:04:05")) }