chore: update create memo with visibility

This commit is contained in:
boojack 2022-07-15 21:25:07 +08:00
parent 3517c6181d
commit 6053df050c
4 changed files with 13 additions and 7 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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)
}

View File

@ -17,6 +17,7 @@ interface Memo {
interface MemoCreate {
content: string;
visibility?: Visibility;
createdTs?: TimeStamp;
}