store.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package repo
  2. import (
  3. "context"
  4. "gogs.io/gogs/internal/database"
  5. )
  6. // Store is the data layer carrier for context middleware. This interface is
  7. // meant to abstract away and limit the exposure of the underlying data layer to
  8. // the handler through a thin-wrapper.
  9. type Store interface {
  10. // GetAccessTokenBySHA1 returns the access token with given SHA1. It returns
  11. // database.ErrAccessTokenNotExist when not found.
  12. GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error)
  13. // TouchAccessTokenByID updates the updated time of the given access token to
  14. // the current time.
  15. TouchAccessTokenByID(ctx context.Context, id int64) error
  16. // GetRepositoryByName returns the repository with given owner and name. It
  17. // returns database.ErrRepoNotExist when not found.
  18. GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error)
  19. }
  20. type store struct{}
  21. // NewStore returns a new Store using the global database handle.
  22. func NewStore() Store {
  23. return &store{}
  24. }
  25. func (*store) GetAccessTokenBySHA1(ctx context.Context, sha1 string) (*database.AccessToken, error) {
  26. return database.Handle.AccessTokens().GetBySHA1(ctx, sha1)
  27. }
  28. func (*store) TouchAccessTokenByID(ctx context.Context, id int64) error {
  29. return database.Handle.AccessTokens().Touch(ctx, id)
  30. }
  31. func (*store) GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*database.Repository, error) {
  32. return database.Handle.Repositories().GetByName(ctx, ownerID, name)
  33. }