repository.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package interfaces
  2. import (
  3. "context"
  4. "database/sql"
  5. "mime/multipart"
  6. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  7. "github.com/gofiber/fiber/v2"
  8. )
  9. type ThingRepository interface {
  10. Get(ctx context.Context, thingID int) (*models.Thing, error)
  11. Search(ctx context.Context, search string) ([]models.Thing, error)
  12. GetByPlaceID(ctx context.Context, placeID int) ([]models.Thing, error)
  13. GetAllByPlaceID(ctx context.Context, placeID int) ([]models.Thing, error)
  14. Add(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) (int, error)
  15. Update(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) error
  16. Delete(ctx context.Context, thingID int, tx *sql.Tx) error
  17. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  18. CommitTx(tx *sql.Tx) error
  19. }
  20. type PlaceRepository interface {
  21. GetAll(ctx context.Context) ([]models.Place, error)
  22. Get(ctx context.Context, placeID int) (*models.Place, error)
  23. GetNestedPlaces(ctx context.Context, placeID int) ([]models.Place, error)
  24. Add(ctx context.Context, req models.AddPlaceRequest, tx *sql.Tx) (int, error)
  25. Update(ctx context.Context, req models.UpdatePlaceRequest, tx *sql.Tx) error
  26. Delete(ctx context.Context, placeID int, tx *sql.Tx) error
  27. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  28. CommitTx(tx *sql.Tx) error
  29. }
  30. type PlaceThingRepository interface {
  31. GetByThingID(ctx context.Context, thingID int) (*models.PlaceThing, error)
  32. Add(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) error
  33. UpdatePlace(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) error
  34. DeleteThing(ctx context.Context, thingID int, tx *sql.Tx) error
  35. }
  36. type PlaceImageRepository interface {
  37. Add(ctx context.Context, req models.AddPlaceImageRequest, tx *sql.Tx) error
  38. Get(ctx context.Context, imageID int) (*models.Image, error)
  39. GetByPlaceID(ctx context.Context, placeID int) ([]models.Image, error)
  40. Delete(ctx context.Context, imageID int, tx *sql.Tx) error
  41. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  42. CommitTx(tx *sql.Tx) error
  43. }
  44. type ThingImageRepository interface {
  45. Add(ctx context.Context, req models.AddThingImageRequest, tx *sql.Tx) error
  46. Get(ctx context.Context, imageID int) (*models.Image, error)
  47. GetByThingID(ctx context.Context, thingID int) ([]models.Image, error)
  48. GetByPlaceID(ctx context.Context, placeID int) ([]models.Image, error)
  49. Delete(ctx context.Context, imageID int, tx *sql.Tx) error
  50. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  51. CommitTx(tx *sql.Tx) error
  52. }
  53. type UserRepository interface {
  54. Get(ctx context.Context, username string) (*models.User, error)
  55. Add(ctx context.Context, username string, password string) (int, error)
  56. Update(ctx context.Context, req models.UpdateUserRequest) error
  57. }
  58. type TagRepository interface {
  59. GetAll(ctx context.Context) ([]models.Tag, error)
  60. Get(ctx context.Context, tagID int) (*models.Tag, error)
  61. GetByThingID(ctx context.Context, thingID int) ([]models.Tag, error)
  62. Add(ctx context.Context, req models.AddTagRequest, tx *sql.Tx) (int, error)
  63. Update(ctx context.Context, req models.UpdateTagRequest, tx *sql.Tx) error
  64. Delete(ctx context.Context, tagID int, tx *sql.Tx) error
  65. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  66. CommitTx(tx *sql.Tx) error
  67. }
  68. type ThingTagRepository interface {
  69. GetByPlaceID(ctx context.Context, placeID int) ([]models.ThingTag, error)
  70. Add(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) error
  71. Delete(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) error
  72. DeleteByTagID(ctx context.Context, tagID int, tx *sql.Tx) error
  73. DeleteByThingID(ctx context.Context, thingID int, tx *sql.Tx) error
  74. BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
  75. CommitTx(tx *sql.Tx) error
  76. }
  77. type ThingNotificationRepository interface {
  78. Add(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) error
  79. Update(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) error
  80. Delete(ctx context.Context, thingID int, tx *sql.Tx) error
  81. Get(ctx context.Context, thingID int) (*models.ThingNotification, error)
  82. GetExpired(ctx context.Context) ([]models.ExtThingNotification, error)
  83. }
  84. type FileRepository interface {
  85. Save(fctx *fiber.Ctx, header *multipart.FileHeader, path string) error
  86. Delete(path string) error
  87. }