common.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package admin
  2. import (
  3. "context"
  4. "time"
  5. "github.com/gofiber/fiber/v2"
  6. "github.com/golang-jwt/jwt/v4"
  7. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/models"
  8. )
  9. type (
  10. CacheService interface {
  11. Delete(key string)
  12. }
  13. TransactionManager interface {
  14. ReadCommitted(context.Context, func(ctx context.Context) error) error
  15. }
  16. ArticleRepository interface {
  17. GetAll(ctx context.Context) ([]models.Article, error)
  18. GetByURL(ctx context.Context, url string) (*models.Article, error)
  19. GetByID(ctx context.Context, id uint64) (*models.Article, error)
  20. Add(ctx context.Context, m models.Article) (uint64, error)
  21. Update(ctx context.Context, m models.Article) error
  22. Delete(ctx context.Context, id uint64) error
  23. }
  24. TagRepository interface {
  25. GetAll(ctx context.Context) ([]models.Tag, error)
  26. IsUsed(ctx context.Context, id uint64) (bool, error)
  27. GetByArticleID(ctx context.Context, id uint64) ([]models.Tag, error)
  28. GetByURL(ctx context.Context, tag string) (*models.Tag, error)
  29. GetByID(ctx context.Context, id uint64) (*models.Tag, error)
  30. Add(ctx context.Context, m models.Tag) error
  31. Update(ctx context.Context, m models.Tag) error
  32. Delete(ctx context.Context, id uint64) error
  33. }
  34. ArticleTagRepository interface {
  35. Add(ctx context.Context, id uint64, tagIDs []uint64) error
  36. Delete(ctx context.Context, id uint64, tagIDs []uint64) error
  37. DeleteByArticleID(ctx context.Context, id uint64) error
  38. }
  39. LanguageRepository interface {
  40. GetAll(ctx context.Context) ([]models.Language, error)
  41. }
  42. AuthService interface {
  43. GeneratePasswordHash(password string) (string, error)
  44. IsCorrectPassword(password string, hash string) bool
  45. GenerateToken(user models.User) (string, error)
  46. GetClaims(fctx *fiber.Ctx) jwt.MapClaims
  47. }
  48. ConfigService interface {
  49. JWTCookie() string
  50. JWTLifeTime() time.Duration
  51. }
  52. UserRepository interface {
  53. Get(ctx context.Context, username string) (*models.User, error)
  54. Add(ctx context.Context, username string, password string) (uint64, error)
  55. UpdatePassword(ctx context.Context, id uint64, newPassword string) error
  56. }
  57. )