diff --git a/api/memo.go b/api/memo.go index c86323d7..c9ac227f 100644 --- a/api/memo.go +++ b/api/memo.go @@ -21,6 +21,7 @@ type MemoPatch struct { Content *string `json:"content"` RowStatus *string `json:"rowStatus"` + CreatedTs *int64 `json:"createdTs"` } type MemoFind struct { diff --git a/common/error.go b/common/error.go index d96277d6..ef792ed4 100644 --- a/common/error.go +++ b/common/error.go @@ -22,29 +22,6 @@ const ( DbConnectionFailure Code = 101 DbStatementSyntaxError Code = 102 DbExecutionError Code = 103 - - // 201 db migration error - // Db migration is a core feature, so we separate it from the db error - MigrationSchemaMissing Code = 201 - MigrationAlreadyApplied Code = 202 - MigrationOutOfOrder Code = 203 - MigrationBaselineMissing Code = 204 - - // 301 task error - TaskTimingNotAllowed Code = 301 - - // 10001 advisor error code - CompatibilityDropDatabase Code = 10001 - CompatibilityRenameTable Code = 10002 - CompatibilityDropTable Code = 10003 - CompatibilityRenameColumn Code = 10004 - CompatibilityDropColumn Code = 10005 - CompatibilityAddPrimaryKey Code = 10006 - CompatibilityAddUniqueKey Code = 10007 - CompatibilityAddForeignKey Code = 10008 - CompatibilityAddCheck Code = 10009 - CompatibilityAlterCheck Code = 10010 - CompatibilityAlterColumn Code = 10011 ) // Error represents an application-specific error. Application errors can be diff --git a/server/auth.go b/server/auth.go index 466779be..63ffb609 100644 --- a/server/auth.go +++ b/server/auth.go @@ -23,10 +23,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { } user, err := s.UserService.FindUser(userFind) if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err) + return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by name %s", login.Name)).SetInternal(err) } if user == nil { - return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found: %s", login.Name)) + return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found with name %s", login.Name)) } // Compare the stored hashed password, with the hashed version of the password that was received. @@ -35,8 +35,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect password").SetInternal(err) } - err = setUserSession(c, user) - if err != nil { + if err = setUserSession(c, user); err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set login session").SetInternal(err) } @@ -64,10 +63,12 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signup request").SetInternal(err) } - if len(signup.Name) <= 5 { + // Validate signup form. + // We can do stricter checks later. + if len(signup.Name) < 6 { return echo.NewHTTPError(http.StatusBadRequest, "Username is too short, minimum length is 6.") } - if len(signup.Password) <= 5 { + if len(signup.Password) < 6 { return echo.NewHTTPError(http.StatusBadRequest, "Password is too short, minimum length is 6.") } @@ -76,10 +77,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { } user, err := s.UserService.FindUser(userFind) if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err) + return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by name %s", signup.Name)).SetInternal(err) } if user != nil { - return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Existed user found: %s", signup.Name)) + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Existed user found: %s", signup.Name)) } passwordHash, err := bcrypt.GenerateFromPassword([]byte(signup.Password), bcrypt.DefaultCost) diff --git a/server/memo.go b/server/memo.go index b8d33aee..6284c4f5 100644 --- a/server/memo.go +++ b/server/memo.go @@ -65,17 +65,11 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { memoFind := &api.MemoFind{ CreatorId: &userId, } - showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden")) - if err != nil { - showHiddenMemo = false + rowStatus := c.QueryParam("rowStatus") + if rowStatus != "" { + memoFind.RowStatus = &rowStatus } - rowStatus := "NORMAL" - if showHiddenMemo { - rowStatus = "HIDDEN" - } - memoFind.RowStatus = &rowStatus - list, err := s.MemoService.FindMemoList(memoFind) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err) diff --git a/server/webhook.go b/server/webhook.go index 72504385..fb944cb8 100644 --- a/server/webhook.go +++ b/server/webhook.go @@ -66,17 +66,11 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) { memoFind := &api.MemoFind{ CreatorId: &user.Id, } - showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden")) - if err != nil { - showHiddenMemo = false + rowStatus := c.QueryParam("rowStatus") + if rowStatus != "" { + memoFind.RowStatus = &rowStatus } - rowStatus := "NORMAL" - if showHiddenMemo { - rowStatus = "HIDDEN" - } - memoFind.RowStatus = &rowStatus - list, err := s.MemoService.FindMemoList(memoFind) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err) diff --git a/store/memo.go b/store/memo.go index ebf61501..6164914e 100644 --- a/store/memo.go +++ b/store/memo.go @@ -109,6 +109,9 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) { if v := patch.RowStatus; v != nil { set, args = append(set, "row_status = ?"), append(args, *v) } + if v := patch.CreatedTs; v != nil { + set, args = append(set, "created_ts = ?"), append(args, *v) + } args = append(args, patch.Id) diff --git a/web/src/helpers/api.ts b/web/src/helpers/api.ts index e75946d6..f9baf5cd 100644 --- a/web/src/helpers/api.ts +++ b/web/src/helpers/api.ts @@ -113,14 +113,14 @@ namespace api { export function getMyMemos() { return request({ method: "GET", - url: "/api/memo", + url: "/api/memo?rowStatus=NORMAL", }); } export function getMyDeletedMemos() { return request({ method: "GET", - url: "/api/memo?hidden=true", + url: "/api/memo?rowStatus=HIDDEN", }); }