From 20bf3a0c3460bb4879ca7783c0d64c2cdd6170f1 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 16 Jul 2026 20:51:18 +0800 Subject: [PATCH] refactor: update backend database return type --- backend/database/database.go | 84 ++++++++-------- backend/database/mysql_database.go | 142 ++++++++++++++-------------- backend/database/sqlite_database.go | 82 ++++++++-------- 3 files changed, 148 insertions(+), 160 deletions(-) diff --git a/backend/database/database.go b/backend/database/database.go index a590bae..68bf336 100644 --- a/backend/database/database.go +++ b/backend/database/database.go @@ -7,16 +7,6 @@ import ( "github.com/yyc12345/coconut-leaf/backend/config" ) -// ResponseBody is the envelope returned by every Database operation, mirroring -// the legacy database.ResponseBody. Data is any so each method can return its -// own shape (scalar, []string, []any row, [][]any rows, ...). JSON tags keep the -// legacy lowercase keys (success/error/data) used by ConstructResponseBody. -type ResponseBody struct { - Success bool `json:"success"` - Error string `json:"error"` - Data any `json:"data"` -} - // CalendarUpdateOptions carries the optional fields of CalendarUpdate. A nil // pointer means "not provided", mirroring the legacy **optArgs semantics: a // field is applied only when its pointer is non-nil. @@ -47,50 +37,50 @@ type Deps struct { // Database describes every database operation the Gin server may use. It is the // Go equivalent of the legacy CalendarDatabase public surface: each method takes -// a context.Context for cancellation and returns a ResponseBody whose -// Success/Error fields encode failure (mirroring the legacy decorator behavior). +// a context.Context for cancellation and returns (any, error). The server layer +// is responsible for wrapping the result into an HTTP response body. type Database interface { Init(username, password string) error Close() error - CommonSalt(ctx context.Context, username string) ResponseBody - CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody - CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody - CommonLogout(ctx context.Context, token string) ResponseBody - CommonTokenValid(ctx context.Context, token string) ResponseBody + CommonSalt(ctx context.Context, username string) (any, error) + CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) + CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) + CommonLogout(ctx context.Context, token string) (any, error) + CommonTokenValid(ctx context.Context, token string) (any, error) - CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody - CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody - CalendarGetDetail(ctx context.Context, token, uuid string) ResponseBody - CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) ResponseBody - CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) ResponseBody - CalendarDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody + CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) + CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) + CalendarGetDetail(ctx context.Context, token, uuid string) (any, error) + CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) (any, error) + CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) (any, error) + CalendarDelete(ctx context.Context, token, uuid, lastChange string) (any, error) - CollectionGetFullOwn(ctx context.Context, token string) ResponseBody - CollectionGetListOwn(ctx context.Context, token string) ResponseBody - CollectionGetDetailOwn(ctx context.Context, token, uuid string) ResponseBody - CollectionAddOwn(ctx context.Context, token, name string) ResponseBody - CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) ResponseBody - CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) ResponseBody - CollectionGetSharing(ctx context.Context, token, uuid string) ResponseBody - CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody - CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody - CollectionGetShared(ctx context.Context, token string) ResponseBody + CollectionGetFullOwn(ctx context.Context, token string) (any, error) + CollectionGetListOwn(ctx context.Context, token string) (any, error) + CollectionGetDetailOwn(ctx context.Context, token, uuid string) (any, error) + CollectionAddOwn(ctx context.Context, token, name string) (any, error) + CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) (any, error) + CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) (any, error) + CollectionGetSharing(ctx context.Context, token, uuid string) (any, error) + CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) + CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) + CollectionGetShared(ctx context.Context, token string) (any, error) - TodoGetFull(ctx context.Context, token string) ResponseBody - TodoGetList(ctx context.Context, token string) ResponseBody - TodoGetDetail(ctx context.Context, token, uuid string) ResponseBody - TodoAdd(ctx context.Context, token string) ResponseBody - TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) ResponseBody - TodoDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody + TodoGetFull(ctx context.Context, token string) (any, error) + TodoGetList(ctx context.Context, token string) (any, error) + TodoGetDetail(ctx context.Context, token, uuid string) (any, error) + TodoAdd(ctx context.Context, token string) (any, error) + TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) (any, error) + TodoDelete(ctx context.Context, token, uuid, lastChange string) (any, error) - AdminGet(ctx context.Context, token string) ResponseBody - AdminAdd(ctx context.Context, token, username string) ResponseBody - AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) ResponseBody - AdminDelete(ctx context.Context, token, username string) ResponseBody + AdminGet(ctx context.Context, token string) (any, error) + AdminAdd(ctx context.Context, token, username string) (any, error) + AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) (any, error) + AdminDelete(ctx context.Context, token, username string) (any, error) - ProfileIsAdmin(ctx context.Context, token string) ResponseBody - ProfileChangePassword(ctx context.Context, token, password string) ResponseBody - ProfileGetToken(ctx context.Context, token string) ResponseBody - ProfileDeleteToken(ctx context.Context, token, deleteToken string) ResponseBody + ProfileIsAdmin(ctx context.Context, token string) (any, error) + ProfileChangePassword(ctx context.Context, token, password string) (any, error) + ProfileGetToken(ctx context.Context, token string) (any, error) + ProfileDeleteToken(ctx context.Context, token, deleteToken string) (any, error) } diff --git a/backend/database/mysql_database.go b/backend/database/mysql_database.go index 4a75dd0..f30cb41 100644 --- a/backend/database/mysql_database.go +++ b/backend/database/mysql_database.go @@ -7,8 +7,6 @@ import ( var errNotImplemented = errors.New("mysql database: not implemented") -var notImplResp = ResponseBody{Success: false, Error: errNotImplemented.Error()} - // stubDatabase provides a not-implemented default for every Database method. // MysqlDatabase embeds it so the interface is satisfied without hand-writing // each method; individual methods can be overridden on MysqlDatabase later. @@ -17,115 +15,115 @@ type stubDatabase struct{} func (stubDatabase) Init(username, password string) error { return errNotImplemented } func (stubDatabase) Close() error { return errNotImplemented } -func (stubDatabase) CommonSalt(ctx context.Context, username string) ResponseBody { - return notImplResp +func (stubDatabase) CommonSalt(ctx context.Context, username string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody { - return notImplResp +func (stubDatabase) CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody { - return notImplResp +func (stubDatabase) CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CommonLogout(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) CommonLogout(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CommonTokenValid(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) CommonTokenValid(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody { - return notImplResp +func (stubDatabase) CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody { - return notImplResp +func (stubDatabase) CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarGetDetail(ctx context.Context, token, uuid string) ResponseBody { - return notImplResp +func (stubDatabase) CalendarGetDetail(ctx context.Context, token, uuid string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) ResponseBody { - return notImplResp +func (stubDatabase) CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) ResponseBody { - return notImplResp +func (stubDatabase) CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CalendarDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) CalendarDelete(ctx context.Context, token, uuid, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionGetFullOwn(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionGetFullOwn(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionGetListOwn(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionGetListOwn(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionGetDetailOwn(ctx context.Context, token, uuid string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionGetDetailOwn(ctx context.Context, token, uuid string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionAddOwn(ctx context.Context, token, name string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionAddOwn(ctx context.Context, token, name string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionGetSharing(ctx context.Context, token, uuid string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionGetSharing(ctx context.Context, token, uuid string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) CollectionGetShared(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) CollectionGetShared(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoGetFull(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) TodoGetFull(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoGetList(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) TodoGetList(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoGetDetail(ctx context.Context, token, uuid string) ResponseBody { - return notImplResp +func (stubDatabase) TodoGetDetail(ctx context.Context, token, uuid string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoAdd(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) TodoAdd(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) TodoDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody { - return notImplResp +func (stubDatabase) TodoDelete(ctx context.Context, token, uuid, lastChange string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) AdminGet(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) AdminGet(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) AdminAdd(ctx context.Context, token, username string) ResponseBody { - return notImplResp +func (stubDatabase) AdminAdd(ctx context.Context, token, username string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) ResponseBody { - return notImplResp +func (stubDatabase) AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) AdminDelete(ctx context.Context, token, username string) ResponseBody { - return notImplResp +func (stubDatabase) AdminDelete(ctx context.Context, token, username string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) ProfileIsAdmin(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) ProfileIsAdmin(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) ProfileChangePassword(ctx context.Context, token, password string) ResponseBody { - return notImplResp +func (stubDatabase) ProfileChangePassword(ctx context.Context, token, password string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) ProfileGetToken(ctx context.Context, token string) ResponseBody { - return notImplResp +func (stubDatabase) ProfileGetToken(ctx context.Context, token string) (any, error) { + return nil, errNotImplemented } -func (stubDatabase) ProfileDeleteToken(ctx context.Context, token, deleteToken string) ResponseBody { - return notImplResp +func (stubDatabase) ProfileDeleteToken(ctx context.Context, token, deleteToken string) (any, error) { + return nil, errNotImplemented } // MysqlDatabase implements Database as a fully not-implemented stub by diff --git a/backend/database/sqlite_database.go b/backend/database/sqlite_database.go index 3e9b4ef..78b7c4d 100644 --- a/backend/database/sqlite_database.go +++ b/backend/database/sqlite_database.go @@ -150,7 +150,7 @@ func (d *Sqlite3Database) Close() error { // tokens (logging when it does), run the work, commit on success / rollback on // error. DB errors are logged only in debug mode, matching the legacy // `if cfg.others.debug: LOGGER.exception(e)` behavior. -func (d *Sqlite3Database) safeOp(ctx context.Context, fn dbOp) ResponseBody { +func (d *Sqlite3Database) safeOp(ctx context.Context, fn dbOp) (any, error) { d.mu.Lock() defer d.mu.Unlock() @@ -162,7 +162,7 @@ func (d *Sqlite3Database) safeOp(ctx context.Context, fn dbOp) ResponseBody { if debug { logger.Error("failed to begin transaction", "error", err) } - return ResponseBody{Success: false, Error: err.Error()} + return nil, err } if now := utils.GetCurrentTimestamp(); now-d.latestClean > d.deps.Cfg.Others.AutoTokenCleanDuration { @@ -173,7 +173,7 @@ func (d *Sqlite3Database) safeOp(ctx context.Context, fn dbOp) ResponseBody { if debug { logger.Error("failed to clean outdated tokens", "error", err) } - return ResponseBody{Success: false, Error: err.Error()} + return nil, err } } @@ -183,15 +183,15 @@ func (d *Sqlite3Database) safeOp(ctx context.Context, fn dbOp) ResponseBody { if debug { logger.Error("database operation failed", "error", err) } - return ResponseBody{Success: false, Error: err.Error()} + return nil, err } if err := tx.Commit(); err != nil { if debug { logger.Error("failed to commit transaction", "error", err) } - return ResponseBody{Success: false, Error: err.Error()} + return nil, err } - return ResponseBody{Success: true, Data: data} + return data, nil } // region: Token-related Internal Operations @@ -246,7 +246,7 @@ func tokenOperIsAdmin(ctx context.Context, tx *sql.Tx, username string) (bool, e // region: Common Namespace -func (d *Sqlite3Database) CommonSalt(ctx context.Context, username string) ResponseBody { +func (d *Sqlite3Database) CommonSalt(ctx context.Context, username string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { salt := utils.GenerateSalt() if _, err := tx.ExecContext(ctx, "UPDATE user SET [salt] = ? WHERE [name] = ?;", salt, username); err != nil { @@ -256,7 +256,7 @@ func (d *Sqlite3Database) CommonSalt(ctx context.Context, username string) Respo }) } -func (d *Sqlite3Database) CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody { +func (d *Sqlite3Database) CommonLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { var gottenPassword string var gottenSalt int64 @@ -278,7 +278,7 @@ func (d *Sqlite3Database) CommonLogin(ctx context.Context, username, password, c }) } -func (d *Sqlite3Database) CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) ResponseBody { +func (d *Sqlite3Database) CommonWebLogin(ctx context.Context, username, password, clientUa, clientIp string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { logger := d.deps.Logger logger.Debug("WebLogin username", "username", username) @@ -298,7 +298,7 @@ func (d *Sqlite3Database) CommonWebLogin(ctx context.Context, username, password }) } -func (d *Sqlite3Database) CommonLogout(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) CommonLogout(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -310,7 +310,7 @@ func (d *Sqlite3Database) CommonLogout(ctx context.Context, token string) Respon }) } -func (d *Sqlite3Database) CommonTokenValid(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) CommonTokenValid(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -323,7 +323,7 @@ func (d *Sqlite3Database) CommonTokenValid(ctx context.Context, token string) Re // region: Calendar Namespace -func (d *Sqlite3Database) CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody { +func (d *Sqlite3Database) CalendarGetFull(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -353,7 +353,7 @@ func (d *Sqlite3Database) CalendarGetFull(ctx context.Context, token string, sta }) } -func (d *Sqlite3Database) CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) ResponseBody { +func (d *Sqlite3Database) CalendarGetList(ctx context.Context, token string, startDateTime, endDateTime int64) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -382,7 +382,7 @@ func (d *Sqlite3Database) CalendarGetList(ctx context.Context, token string, sta }) } -func (d *Sqlite3Database) CalendarGetDetail(ctx context.Context, token, uuid string) ResponseBody { +func (d *Sqlite3Database) CalendarGetDetail(ctx context.Context, token, uuid string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -401,7 +401,7 @@ func (d *Sqlite3Database) CalendarGetDetail(ctx context.Context, token, uuid str }) } -func (d *Sqlite3Database) CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) ResponseBody { +func (d *Sqlite3Database) CalendarUpdate(ctx context.Context, token, uuid, lastChange string, opts CalendarUpdateOptions) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -489,7 +489,7 @@ func (d *Sqlite3Database) CalendarUpdate(ctx context.Context, token, uuid, lastC }) } -func (d *Sqlite3Database) CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) ResponseBody { +func (d *Sqlite3Database) CalendarAdd(ctx context.Context, token, belongTo, title, description string, eventDateTimeStart, eventDateTimeEnd int64, loopRules string, timezoneOffset int64) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -511,7 +511,7 @@ func (d *Sqlite3Database) CalendarAdd(ctx context.Context, token, belongTo, titl }) } -func (d *Sqlite3Database) CalendarDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody { +func (d *Sqlite3Database) CalendarDelete(ctx context.Context, token, uuid, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -535,7 +535,7 @@ func (d *Sqlite3Database) CalendarDelete(ctx context.Context, token, uuid, lastC // region: Collection Namespace -func (d *Sqlite3Database) CollectionGetFullOwn(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) CollectionGetFullOwn(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -561,7 +561,7 @@ func (d *Sqlite3Database) CollectionGetFullOwn(ctx context.Context, token string }) } -func (d *Sqlite3Database) CollectionGetListOwn(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) CollectionGetListOwn(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -587,7 +587,7 @@ func (d *Sqlite3Database) CollectionGetListOwn(ctx context.Context, token string }) } -func (d *Sqlite3Database) CollectionGetDetailOwn(ctx context.Context, token, uuid string) ResponseBody { +func (d *Sqlite3Database) CollectionGetDetailOwn(ctx context.Context, token, uuid string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -605,7 +605,7 @@ func (d *Sqlite3Database) CollectionGetDetailOwn(ctx context.Context, token, uui }) } -func (d *Sqlite3Database) CollectionAddOwn(ctx context.Context, token, name string) ResponseBody { +func (d *Sqlite3Database) CollectionAddOwn(ctx context.Context, token, name string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -620,7 +620,7 @@ func (d *Sqlite3Database) CollectionAddOwn(ctx context.Context, token, name stri }) } -func (d *Sqlite3Database) CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) ResponseBody { +func (d *Sqlite3Database) CollectionUpdateOwn(ctx context.Context, token, uuid, name, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -641,7 +641,7 @@ func (d *Sqlite3Database) CollectionUpdateOwn(ctx context.Context, token, uuid, }) } -func (d *Sqlite3Database) CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) ResponseBody { +func (d *Sqlite3Database) CollectionDeleteOwn(ctx context.Context, token, uuid, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -661,7 +661,7 @@ func (d *Sqlite3Database) CollectionDeleteOwn(ctx context.Context, token, uuid, }) } -func (d *Sqlite3Database) CollectionGetSharing(ctx context.Context, token, uuid string) ResponseBody { +func (d *Sqlite3Database) CollectionGetSharing(ctx context.Context, token, uuid string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -686,7 +686,7 @@ func (d *Sqlite3Database) CollectionGetSharing(ctx context.Context, token, uuid }) } -func (d *Sqlite3Database) CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody { +func (d *Sqlite3Database) CollectionDeleteSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -720,7 +720,7 @@ func (d *Sqlite3Database) CollectionDeleteSharing(ctx context.Context, token, uu }) } -func (d *Sqlite3Database) CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) ResponseBody { +func (d *Sqlite3Database) CollectionAddSharing(ctx context.Context, token, uuid, target, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { if err := tokenOperCheckValid(ctx, tx, token); err != nil { return nil, err @@ -751,7 +751,7 @@ func (d *Sqlite3Database) CollectionAddSharing(ctx context.Context, token, uuid, }) } -func (d *Sqlite3Database) CollectionGetShared(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) CollectionGetShared(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -784,7 +784,7 @@ func (d *Sqlite3Database) CollectionGetShared(ctx context.Context, token string) // region: Todo Namespace -func (d *Sqlite3Database) TodoGetFull(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) TodoGetFull(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -810,7 +810,7 @@ func (d *Sqlite3Database) TodoGetFull(ctx context.Context, token string) Respons }) } -func (d *Sqlite3Database) TodoGetList(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) TodoGetList(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -836,7 +836,7 @@ func (d *Sqlite3Database) TodoGetList(ctx context.Context, token string) Respons }) } -func (d *Sqlite3Database) TodoGetDetail(ctx context.Context, token, uuid string) ResponseBody { +func (d *Sqlite3Database) TodoGetDetail(ctx context.Context, token, uuid string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -854,7 +854,7 @@ func (d *Sqlite3Database) TodoGetDetail(ctx context.Context, token, uuid string) }) } -func (d *Sqlite3Database) TodoAdd(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) TodoAdd(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -870,7 +870,7 @@ func (d *Sqlite3Database) TodoAdd(ctx context.Context, token string) ResponseBod }) } -func (d *Sqlite3Database) TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) ResponseBody { +func (d *Sqlite3Database) TodoUpdate(ctx context.Context, token, uuid, data, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { // check valid token if err := tokenOperCheckValid(ctx, tx, token); err != nil { @@ -894,7 +894,7 @@ func (d *Sqlite3Database) TodoUpdate(ctx context.Context, token, uuid, data, las }) } -func (d *Sqlite3Database) TodoDelete(ctx context.Context, token, uuid, lastChange string) ResponseBody { +func (d *Sqlite3Database) TodoDelete(ctx context.Context, token, uuid, lastChange string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { // check valid token if err := tokenOperCheckValid(ctx, tx, token); err != nil { @@ -921,7 +921,7 @@ func (d *Sqlite3Database) TodoDelete(ctx context.Context, token, uuid, lastChang // region: Admin Namespace -func (d *Sqlite3Database) AdminGet(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) AdminGet(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -955,7 +955,7 @@ func (d *Sqlite3Database) AdminGet(ctx context.Context, token string) ResponseBo }) } -func (d *Sqlite3Database) AdminAdd(ctx context.Context, token, username string) ResponseBody { +func (d *Sqlite3Database) AdminAdd(ctx context.Context, token, username string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { caller, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -976,7 +976,7 @@ func (d *Sqlite3Database) AdminAdd(ctx context.Context, token, username string) }) } -func (d *Sqlite3Database) AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) ResponseBody { +func (d *Sqlite3Database) AdminUpdate(ctx context.Context, token, username string, opts AdminUpdateOptions) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { caller, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -1030,7 +1030,7 @@ func (d *Sqlite3Database) AdminUpdate(ctx context.Context, token, username strin }) } -func (d *Sqlite3Database) AdminDelete(ctx context.Context, token, username string) ResponseBody { +func (d *Sqlite3Database) AdminDelete(ctx context.Context, token, username string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { caller, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -1062,7 +1062,7 @@ func (d *Sqlite3Database) AdminDelete(ctx context.Context, token, username strin // region: Profile Namespace -func (d *Sqlite3Database) ProfileIsAdmin(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) ProfileIsAdmin(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -1072,7 +1072,7 @@ func (d *Sqlite3Database) ProfileIsAdmin(ctx context.Context, token string) Resp }) } -func (d *Sqlite3Database) ProfileChangePassword(ctx context.Context, token, password string) ResponseBody { +func (d *Sqlite3Database) ProfileChangePassword(ctx context.Context, token, password string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -1085,7 +1085,7 @@ func (d *Sqlite3Database) ProfileChangePassword(ctx context.Context, token, pass }) } -func (d *Sqlite3Database) ProfileGetToken(ctx context.Context, token string) ResponseBody { +func (d *Sqlite3Database) ProfileGetToken(ctx context.Context, token string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil { @@ -1112,7 +1112,7 @@ func (d *Sqlite3Database) ProfileGetToken(ctx context.Context, token string) Res }) } -func (d *Sqlite3Database) ProfileDeleteToken(ctx context.Context, token, deleteToken string) ResponseBody { +func (d *Sqlite3Database) ProfileDeleteToken(ctx context.Context, token, deleteToken string) (any, error) { return d.safeOp(ctx, func(ctx context.Context, tx *sql.Tx) (any, error) { username, err := tokenOperGetUsername(ctx, tx, token) if err != nil {