1
0

refactor: update backend database return type

This commit is contained in:
2026-07-16 20:51:18 +08:00
parent 14350f84c5
commit 20bf3a0c34
3 changed files with 148 additions and 160 deletions

View File

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