diff --git a/api/memo.go b/api/memo.go index 43d8f773..0d49399e 100644 --- a/api/memo.go +++ b/api/memo.go @@ -42,8 +42,8 @@ type MemoCreate struct { CreatedTs *int64 `json:"createdTs"` // Domain specific fields - Content string `json:"content"` - Visibility Visibility `json:"visibility"` + Content string `json:"content"` + Visibility *Visibility `json:"visibility"` } type MemoPatch struct { diff --git a/server/memo.go b/server/memo.go index babe1ce2..25df508f 100644 --- a/server/memo.go +++ b/server/memo.go @@ -22,8 +22,10 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err) } - // TODO(steven): remove this line after frontend is ready - memoCreate.Visibility = api.Privite + if memoCreate.Visibility == nil || *memoCreate.Visibility == "" { + private := api.Privite + memoCreate.Visibility = &private + } memo, err := s.Store.CreateMemo(memoCreate) if err != nil { diff --git a/store/memo.go b/store/memo.go index 1019daa9..7512d93c 100644 --- a/store/memo.go +++ b/store/memo.go @@ -118,10 +118,13 @@ func (s *Store) DeleteMemo(delete *api.MemoDelete) error { } func createMemoRaw(db *sql.DB, create *api.MemoCreate) (*memoRaw, error) { - set := []string{"creator_id", "content", "visibility"} - placeholder := []string{"?", "?", "?"} - args := []interface{}{create.CreatorID, create.Content, create.Visibility} + set := []string{"creator_id", "content"} + placeholder := []string{"?", "?"} + args := []interface{}{create.CreatorID, create.Content} + if v := create.Visibility; v != nil { + set, placeholder, args = append(set, "visibility"), append(placeholder, "?"), append(args, *v) + } if v := create.CreatedTs; v != nil { set, placeholder, args = append(set, "created_ts"), append(placeholder, "?"), append(args, *v) } diff --git a/web/src/types/modules/memo.d.ts b/web/src/types/modules/memo.d.ts index 6b4e1e8c..867cb794 100644 --- a/web/src/types/modules/memo.d.ts +++ b/web/src/types/modules/memo.d.ts @@ -17,6 +17,7 @@ interface Memo { interface MemoCreate { content: string; + visibility?: Visibility; createdTs?: TimeStamp; }