12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package repo
- import (
- "context"
- "gogs.io/gogs/internal/database"
- )
- // Store is the data layer carrier for context middleware. This interface is
- // meant to abstract away and limit the exposure of the underlying data layer to
- // the handler through a thin-wrapper.
- type Store interface {
- // GetAccessTokenBySHA1 returns the access token with given SHA1. It returns
- // database.ErrAccessTokenNotExist when not found.
- GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error)
- // TouchAccessTokenByID updates the updated time of the given access token to
- // the current time.
- TouchAccessTokenByID(ctx context.Context, id int64) error
- // GetRepositoryByName returns the repository with given owner and name. It
- // returns database.ErrRepoNotExist when not found.
- GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error)
- // IsTwoFactorEnabled returns true if the user has enabled 2FA.
- IsTwoFactorEnabled(ctx context.Context, userID int64) bool
- }
- type store struct{}
- // NewStore returns a new Store using the global database handle.
- func NewStore() Store {
- return &store{}
- }
- func (*store) GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error) {
- return database.Handle.AccessTokens().GetBySHA1(ctx, sha1)
- }
- func (*store) TouchAccessTokenByID(ctx context.Context, id int64) error {
- return database.Handle.AccessTokens().Touch(ctx, id)
- }
- func (*store) GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error) {
- return database.Handle.Repositories().GetByName(ctx, ownerID, name)
- }
- func (*store) IsTwoFactorEnabled(ctx context.Context, userID int64) bool {
- return database.Handle.TwoFactors().IsEnabled(ctx, userID)
- }
|