Dmitriy Gnatenko 3 місяців тому
батько
коміт
2a1d7989ac
100 змінених файлів з 4017 додано та 6548 видалено
  1. 5 2
      Makefile
  2. BIN
      build/app/app
  3. 1 1
      cmd/app/main.go
  4. 20 182
      go.mod
  5. 16 0
      init/systemd/homethings.service
  6. 5 2
      internal/api/v1/auth/check_auth.go
  7. 7 6
      internal/api/v1/auth/check_auth_test.go
  8. 6 0
      internal/api/v1/auth/login.go
  9. 6 8
      internal/api/v1/auth/login_test.go
  10. 43 43
      internal/api/v1/auth/mocks/auth_service_minimock.go
  11. 1 1
      internal/api/v1/auth/mocks/user_repository_minimock.go
  12. 0 8
      internal/api/v1/common.go
  13. 44 48
      internal/api/v1/image/add_image.go
  14. 51 133
      internal/api/v1/image/add_image_test.go
  15. 22 13
      internal/api/v1/image/delete_place_image.go
  16. 46 34
      internal/api/v1/image/delete_place_image_test.go
  17. 22 13
      internal/api/v1/image/delete_thing_image.go
  18. 45 33
      internal/api/v1/image/delete_thing_image_test.go
  19. 9 5
      internal/api/v1/image/get_place_images.go
  20. 18 17
      internal/api/v1/image/get_place_images_test.go
  21. 8 5
      internal/api/v1/image/get_thing_images.go
  22. 14 13
      internal/api/v1/image/get_thing_images_test.go
  23. 1 1
      internal/api/v1/image/mocks/file_repository_minimock.go
  24. 42 730
      internal/api/v1/image/mocks/place_image_repository_minimock.go
  25. 42 730
      internal/api/v1/image/mocks/thing_image_repository_minimock.go
  26. 393 0
      internal/api/v1/image/mocks/transaction_manager_minimock.go
  27. 14 8
      internal/api/v1/notification/add_thing_notification.go
  28. 12 15
      internal/api/v1/notification/add_thing_notification_test.go
  29. 8 2
      internal/api/v1/notification/delete_thing_notification.go
  30. 13 15
      internal/api/v1/notification/delete_thing_notification_test.go
  31. 6 3
      internal/api/v1/notification/get_expired_thing_notifications.go
  32. 9 8
      internal/api/v1/notification/get_expired_thing_notifications_test.go
  33. 8 3
      internal/api/v1/notification/get_thing_notification.go
  34. 12 11
      internal/api/v1/notification/get_thing_notification_test.go
  35. 75 160
      internal/api/v1/notification/mocks/thing_notification_repository_minimock.go
  36. 16 5
      internal/api/v1/notification/update_thing_notification.go
  37. 19 21
      internal/api/v1/notification/update_thing_notification_test.go
  38. 27 21
      internal/api/v1/place/add_place.go
  39. 15 17
      internal/api/v1/place/add_place_test.go
  40. 71 64
      internal/api/v1/place/delete_place.go
  41. 248 254
      internal/api/v1/place/delete_place_test.go
  42. 8 3
      internal/api/v1/place/get_place.go
  43. 7 3
      internal/api/v1/place/get_place_nested.go
  44. 11 10
      internal/api/v1/place/get_place_nested_test.go
  45. 21 21
      internal/api/v1/place/get_place_test.go
  46. 6 3
      internal/api/v1/place/get_place_tree.go
  47. 10 9
      internal/api/v1/place/get_place_tree_test.go
  48. 6 3
      internal/api/v1/place/get_places.go
  49. 10 9
      internal/api/v1/place/get_places_test.go
  50. 1 1
      internal/api/v1/place/mocks/file_repository_minimock.go
  51. 47 76
      internal/api/v1/place/mocks/place_image_repository_minimock.go
  52. 43 727
      internal/api/v1/place/mocks/place_repository_minimock.go
  53. 24 53
      internal/api/v1/place/mocks/place_thing_repository_minimock.go
  54. 47 76
      internal/api/v1/place/mocks/thing_image_repository_minimock.go
  55. 24 53
      internal/api/v1/place/mocks/thing_notification_repository_minimock.go
  56. 47 76
      internal/api/v1/place/mocks/thing_repository_minimock.go
  57. 24 53
      internal/api/v1/place/mocks/thing_tag_repository_minimock.go
  58. 393 0
      internal/api/v1/place/mocks/transaction_manager_minimock.go
  59. 11 4
      internal/api/v1/place/update_place.go
  60. 18 20
      internal/api/v1/place/update_place_test.go
  61. 22 16
      internal/api/v1/tag/add_tag.go
  62. 11 14
      internal/api/v1/tag/add_tag_test.go
  63. 18 6
      internal/api/v1/tag/add_thing_tag.go
  64. 23 24
      internal/api/v1/tag/add_thing_tag_test.go
  65. 20 13
      internal/api/v1/tag/delete_tag.go
  66. 48 75
      internal/api/v1/tag/delete_tag_test.go
  67. 14 3
      internal/api/v1/tag/delete_thing_tag.go
  68. 23 24
      internal/api/v1/tag/delete_thing_tag_test.go
  69. 8 3
      internal/api/v1/tag/get_tag.go
  70. 12 11
      internal/api/v1/tag/get_tag_test.go
  71. 6 3
      internal/api/v1/tag/get_tags.go
  72. 9 8
      internal/api/v1/tag/get_tags_test.go
  73. 8 3
      internal/api/v1/tag/get_thing_tags.go
  74. 13 12
      internal/api/v1/tag/get_thing_tags_test.go
  75. 43 727
      internal/api/v1/tag/mocks/tag_repository_minimock.go
  76. 24 24
      internal/api/v1/tag/mocks/thing_repository_minimock.go
  77. 52 137
      internal/api/v1/tag/mocks/thing_tag_repository_minimock.go
  78. 393 0
      internal/api/v1/tag/mocks/transaction_manager_minimock.go
  79. 11 4
      internal/api/v1/tag/update_tag.go
  80. 15 18
      internal/api/v1/tag/update_tag_test.go
  81. 44 35
      internal/api/v1/thing/add_thing.go
  82. 53 71
      internal/api/v1/thing/add_thing_test.go
  83. 43 36
      internal/api/v1/thing/delete_thing.go
  84. 106 166
      internal/api/v1/thing/delete_thing_test.go
  85. 9 4
      internal/api/v1/thing/get_place_things.go
  86. 19 18
      internal/api/v1/thing/get_place_things_test.go
  87. 8 3
      internal/api/v1/thing/get_thing.go
  88. 13 12
      internal/api/v1/thing/get_thing_test.go
  89. 1 1
      internal/api/v1/thing/mocks/file_repository_minimock.go
  90. 75 160
      internal/api/v1/thing/mocks/place_thing_repository_minimock.go
  91. 47 76
      internal/api/v1/thing/mocks/thing_image_repository_minimock.go
  92. 24 53
      internal/api/v1/thing/mocks/thing_notification_repository_minimock.go
  93. 45 729
      internal/api/v1/thing/mocks/thing_repository_minimock.go
  94. 47 76
      internal/api/v1/thing/mocks/thing_tag_repository_minimock.go
  95. 393 0
      internal/api/v1/thing/mocks/transaction_manager_minimock.go
  96. 4 2
      internal/api/v1/thing/search_thing.go
  97. 11 10
      internal/api/v1/thing/search_thing_test.go
  98. 36 28
      internal/api/v1/thing/update_thing.go
  99. 82 107
      internal/api/v1/thing/update_thing_test.go
  100. 6 1
      internal/api/v1/user/add_user.go

+ 5 - 2
Makefile

@@ -27,8 +27,11 @@ test:
 	go test ./...
 
 test-cover:
-	go test ./... -coverprofile=./coverage.out
-	go tool cover -html=./coverage.out
+	go clean -testcache
+	go test ./... -coverprofile=coverage.tmp.out -covermode count -coverpkg=git.dmitriygnatenko.ru/dima/homethings/internal/api/...
+	grep -v 'mocks\|config' coverage.tmp.out  > coverage.out
+	rm coverage.tmp.out
+	go tool cover -html=coverage.out;
 
 lint:
 	golangci-lint run --timeout=3m


+ 1 - 1
cmd/app/main.go

@@ -26,7 +26,7 @@ func main() {
 		log.Fatal(err)
 	}
 
-	if err = fiberApp.Listen(":" + serviceProvider.EnvService().AppPort()); err != nil {
+	if err = fiberApp.Listen(":" + serviceProvider.ConfigService().AppPort()); err != nil {
 		log.Fatal(err)
 	}
 }

+ 20 - 182
go.mod

@@ -3,238 +3,76 @@ module git.dmitriygnatenko.ru/dima/homethings
 go 1.22.2
 
 require (
+	git.dmitriygnatenko.ru/dima/go-common v1.6.2
 	github.com/Masterminds/squirrel v1.5.3
-	github.com/brianvoe/gofakeit/v6 v6.19.0
+	github.com/brianvoe/gofakeit/v6 v6.28.0
 	github.com/disintegration/imaging v1.6.2
-	github.com/go-playground/validator/v10 v10.11.1
-	github.com/gofiber/fiber/v2 v2.42.0
+	github.com/go-playground/validator/v10 v10.22.0
+	github.com/gofiber/fiber/v2 v2.52.5
 	github.com/gofiber/jwt/v3 v3.3.6
-	github.com/gofiber/swagger v0.1.7
+	github.com/gofiber/swagger v1.1.0
 	github.com/gojuno/minimock/v3 v3.3.13
 	github.com/golang-jwt/jwt/v4 v4.4.3
 	github.com/lib/pq v1.10.9
 	github.com/spf13/viper v1.19.0
 	github.com/stretchr/testify v1.9.0
 	github.com/swaggo/swag v1.16.3
-	golang.org/x/crypto v0.25.0
+	golang.org/x/crypto v0.26.0
 )
 
 require (
-	4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
-	4d63.com/gochecknoglobals v0.2.1 // indirect
-	github.com/4meepo/tagalign v1.3.4 // indirect
-	github.com/Abirdcfly/dupword v0.0.14 // indirect
-	github.com/Antonboom/errname v0.1.13 // indirect
-	github.com/Antonboom/nilnil v0.1.9 // indirect
-	github.com/Antonboom/testifylint v1.4.3 // indirect
-	github.com/BurntSushi/toml v1.4.0 // indirect
-	github.com/Crocmagnon/fatcontext v0.4.0 // indirect
-	github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
-	github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 // indirect
 	github.com/KyleBanks/depth v1.2.1 // indirect
-	github.com/Masterminds/semver/v3 v3.2.1 // indirect
-	github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect
-	github.com/alecthomas/go-check-sumtype v0.1.4 // indirect
-	github.com/alexkohler/nakedret/v2 v2.0.4 // indirect
-	github.com/alexkohler/prealloc v1.0.0 // indirect
-	github.com/alingse/asasalint v0.0.11 // indirect
-	github.com/andybalholm/brotli v1.0.4 // indirect
-	github.com/ashanbrown/forbidigo v1.6.0 // indirect
-	github.com/ashanbrown/makezero v1.1.1 // indirect
-	github.com/beorn7/perks v1.0.1 // indirect
-	github.com/bkielbasa/cyclop v1.2.1 // indirect
-	github.com/blizzy78/varnamelen v0.8.0 // indirect
-	github.com/bombsimon/wsl/v4 v4.4.1 // indirect
-	github.com/breml/bidichk v0.2.7 // indirect
-	github.com/breml/errchkjson v0.3.6 // indirect
-	github.com/butuzov/ireturn v0.3.0 // indirect
-	github.com/butuzov/mirror v1.2.0 // indirect
-	github.com/catenacyber/perfsprint v0.7.1 // indirect
-	github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
-	github.com/cespare/xxhash/v2 v2.3.0 // indirect
-	github.com/charithe/durationcheck v0.0.10 // indirect
-	github.com/chavacava/garif v0.1.0 // indirect
-	github.com/ckaznocha/intrange v0.1.2 // indirect
-	github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
-	github.com/curioswitch/go-reassign v0.2.0 // indirect
-	github.com/daixiang0/gci v0.13.4 // indirect
+	github.com/andybalholm/brotli v1.1.0 // indirect
 	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
-	github.com/denis-tingaikin/go-header v0.5.0 // indirect
-	github.com/ettle/strcase v0.2.0 // indirect
-	github.com/fatih/color v1.17.0 // indirect
-	github.com/fatih/structtag v1.2.0 // indirect
-	github.com/firefart/nonamedreturns v1.0.5 // indirect
 	github.com/fsnotify/fsnotify v1.7.0 // indirect
-	github.com/fzipp/gocyclo v0.6.0 // indirect
-	github.com/ghostiam/protogetter v0.3.6 // indirect
-	github.com/go-critic/go-critic v0.11.4 // indirect
+	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 	github.com/go-openapi/jsonpointer v0.21.0 // indirect
 	github.com/go-openapi/jsonreference v0.21.0 // indirect
 	github.com/go-openapi/spec v0.21.0 // indirect
 	github.com/go-openapi/swag v0.23.0 // indirect
-	github.com/go-playground/locales v0.14.0 // indirect
-	github.com/go-playground/universal-translator v0.18.0 // indirect
-	github.com/go-toolsmith/astcast v1.1.0 // indirect
-	github.com/go-toolsmith/astcopy v1.1.0 // indirect
-	github.com/go-toolsmith/astequal v1.2.0 // indirect
-	github.com/go-toolsmith/astfmt v1.1.0 // indirect
-	github.com/go-toolsmith/astp v1.1.0 // indirect
-	github.com/go-toolsmith/strparse v1.1.0 // indirect
-	github.com/go-toolsmith/typep v1.1.0 // indirect
-	github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
-	github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
-	github.com/gobwas/glob v0.2.3 // indirect
-	github.com/gofrs/flock v0.12.1 // indirect
-	github.com/golang/protobuf v1.5.4 // indirect
-	github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
-	github.com/golangci/gofmt v0.0.0-20240724082148-399ed8a42d42 // indirect
-	github.com/golangci/golangci-lint v1.59.1 // indirect
-	github.com/golangci/misspell v0.6.0 // indirect
-	github.com/golangci/modinfo v0.3.4 // indirect
-	github.com/golangci/plugin-module-register v0.1.1 // indirect
-	github.com/golangci/revgrep v0.5.3 // indirect
-	github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
-	github.com/google/go-cmp v0.6.0 // indirect
+	github.com/go-playground/locales v0.14.1 // indirect
+	github.com/go-playground/universal-translator v0.18.1 // indirect
 	github.com/google/uuid v1.6.0 // indirect
-	github.com/gordonklaus/ineffassign v0.1.0 // indirect
-	github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
-	github.com/gostaticanalysis/comment v1.4.2 // indirect
-	github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
-	github.com/gostaticanalysis/nilerr v0.1.1 // indirect
-	github.com/hashicorp/go-version v1.7.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
-	github.com/hexdigest/gowrap v1.3.10 // indirect
-	github.com/hexops/gotextdiff v1.0.3 // indirect
-	github.com/inconshreveable/mousetrap v1.1.0 // indirect
-	github.com/jgautheron/goconst v1.7.1 // indirect
-	github.com/jingyugao/rowserrcheck v1.1.1 // indirect
-	github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
-	github.com/jjti/go-spancheck v0.6.2 // indirect
+	github.com/jmoiron/sqlx v1.4.0 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
-	github.com/julz/importas v0.1.0 // indirect
-	github.com/karamaru-alpha/copyloopvar v1.1.0 // indirect
-	github.com/kisielk/errcheck v1.7.0 // indirect
-	github.com/kkHAIKE/contextcheck v1.1.5 // indirect
 	github.com/klauspost/compress v1.17.9 // indirect
-	github.com/kulti/thelper v0.6.3 // indirect
-	github.com/kunwardeep/paralleltest v1.0.10 // indirect
-	github.com/kyoh86/exportloopref v0.1.11 // indirect
 	github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
 	github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
-	github.com/lasiar/canonicalheader v1.1.1 // indirect
-	github.com/ldez/gomoddirectives v0.2.4 // indirect
-	github.com/ldez/tagliatelle v0.5.0 // indirect
-	github.com/leodido/go-urn v1.2.1 // indirect
-	github.com/leonklingele/grouper v1.1.2 // indirect
-	github.com/lufeee/execinquery v1.2.1 // indirect
-	github.com/macabu/inamedparam v0.1.3 // indirect
+	github.com/leodido/go-urn v1.4.0 // indirect
 	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
-	github.com/maratori/testableexamples v1.0.0 // indirect
-	github.com/maratori/testpackage v1.1.1 // indirect
-	github.com/matoous/godox v0.0.0-20240105082147-c5b5e0e7c0c0 // indirect
 	github.com/mattn/go-colorable v0.1.13 // indirect
 	github.com/mattn/go-isatty v0.0.20 // indirect
 	github.com/mattn/go-runewidth v0.0.16 // indirect
-	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
-	github.com/mgechev/revive v1.3.9 // indirect
-	github.com/mitchellh/go-homedir v1.1.0 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
-	github.com/moricho/tparallel v0.3.2 // indirect
-	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
-	github.com/nakabonne/nestif v0.3.1 // indirect
-	github.com/nishanths/exhaustive v0.12.0 // indirect
-	github.com/nishanths/predeclared v0.2.2 // indirect
-	github.com/nunnatsa/ginkgolinter v0.16.2 // indirect
-	github.com/olekukonko/tablewriter v0.0.5 // indirect
 	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
-	github.com/philhofer/fwd v1.1.1 // indirect
-	github.com/pkg/errors v0.9.1 // indirect
+	github.com/philhofer/fwd v1.1.2 // indirect
 	github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
-	github.com/polyfloyd/go-errorlint v1.5.2 // indirect
-	github.com/prometheus/client_golang v1.19.1 // indirect
-	github.com/prometheus/client_model v0.6.1 // indirect
-	github.com/prometheus/common v0.55.0 // indirect
-	github.com/prometheus/procfs v0.15.1 // indirect
-	github.com/quasilyte/go-ruleguard v0.4.2 // indirect
-	github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
-	github.com/quasilyte/gogrep v0.5.0 // indirect
-	github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
-	github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
 	github.com/rivo/uniseg v0.4.7 // indirect
 	github.com/rogpeppe/go-internal v1.12.0 // indirect
-	github.com/russross/blackfriday/v2 v2.1.0 // indirect
-	github.com/ryancurrah/gomodguard v1.3.3 // indirect
-	github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
 	github.com/sagikazarmark/locafero v0.6.0 // indirect
 	github.com/sagikazarmark/slog-shim v0.1.0 // indirect
-	github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
-	github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
-	github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
-	github.com/sashamelentyev/usestdlibvars v1.27.0 // indirect
 	github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
 	github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
-	github.com/securego/gosec/v2 v2.20.1-0.20240525090044-5f0084eb01a9 // indirect
-	github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
-	github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
-	github.com/sirupsen/logrus v1.9.3 // indirect
-	github.com/sivchari/containedctx v1.0.3 // indirect
-	github.com/sivchari/tenv v1.10.0 // indirect
-	github.com/sonatard/noctx v0.0.2 // indirect
 	github.com/sourcegraph/conc v0.3.0 // indirect
-	github.com/sourcegraph/go-diff v0.7.0 // indirect
 	github.com/spf13/afero v1.11.0 // indirect
 	github.com/spf13/cast v1.6.0 // indirect
-	github.com/spf13/cobra v1.8.1 // indirect
-	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
-	github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
-	github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
-	github.com/stretchr/objx v0.5.2 // indirect
 	github.com/subosito/gotenv v1.6.0 // indirect
 	github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect
-	github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
-	github.com/tdakkota/asciicheck v0.2.0 // indirect
-	github.com/tetafro/godot v1.4.16 // indirect
-	github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a // indirect
-	github.com/timonwong/loggercheck v0.9.4 // indirect
-	github.com/tinylib/msgp v1.1.6 // indirect
-	github.com/tomarrell/wrapcheck/v2 v2.8.3 // indirect
-	github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
-	github.com/ultraware/funlen v0.1.0 // indirect
-	github.com/ultraware/whitespace v0.1.1 // indirect
-	github.com/urfave/cli/v2 v2.27.3 // indirect
-	github.com/uudashr/gocognit v1.1.3 // indirect
+	github.com/swaggo/files/v2 v2.0.1 // indirect
+	github.com/tinylib/msgp v1.1.8 // indirect
 	github.com/valyala/bytebufferpool v1.0.0 // indirect
-	github.com/valyala/fasthttp v1.44.0 // indirect
+	github.com/valyala/fasthttp v1.55.0 // indirect
 	github.com/valyala/tcplisten v1.0.0 // indirect
-	github.com/xen0n/gosmopolitan v1.2.2 // indirect
-	github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
-	github.com/yagipy/maintidx v1.0.0 // indirect
-	github.com/yeya24/promlinter v0.3.0 // indirect
-	github.com/ykadowak/zerologlint v0.1.5 // indirect
-	gitlab.com/bosi/decorder v0.4.2 // indirect
-	go-simpler.org/musttag v0.12.2 // indirect
-	go-simpler.org/sloglint v0.7.2 // indirect
-	go.uber.org/atomic v1.11.0 // indirect
-	go.uber.org/automaxprocs v1.5.3 // indirect
 	go.uber.org/multierr v1.11.0 // indirect
-	go.uber.org/zap v1.27.0 // indirect
 	golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
-	golang.org/x/exp/typeparams v0.0.0-20240719175910-8a7402abbf56 // indirect
 	golang.org/x/image v0.11.0 // indirect
-	golang.org/x/mod v0.19.0 // indirect
-	golang.org/x/net v0.27.0 // indirect
-	golang.org/x/sync v0.7.0 // indirect
-	golang.org/x/sys v0.22.0 // indirect
-	golang.org/x/text v0.16.0 // indirect
-	golang.org/x/tools v0.23.0 // indirect
-	google.golang.org/protobuf v1.34.2 // indirect
+	golang.org/x/net v0.28.0 // indirect
+	golang.org/x/sys v0.24.0 // indirect
+	golang.org/x/text v0.17.0 // indirect
+	golang.org/x/tools v0.24.0 // indirect
 	gopkg.in/ini.v1 v1.67.0 // indirect
-	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
-	honnef.co/go/tools v0.4.7 // indirect
-	mvdan.cc/gofumpt v0.6.0 // indirect
-	mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
-	sigs.k8s.io/yaml v1.4.0 // indirect
 )

+ 16 - 0
init/systemd/homethings.service

@@ -0,0 +1,16 @@
+[Unit]
+Description=Homethings service
+After=network.target
+After=nginx.service
+After=postgresql.service
+
+[Service]
+Type=simple
+User=dima
+Group=dima
+ExecStart=/var/www/homethings.ru/build/app/app -config="/var/www/homethings.ru/.env"
+WorkingDirectory=/var/www/homethings.ru/build/app
+Restart=always
+
+[Install]
+WantedBy=multi-user.target

+ 5 - 2
internal/api/v1/auth/check_auth.go

@@ -9,6 +9,7 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 	"github.com/golang-jwt/jwt/v4"
 
@@ -18,9 +19,9 @@ import (
 
 type (
 	AuthService interface {
-		GetClaims(fctx *fiber.Ctx) jwt.MapClaims
+		GetClaims(*fiber.Ctx) jwt.MapClaims
 		IsCorrectPassword(password string, hash string) bool
-		GenerateToken(user models.User) (string, error)
+		GenerateToken(models.User) (string, error)
 	}
 
 	UserRepository interface {
@@ -47,9 +48,11 @@ func CheckAuthHandler(
 		user, err := userRepository.Get(ctx, claims["name"].(string))
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusForbidden, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 7 - 6
internal/api/v1/auth/check_auth_test.go

@@ -3,7 +3,6 @@ package auth
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -13,10 +12,9 @@ import (
 	"github.com/golang-jwt/jwt/v4"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/auth/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -31,7 +29,7 @@ func TestCheckAuthHandler(t *testing.T) {
 
 	var (
 		username  = gofakeit.Username()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 
 		correctReq = req{
 			method:      fiber.MethodGet,
@@ -126,10 +124,13 @@ func TestCheckAuthHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/auth/check", CheckAuthHandler(tt.authServiceMock(mc), tt.userRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 0
internal/api/v1/auth/login.go

@@ -4,6 +4,7 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
@@ -30,20 +31,24 @@ func LoginHandler(
 		ctx := fctx.Context()
 		req := dto.LoginRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
 		user, err := userRepository.Get(ctx, req.Username)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusForbidden, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
@@ -53,6 +58,7 @@ func LoginHandler(
 
 		token, err := authService.GenerateToken(*user)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 6 - 8
internal/api/v1/auth/login_test.go

@@ -3,7 +3,6 @@ package auth
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/auth/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,12 +28,12 @@ func TestLoginHandler(t *testing.T) {
 	}
 
 	var (
-		id           = gofakeit.Number(1, 1000)
+		id           = gofakeit.Uint64()
 		username     = gofakeit.Username()
 		password     = gofakeit.Word()
 		passwordHash = gofakeit.Word()
 		token        = gofakeit.Word()
-		testError    = errors.New(gofakeit.Phrase())
+		testError    = gofakeit.Error()
 
 		correctReq = req{
 			method: fiber.MethodPost,
@@ -203,13 +201,13 @@ func TestLoginHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Post("/v1/auth/login", LoginHandler(tt.authServiceMock(mc), tt.userRepoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 43 - 43
internal/api/v1/auth/mocks/auth_service_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -20,14 +20,14 @@ type AuthServiceMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcGenerateToken          func(user models.User) (s1 string, err error)
-	inspectFuncGenerateToken   func(user models.User)
+	funcGenerateToken          func(u1 models.User) (s1 string, err error)
+	inspectFuncGenerateToken   func(u1 models.User)
 	afterGenerateTokenCounter  uint64
 	beforeGenerateTokenCounter uint64
 	GenerateTokenMock          mAuthServiceMockGenerateToken
 
-	funcGetClaims          func(fctx *fiber.Ctx) (m1 jwt.MapClaims)
-	inspectFuncGetClaims   func(fctx *fiber.Ctx)
+	funcGetClaims          func(cp1 *fiber.Ctx) (m1 jwt.MapClaims)
+	inspectFuncGetClaims   func(cp1 *fiber.Ctx)
 	afterGetClaimsCounter  uint64
 	beforeGetClaimsCounter uint64
 	GetClaimsMock          mAuthServiceMockGetClaims
@@ -84,12 +84,12 @@ type AuthServiceMockGenerateTokenExpectation struct {
 
 // AuthServiceMockGenerateTokenParams contains parameters of the AuthService.GenerateToken
 type AuthServiceMockGenerateTokenParams struct {
-	user models.User
+	u1 models.User
 }
 
 // AuthServiceMockGenerateTokenParamPtrs contains pointers to parameters of the AuthService.GenerateToken
 type AuthServiceMockGenerateTokenParamPtrs struct {
-	user *models.User
+	u1 *models.User
 }
 
 // AuthServiceMockGenerateTokenResults contains results of the AuthService.GenerateToken
@@ -109,7 +109,7 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) Optional() *mAuthServiceMo
 }
 
 // Expect sets up expected params for AuthService.GenerateToken
-func (mmGenerateToken *mAuthServiceMockGenerateToken) Expect(user models.User) *mAuthServiceMockGenerateToken {
+func (mmGenerateToken *mAuthServiceMockGenerateToken) Expect(u1 models.User) *mAuthServiceMockGenerateToken {
 	if mmGenerateToken.mock.funcGenerateToken != nil {
 		mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set")
 	}
@@ -122,7 +122,7 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) Expect(user models.User) *
 		mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by ExpectParams functions")
 	}
 
-	mmGenerateToken.defaultExpectation.params = &AuthServiceMockGenerateTokenParams{user}
+	mmGenerateToken.defaultExpectation.params = &AuthServiceMockGenerateTokenParams{u1}
 	for _, e := range mmGenerateToken.expectations {
 		if minimock.Equal(e.params, mmGenerateToken.defaultExpectation.params) {
 			mmGenerateToken.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGenerateToken.defaultExpectation.params)
@@ -132,8 +132,8 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) Expect(user models.User) *
 	return mmGenerateToken
 }
 
-// ExpectUserParam1 sets up expected param user for AuthService.GenerateToken
-func (mmGenerateToken *mAuthServiceMockGenerateToken) ExpectUserParam1(user models.User) *mAuthServiceMockGenerateToken {
+// ExpectU1Param1 sets up expected param u1 for AuthService.GenerateToken
+func (mmGenerateToken *mAuthServiceMockGenerateToken) ExpectU1Param1(u1 models.User) *mAuthServiceMockGenerateToken {
 	if mmGenerateToken.mock.funcGenerateToken != nil {
 		mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set")
 	}
@@ -149,13 +149,13 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) ExpectUserParam1(user mode
 	if mmGenerateToken.defaultExpectation.paramPtrs == nil {
 		mmGenerateToken.defaultExpectation.paramPtrs = &AuthServiceMockGenerateTokenParamPtrs{}
 	}
-	mmGenerateToken.defaultExpectation.paramPtrs.user = &user
+	mmGenerateToken.defaultExpectation.paramPtrs.u1 = &u1
 
 	return mmGenerateToken
 }
 
 // Inspect accepts an inspector function that has same arguments as the AuthService.GenerateToken
-func (mmGenerateToken *mAuthServiceMockGenerateToken) Inspect(f func(user models.User)) *mAuthServiceMockGenerateToken {
+func (mmGenerateToken *mAuthServiceMockGenerateToken) Inspect(f func(u1 models.User)) *mAuthServiceMockGenerateToken {
 	if mmGenerateToken.mock.inspectFuncGenerateToken != nil {
 		mmGenerateToken.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.GenerateToken")
 	}
@@ -179,7 +179,7 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) Return(s1 string, err erro
 }
 
 // Set uses given function f to mock the AuthService.GenerateToken method
-func (mmGenerateToken *mAuthServiceMockGenerateToken) Set(f func(user models.User) (s1 string, err error)) *AuthServiceMock {
+func (mmGenerateToken *mAuthServiceMockGenerateToken) Set(f func(u1 models.User) (s1 string, err error)) *AuthServiceMock {
 	if mmGenerateToken.defaultExpectation != nil {
 		mmGenerateToken.mock.t.Fatalf("Default expectation is already set for the AuthService.GenerateToken method")
 	}
@@ -194,14 +194,14 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) Set(f func(user models.Use
 
 // When sets expectation for the AuthService.GenerateToken which will trigger the result defined by the following
 // Then helper
-func (mmGenerateToken *mAuthServiceMockGenerateToken) When(user models.User) *AuthServiceMockGenerateTokenExpectation {
+func (mmGenerateToken *mAuthServiceMockGenerateToken) When(u1 models.User) *AuthServiceMockGenerateTokenExpectation {
 	if mmGenerateToken.mock.funcGenerateToken != nil {
 		mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set")
 	}
 
 	expectation := &AuthServiceMockGenerateTokenExpectation{
 		mock:   mmGenerateToken.mock,
-		params: &AuthServiceMockGenerateTokenParams{user},
+		params: &AuthServiceMockGenerateTokenParams{u1},
 	}
 	mmGenerateToken.expectations = append(mmGenerateToken.expectations, expectation)
 	return expectation
@@ -234,15 +234,15 @@ func (mmGenerateToken *mAuthServiceMockGenerateToken) invocationsDone() bool {
 }
 
 // GenerateToken implements auth.AuthService
-func (mmGenerateToken *AuthServiceMock) GenerateToken(user models.User) (s1 string, err error) {
+func (mmGenerateToken *AuthServiceMock) GenerateToken(u1 models.User) (s1 string, err error) {
 	mm_atomic.AddUint64(&mmGenerateToken.beforeGenerateTokenCounter, 1)
 	defer mm_atomic.AddUint64(&mmGenerateToken.afterGenerateTokenCounter, 1)
 
 	if mmGenerateToken.inspectFuncGenerateToken != nil {
-		mmGenerateToken.inspectFuncGenerateToken(user)
+		mmGenerateToken.inspectFuncGenerateToken(u1)
 	}
 
-	mm_params := AuthServiceMockGenerateTokenParams{user}
+	mm_params := AuthServiceMockGenerateTokenParams{u1}
 
 	// Record call args
 	mmGenerateToken.GenerateTokenMock.mutex.Lock()
@@ -261,12 +261,12 @@ func (mmGenerateToken *AuthServiceMock) GenerateToken(user models.User) (s1 stri
 		mm_want := mmGenerateToken.GenerateTokenMock.defaultExpectation.params
 		mm_want_ptrs := mmGenerateToken.GenerateTokenMock.defaultExpectation.paramPtrs
 
-		mm_got := AuthServiceMockGenerateTokenParams{user}
+		mm_got := AuthServiceMockGenerateTokenParams{u1}
 
 		if mm_want_ptrs != nil {
 
-			if mm_want_ptrs.user != nil && !minimock.Equal(*mm_want_ptrs.user, mm_got.user) {
-				mmGenerateToken.t.Errorf("AuthServiceMock.GenerateToken got unexpected parameter user, want: %#v, got: %#v%s\n", *mm_want_ptrs.user, mm_got.user, minimock.Diff(*mm_want_ptrs.user, mm_got.user))
+			if mm_want_ptrs.u1 != nil && !minimock.Equal(*mm_want_ptrs.u1, mm_got.u1) {
+				mmGenerateToken.t.Errorf("AuthServiceMock.GenerateToken got unexpected parameter u1, want: %#v, got: %#v%s\n", *mm_want_ptrs.u1, mm_got.u1, minimock.Diff(*mm_want_ptrs.u1, mm_got.u1))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -280,9 +280,9 @@ func (mmGenerateToken *AuthServiceMock) GenerateToken(user models.User) (s1 stri
 		return (*mm_results).s1, (*mm_results).err
 	}
 	if mmGenerateToken.funcGenerateToken != nil {
-		return mmGenerateToken.funcGenerateToken(user)
+		return mmGenerateToken.funcGenerateToken(u1)
 	}
-	mmGenerateToken.t.Fatalf("Unexpected call to AuthServiceMock.GenerateToken. %v", user)
+	mmGenerateToken.t.Fatalf("Unexpected call to AuthServiceMock.GenerateToken. %v", u1)
 	return
 }
 
@@ -377,12 +377,12 @@ type AuthServiceMockGetClaimsExpectation struct {
 
 // AuthServiceMockGetClaimsParams contains parameters of the AuthService.GetClaims
 type AuthServiceMockGetClaimsParams struct {
-	fctx *fiber.Ctx
+	cp1 *fiber.Ctx
 }
 
 // AuthServiceMockGetClaimsParamPtrs contains pointers to parameters of the AuthService.GetClaims
 type AuthServiceMockGetClaimsParamPtrs struct {
-	fctx **fiber.Ctx
+	cp1 **fiber.Ctx
 }
 
 // AuthServiceMockGetClaimsResults contains results of the AuthService.GetClaims
@@ -401,7 +401,7 @@ func (mmGetClaims *mAuthServiceMockGetClaims) Optional() *mAuthServiceMockGetCla
 }
 
 // Expect sets up expected params for AuthService.GetClaims
-func (mmGetClaims *mAuthServiceMockGetClaims) Expect(fctx *fiber.Ctx) *mAuthServiceMockGetClaims {
+func (mmGetClaims *mAuthServiceMockGetClaims) Expect(cp1 *fiber.Ctx) *mAuthServiceMockGetClaims {
 	if mmGetClaims.mock.funcGetClaims != nil {
 		mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set")
 	}
@@ -414,7 +414,7 @@ func (mmGetClaims *mAuthServiceMockGetClaims) Expect(fctx *fiber.Ctx) *mAuthServ
 		mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by ExpectParams functions")
 	}
 
-	mmGetClaims.defaultExpectation.params = &AuthServiceMockGetClaimsParams{fctx}
+	mmGetClaims.defaultExpectation.params = &AuthServiceMockGetClaimsParams{cp1}
 	for _, e := range mmGetClaims.expectations {
 		if minimock.Equal(e.params, mmGetClaims.defaultExpectation.params) {
 			mmGetClaims.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetClaims.defaultExpectation.params)
@@ -424,8 +424,8 @@ func (mmGetClaims *mAuthServiceMockGetClaims) Expect(fctx *fiber.Ctx) *mAuthServ
 	return mmGetClaims
 }
 
-// ExpectFctxParam1 sets up expected param fctx for AuthService.GetClaims
-func (mmGetClaims *mAuthServiceMockGetClaims) ExpectFctxParam1(fctx *fiber.Ctx) *mAuthServiceMockGetClaims {
+// ExpectCp1Param1 sets up expected param cp1 for AuthService.GetClaims
+func (mmGetClaims *mAuthServiceMockGetClaims) ExpectCp1Param1(cp1 *fiber.Ctx) *mAuthServiceMockGetClaims {
 	if mmGetClaims.mock.funcGetClaims != nil {
 		mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set")
 	}
@@ -441,13 +441,13 @@ func (mmGetClaims *mAuthServiceMockGetClaims) ExpectFctxParam1(fctx *fiber.Ctx)
 	if mmGetClaims.defaultExpectation.paramPtrs == nil {
 		mmGetClaims.defaultExpectation.paramPtrs = &AuthServiceMockGetClaimsParamPtrs{}
 	}
-	mmGetClaims.defaultExpectation.paramPtrs.fctx = &fctx
+	mmGetClaims.defaultExpectation.paramPtrs.cp1 = &cp1
 
 	return mmGetClaims
 }
 
 // Inspect accepts an inspector function that has same arguments as the AuthService.GetClaims
-func (mmGetClaims *mAuthServiceMockGetClaims) Inspect(f func(fctx *fiber.Ctx)) *mAuthServiceMockGetClaims {
+func (mmGetClaims *mAuthServiceMockGetClaims) Inspect(f func(cp1 *fiber.Ctx)) *mAuthServiceMockGetClaims {
 	if mmGetClaims.mock.inspectFuncGetClaims != nil {
 		mmGetClaims.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.GetClaims")
 	}
@@ -471,7 +471,7 @@ func (mmGetClaims *mAuthServiceMockGetClaims) Return(m1 jwt.MapClaims) *AuthServ
 }
 
 // Set uses given function f to mock the AuthService.GetClaims method
-func (mmGetClaims *mAuthServiceMockGetClaims) Set(f func(fctx *fiber.Ctx) (m1 jwt.MapClaims)) *AuthServiceMock {
+func (mmGetClaims *mAuthServiceMockGetClaims) Set(f func(cp1 *fiber.Ctx) (m1 jwt.MapClaims)) *AuthServiceMock {
 	if mmGetClaims.defaultExpectation != nil {
 		mmGetClaims.mock.t.Fatalf("Default expectation is already set for the AuthService.GetClaims method")
 	}
@@ -486,14 +486,14 @@ func (mmGetClaims *mAuthServiceMockGetClaims) Set(f func(fctx *fiber.Ctx) (m1 jw
 
 // When sets expectation for the AuthService.GetClaims which will trigger the result defined by the following
 // Then helper
-func (mmGetClaims *mAuthServiceMockGetClaims) When(fctx *fiber.Ctx) *AuthServiceMockGetClaimsExpectation {
+func (mmGetClaims *mAuthServiceMockGetClaims) When(cp1 *fiber.Ctx) *AuthServiceMockGetClaimsExpectation {
 	if mmGetClaims.mock.funcGetClaims != nil {
 		mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set")
 	}
 
 	expectation := &AuthServiceMockGetClaimsExpectation{
 		mock:   mmGetClaims.mock,
-		params: &AuthServiceMockGetClaimsParams{fctx},
+		params: &AuthServiceMockGetClaimsParams{cp1},
 	}
 	mmGetClaims.expectations = append(mmGetClaims.expectations, expectation)
 	return expectation
@@ -526,15 +526,15 @@ func (mmGetClaims *mAuthServiceMockGetClaims) invocationsDone() bool {
 }
 
 // GetClaims implements auth.AuthService
-func (mmGetClaims *AuthServiceMock) GetClaims(fctx *fiber.Ctx) (m1 jwt.MapClaims) {
+func (mmGetClaims *AuthServiceMock) GetClaims(cp1 *fiber.Ctx) (m1 jwt.MapClaims) {
 	mm_atomic.AddUint64(&mmGetClaims.beforeGetClaimsCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetClaims.afterGetClaimsCounter, 1)
 
 	if mmGetClaims.inspectFuncGetClaims != nil {
-		mmGetClaims.inspectFuncGetClaims(fctx)
+		mmGetClaims.inspectFuncGetClaims(cp1)
 	}
 
-	mm_params := AuthServiceMockGetClaimsParams{fctx}
+	mm_params := AuthServiceMockGetClaimsParams{cp1}
 
 	// Record call args
 	mmGetClaims.GetClaimsMock.mutex.Lock()
@@ -553,12 +553,12 @@ func (mmGetClaims *AuthServiceMock) GetClaims(fctx *fiber.Ctx) (m1 jwt.MapClaims
 		mm_want := mmGetClaims.GetClaimsMock.defaultExpectation.params
 		mm_want_ptrs := mmGetClaims.GetClaimsMock.defaultExpectation.paramPtrs
 
-		mm_got := AuthServiceMockGetClaimsParams{fctx}
+		mm_got := AuthServiceMockGetClaimsParams{cp1}
 
 		if mm_want_ptrs != nil {
 
-			if mm_want_ptrs.fctx != nil && !minimock.Equal(*mm_want_ptrs.fctx, mm_got.fctx) {
-				mmGetClaims.t.Errorf("AuthServiceMock.GetClaims got unexpected parameter fctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.fctx, mm_got.fctx, minimock.Diff(*mm_want_ptrs.fctx, mm_got.fctx))
+			if mm_want_ptrs.cp1 != nil && !minimock.Equal(*mm_want_ptrs.cp1, mm_got.cp1) {
+				mmGetClaims.t.Errorf("AuthServiceMock.GetClaims got unexpected parameter cp1, want: %#v, got: %#v%s\n", *mm_want_ptrs.cp1, mm_got.cp1, minimock.Diff(*mm_want_ptrs.cp1, mm_got.cp1))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -572,9 +572,9 @@ func (mmGetClaims *AuthServiceMock) GetClaims(fctx *fiber.Ctx) (m1 jwt.MapClaims
 		return (*mm_results).m1
 	}
 	if mmGetClaims.funcGetClaims != nil {
-		return mmGetClaims.funcGetClaims(fctx)
+		return mmGetClaims.funcGetClaims(cp1)
 	}
-	mmGetClaims.t.Fatalf("Unexpected call to AuthServiceMock.GetClaims. %v", fctx)
+	mmGetClaims.t.Fatalf("Unexpected call to AuthServiceMock.GetClaims. %v", cp1)
 	return
 }
 

+ 1 - 1
internal/api/v1/auth/mocks/user_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 

+ 0 - 8
internal/api/v1/common.go

@@ -1,8 +0,0 @@
-package v1
-
-import "database/sql"
-
-const (
-	DefaultTxLevel     = sql.LevelReadCommitted
-	DefaultTestTimeOut = -1
-)

+ 44 - 48
internal/api/v1/image/add_image.go

@@ -2,21 +2,20 @@ package image
 
 //go:generate mkdir -p mocks
 //go:generate rm -rf ./mocks/*_minimock.go
-//go:generate minimock -i FileRepository,ThingImageRepository,PlaceImageRepository -o ./mocks/ -s "_minimock.go"
+//go:generate minimock -i TransactionManager,FileRepository,ThingImageRepository,PlaceImageRepository -o ./mocks/ -s "_minimock.go"
 
 import (
 	"context"
-	"database/sql"
 	"mime/multipart"
 	"path/filepath"
 	"strconv"
 	"time"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/random"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
@@ -24,28 +23,28 @@ import (
 const fileDateLayout = "2006-01-02-15-04-05"
 
 type (
+	TransactionManager interface {
+		ReadCommitted(context.Context, func(ctx context.Context) error) error
+	}
+
 	FileRepository interface {
 		Save(fctx *fiber.Ctx, header *multipart.FileHeader, path string) error
 		Delete(path string) error
 	}
 
 	ThingImageRepository interface {
-		Add(ctx context.Context, req models.AddThingImageRequest, tx *sql.Tx) error
-		Get(ctx context.Context, imageID int) (*models.Image, error)
-		GetByThingID(ctx context.Context, thingID int) ([]models.Image, error)
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.Image, error)
-		Delete(ctx context.Context, imageID int, tx *sql.Tx) error
-		BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
-		CommitTx(tx *sql.Tx) error
+		Add(ctx context.Context, req models.AddThingImageRequest) error
+		Get(ctx context.Context, id uint64) (*models.Image, error)
+		GetByThingID(ctx context.Context, id uint64) ([]models.Image, error)
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.Image, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	PlaceImageRepository interface {
-		Add(ctx context.Context, req models.AddPlaceImageRequest, tx *sql.Tx) error
-		Get(ctx context.Context, imageID int) (*models.Image, error)
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.Image, error)
-		Delete(ctx context.Context, imageID int, tx *sql.Tx) error
-		BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
-		CommitTx(tx *sql.Tx) error
+		Add(ctx context.Context, req models.AddPlaceImageRequest) error
+		Get(ctx context.Context, id uint64) (*models.Image, error)
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.Image, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 )
 
@@ -62,41 +61,46 @@ type (
 // @Accept      mpfd
 // @Produce     json
 func AddImageHandler(
+	tm TransactionManager,
 	fileRepository FileRepository,
 	thingImageRepository ThingImageRepository,
 	placeImageRepository PlaceImageRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		var form *multipart.Form
-		var placeID, thingID int
+		var placeID, thingID uint64
 		var files []string
 		var err error
 
 		ctx := fctx.Context()
 
 		if form, err = fctx.MultipartForm(); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		if formPlace := form.Value["place_id"]; len(formPlace) > 0 {
-			placeID, err = strconv.Atoi(formPlace[0])
+			placeID, err = strconv.ParseUint(formPlace[0], 0, 64)
 			if err != nil {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, err.Error())
 			}
 		}
 
 		if formThing := form.Value["thing_id"]; len(formThing) > 0 {
-			thingID, err = strconv.Atoi(formThing[0])
+			thingID, err = strconv.ParseUint(formThing[0], 0, 64)
 			if err != nil {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, err.Error())
 			}
 		}
 
 		date := time.Now().Format(fileDateLayout)
 		for _, file := range form.File["files"] {
-			filename := "/files/" + date + "_" + helpers.GenerateRandomString(10) + filepath.Ext(file.Filename)
+			filename := "/files/" + date + "_" + random.GenerateRandomString(10) + filepath.Ext(file.Filename)
 
 			if err = fileRepository.Save(fctx, file, filename); err != nil {
+				logger.Error(ctx, err.Error())
 				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 			}
 
@@ -107,37 +111,29 @@ func AddImageHandler(
 			return fiber.NewError(fiber.StatusBadRequest, "")
 		}
 
-		var tx *sql.Tx
-		if thingID > 0 {
-			tx, err = thingImageRepository.BeginTx(ctx, API.DefaultTxLevel)
-			if err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
-
-			for _, file := range files {
-				if err = thingImageRepository.Add(ctx, mappers.ToAddThingImageRequest(thingID, file), tx); err != nil {
-					return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			if thingID > 0 {
+				for _, file := range files {
+					txErr := thingImageRepository.Add(ctx, mappers.ToAddThingImageRequest(thingID, file))
+					if txErr != nil {
+						return txErr
+					}
 				}
-			}
-
-			if err = thingImageRepository.CommitTx(tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
-		} else {
-			tx, err = placeImageRepository.BeginTx(ctx, API.DefaultTxLevel)
-			if err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
-
-			for _, file := range files {
-				if err = placeImageRepository.Add(ctx, mappers.ToAddPlaceImageRequest(placeID, file), tx); err != nil {
-					return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			} else {
+				for _, file := range files {
+					txErr := placeImageRepository.Add(ctx, mappers.ToAddPlaceImageRequest(placeID, file))
+					if txErr != nil {
+						return txErr
+					}
 				}
 			}
 
-			if err = placeImageRepository.CommitTx(tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
+			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		return fctx.JSON(factory.CreateEmptyResponse())

+ 51 - 133
internal/api/v1/image/add_image_test.go

@@ -3,8 +3,6 @@ package image
 import (
 	"bytes"
 	"context"
-	"database/sql"
-	"errors"
 	"mime/multipart"
 	"net/http/httptest"
 	"strconv"
@@ -15,10 +13,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -34,15 +31,19 @@ func TestAddImageHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		placeID   = gofakeit.Uint64()
+		thingID   = gofakeit.Uint64()
+		testError = gofakeit.Error()
+
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
 	)
 
 	// Correct request for adding place image
 	addPlaceCorrectBody := &bytes.Buffer{}
 	addPlaceCorrectWriter := multipart.NewWriter(addPlaceCorrectBody)
-	addPlaceCorrectWriter.WriteField("place_id", strconv.Itoa(placeID))
+	addPlaceCorrectWriter.WriteField("place_id", strconv.FormatUint(placeID, 10))
 	addPlaceCorrectWriter.CreateFormFile("files", gofakeit.Word())
 	addPlaceCorrectContentType := addPlaceCorrectWriter.FormDataContentType()
 	addPlaceCorrectWriter.Close()
@@ -50,7 +51,7 @@ func TestAddImageHandler(t *testing.T) {
 	// Correct request for adding thing image
 	addThingCorrectBody := &bytes.Buffer{}
 	addThingCorrectWriter := multipart.NewWriter(addThingCorrectBody)
-	addThingCorrectWriter.WriteField("thing_id", strconv.Itoa(thingID))
+	addThingCorrectWriter.WriteField("thing_id", strconv.FormatUint(thingID, 10))
 	addThingCorrectWriter.CreateFormFile("files", gofakeit.Word())
 	addThingCorrectContentType := addThingCorrectWriter.FormDataContentType()
 	addThingCorrectWriter.Close()
@@ -80,6 +81,7 @@ func TestAddImageHandler(t *testing.T) {
 		req                req
 		resCode            int
 		resBody            interface{}
+		tmMock             func(mc *minimock.Controller) TransactionManager
 		fileRepoMock       func(mc *minimock.Controller) FileRepository
 		placeImageRepoMock func(mc *minimock.Controller) PlaceImageRepository
 		thingImageRepoMock func(mc *minimock.Controller) ThingImageRepository
@@ -91,6 +93,9 @@ func TestAddImageHandler(t *testing.T) {
 				route:  "/v1/images",
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
@@ -110,6 +115,9 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: addPlaceIncorrectContentType,
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
@@ -129,6 +137,9 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: addThingIncorrectContentType,
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
@@ -148,6 +159,9 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: emptyContentType,
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
@@ -159,30 +173,7 @@ func TestAddImageHandler(t *testing.T) {
 			},
 		},
 		{
-			name: "negative case - repository error (begin tx)",
-			req: req{
-				method:      fiber.MethodPost,
-				route:       "/v1/images",
-				body:        addPlaceCorrectBody.Bytes(),
-				contentType: addPlaceCorrectContentType,
-			},
-			resCode: fiber.StatusInternalServerError,
-			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				mock := mocks.NewPlaceImageRepositoryMock(mc)
-				mock.BeginTxMock.Return(nil, testError)
-				return mock
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				return mocks.NewThingImageRepositoryMock(mc)
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				mock := mocks.NewFileRepositoryMock(mc)
-				mock.SaveMock.Return(nil)
-				return mock
-			},
-		},
-		{
-			name: "negative case - repository error (commit tx)",
+			name: "negative case - repository error (add image)",
 			req: req{
 				method:      fiber.MethodPost,
 				route:       "/v1/images",
@@ -190,43 +181,15 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: addPlaceCorrectContentType,
 			},
 			resCode: fiber.StatusInternalServerError,
-			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				mock := mocks.NewPlaceImageRepositoryMock(mc)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceImageRequest, tx *sql.Tx) {
-					assert.Equal(mc, placeID, req.PlaceID)
-				}).Return(nil)
-
-				mock.CommitTxMock.Return(testError)
-
-				return mock
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				return mocks.NewThingImageRepositoryMock(mc)
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				mock := mocks.NewFileRepositoryMock(mc)
-				mock.SaveMock.Return(nil)
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-		},
-		{
-			name: "negative case - repository error (add image)",
-			req: req{
-				method:      fiber.MethodPost,
-				route:       "/v1/images",
-				body:        addPlaceCorrectBody.Bytes(),
-				contentType: addPlaceCorrectContentType,
-			},
-			resCode: fiber.StatusInternalServerError,
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceImageRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceImageRequest) {
 					assert.Equal(mc, placeID, req.PlaceID)
 				}).Return(testError)
 
@@ -251,17 +214,18 @@ func TestAddImageHandler(t *testing.T) {
 			},
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceImageRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceImageRequest) {
 					assert.Equal(mc, placeID, req.PlaceID)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
@@ -274,30 +238,7 @@ func TestAddImageHandler(t *testing.T) {
 			},
 		},
 		{
-			name: "negative case - repository error (begin tx)",
-			req: req{
-				method:      fiber.MethodPost,
-				route:       "/v1/images",
-				body:        addThingCorrectBody.Bytes(),
-				contentType: addThingCorrectContentType,
-			},
-			resCode: fiber.StatusInternalServerError,
-			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				return mocks.NewPlaceImageRepositoryMock(mc)
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				mock := mocks.NewThingImageRepositoryMock(mc)
-				mock.BeginTxMock.Return(nil, testError)
-				return mock
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				mock := mocks.NewFileRepositoryMock(mc)
-				mock.SaveMock.Return(nil)
-				return mock
-			},
-		},
-		{
-			name: "negative case - repository error (commit tx)",
+			name: "negative case - repository error (add image)",
 			req: req{
 				method:      fiber.MethodPost,
 				route:       "/v1/images",
@@ -305,46 +246,18 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: addThingCorrectContentType,
 			},
 			resCode: fiber.StatusInternalServerError,
-			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				return mocks.NewPlaceImageRepositoryMock(mc)
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				mock := mocks.NewThingImageRepositoryMock(mc)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingImageRequest, tx *sql.Tx) {
-					assert.Equal(mc, thingID, req.ThingID)
-				}).Return(nil)
-
-				mock.CommitTxMock.Return(testError)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				mock := mocks.NewFileRepositoryMock(mc)
-				mock.SaveMock.Return(nil)
-				return mock
-			},
-		},
-		{
-			name: "negative case - repository error (add image)",
-			req: req{
-				method:      fiber.MethodPost,
-				route:       "/v1/images",
-				body:        addThingCorrectBody.Bytes(),
-				contentType: addThingCorrectContentType,
-			},
-			resCode: fiber.StatusInternalServerError,
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingImageRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingImageRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(testError)
 
@@ -366,20 +279,21 @@ func TestAddImageHandler(t *testing.T) {
 			},
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingImageRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingImageRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			fileRepoMock: func(mc *minimock.Controller) FileRepository {
@@ -397,6 +311,9 @@ func TestAddImageHandler(t *testing.T) {
 				contentType: addThingCorrectContentType,
 			},
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
@@ -419,6 +336,7 @@ func TestAddImageHandler(t *testing.T) {
 			fiberApp := fiber.New()
 
 			fiberApp.Post("/v1/images", AddImageHandler(
+				tt.tmMock(mc),
 				tt.fileRepoMock(mc),
 				tt.thingImageRepoMock(mc),
 				tt.placeImageRepoMock(mc),
@@ -426,11 +344,11 @@ func TestAddImageHandler(t *testing.T) {
 
 			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, bytes.NewReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 22 - 13
internal/api/v1/image/delete_place_image.go

@@ -1,12 +1,13 @@
 package image
 
 import (
-	"database/sql"
-	"errors"
+	"context"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 )
 
 // @Router 		/api/v1/images/place/{imageId} [delete]
@@ -20,30 +21,38 @@ import (
 // @Accept      json
 // @Produce     json
 func DeletePlaceImageHandler(
+	tm TransactionManager,
 	fileRepository FileRepository,
 	placeImageRepository PlaceImageRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("imageId")
+
+		id, err := request.ConvertToUint64(fctx, "imageId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		image, err := placeImageRepository.Get(ctx, id)
-		if err != nil {
-			if errors.Is(err, sql.ErrNoRows) {
-				return fiber.NewError(fiber.StatusBadRequest, "")
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			image, txErr := placeImageRepository.Get(ctx, id)
+			if txErr != nil {
+				return txErr
 			}
 
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = placeImageRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = placeImageRepository.Delete(ctx, id, nil); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = fileRepository.Delete(image.Image); txErr != nil {
+				return txErr
+			}
 
-		if err = fileRepository.Delete(image.Image); err != nil {
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 46 - 34
internal/api/v1/image/delete_place_image_test.go

@@ -2,8 +2,6 @@ package image
 
 import (
 	"context"
-	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,13 +26,17 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 	}
 
 	var (
-		imageID   = gofakeit.Number(1, 1000)
+		imageID   = uint64(gofakeit.Number(1, 1000))
 		imageURL  = gofakeit.URL()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
+
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
 
 		correctReq = req{
 			method: fiber.MethodDelete,
-			route:  "/v1/images/place/" + strconv.Itoa(imageID),
+			route:  "/v1/images/place/" + strconv.FormatUint(imageID, 10),
 		}
 
 		repoRes = &models.Image{
@@ -48,6 +49,7 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 		req                req
 		resCode            int
 		resBody            interface{}
+		tmMock             func(mc *minimock.Controller) TransactionManager
 		placeImageRepoMock func(mc *minimock.Controller) PlaceImageRepository
 		fileRepoMock       func(mc *minimock.Controller) FileRepository
 	}{
@@ -58,25 +60,11 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 				route:  "/v1/images/place/" + gofakeit.Word(),
 			},
 			resCode: fiber.StatusBadRequest,
-			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				return mocks.NewPlaceImageRepositoryMock(mc)
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				return mocks.NewFileRepositoryMock(mc)
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
 			},
-		},
-		{
-			name:    "negative case - bad request (image not exists)",
-			req:     correctReq,
-			resCode: fiber.StatusBadRequest,
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
-				mock := mocks.NewPlaceImageRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, imageID, id)
-				}).Return(nil, sql.ErrNoRows)
-
-				return mock
+				return mocks.NewPlaceImageRepositoryMock(mc)
 			},
 			fileRepoMock: func(mc *minimock.Controller) FileRepository {
 				return mocks.NewFileRepositoryMock(mc)
@@ -86,10 +74,15 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 			name:    "negative case - repository error (get)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil, testError)
 
@@ -100,17 +93,22 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 			},
 		},
 		{
-			name:    "negative case - repository error (update)",
+			name:    "negative case - repository error (delete)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(testError)
 
@@ -124,14 +122,19 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 			name:    "negative case - file delete error",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -148,14 +151,19 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -177,15 +185,19 @@ func TestDeletePlaceImageHandler(t *testing.T) {
 			fiberApp := fiber.New()
 
 			fiberApp.Delete("/v1/images/place/:imageId", DeletePlaceImageHandler(
+				tt.tmMock(mc),
 				tt.fileRepoMock(mc),
 				tt.placeImageRepoMock(mc),
 			))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 22 - 13
internal/api/v1/image/delete_thing_image.go

@@ -1,12 +1,13 @@
 package image
 
 import (
-	"database/sql"
-	"errors"
+	"context"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 )
 
 // @Router 		/api/v1/images/thing/{imageId} [delete]
@@ -20,30 +21,38 @@ import (
 // @Accept      json
 // @Produce     json
 func DeleteThingImageHandler(
+	tm TransactionManager,
 	fileRepository FileRepository,
 	thingImageRepository ThingImageRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("imageId")
+
+		id, err := request.ConvertToUint64(fctx, "imageId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		image, err := thingImageRepository.Get(ctx, id)
-		if err != nil {
-			if errors.Is(err, sql.ErrNoRows) {
-				return fiber.NewError(fiber.StatusBadRequest, "")
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			image, txErr := thingImageRepository.Get(ctx, id)
+			if txErr != nil {
+				return txErr
 			}
 
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = thingImageRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = thingImageRepository.Delete(ctx, id, nil); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = fileRepository.Delete(image.Image); txErr != nil {
+				return txErr
+			}
 
-		if err = fileRepository.Delete(image.Image); err != nil {
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 45 - 33
internal/api/v1/image/delete_thing_image_test.go

@@ -2,8 +2,6 @@ package image
 
 import (
 	"context"
-	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,13 +26,17 @@ func TestDeleteThingImageHandler(t *testing.T) {
 	}
 
 	var (
-		imageID   = gofakeit.Number(1, 1000)
+		imageID   = uint64(gofakeit.Number(1, 1000))
 		imageURL  = gofakeit.URL()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
+
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
 
 		correctReq = req{
 			method: fiber.MethodDelete,
-			route:  "/v1/images/thing/" + strconv.Itoa(imageID),
+			route:  "/v1/images/thing/" + strconv.FormatUint(imageID, 10),
 		}
 
 		repoRes = &models.Image{
@@ -48,6 +49,7 @@ func TestDeleteThingImageHandler(t *testing.T) {
 		req                req
 		resCode            int
 		resBody            interface{}
+		tmMock             func(mc *minimock.Controller) TransactionManager
 		thingImageRepoMock func(mc *minimock.Controller) ThingImageRepository
 		fileRepoMock       func(mc *minimock.Controller) FileRepository
 	}{
@@ -58,25 +60,11 @@ func TestDeleteThingImageHandler(t *testing.T) {
 				route:  "/v1/images/thing/" + gofakeit.Word(),
 			},
 			resCode: fiber.StatusBadRequest,
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				return mocks.NewThingImageRepositoryMock(mc)
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				return mocks.NewFileRepositoryMock(mc)
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
 			},
-		},
-		{
-			name:    "negative case - bad request (image not exists)",
-			req:     correctReq,
-			resCode: fiber.StatusBadRequest,
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				mock := mocks.NewThingImageRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, imageID, id)
-				}).Return(nil, sql.ErrNoRows)
-
-				return mock
+				return mocks.NewThingImageRepositoryMock(mc)
 			},
 			fileRepoMock: func(mc *minimock.Controller) FileRepository {
 				return mocks.NewFileRepositoryMock(mc)
@@ -86,10 +74,15 @@ func TestDeleteThingImageHandler(t *testing.T) {
 			name:    "negative case - repository error (get)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil, testError)
 
@@ -103,14 +96,19 @@ func TestDeleteThingImageHandler(t *testing.T) {
 			name:    "negative case - repository error (delete)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(testError)
 
@@ -124,14 +122,19 @@ func TestDeleteThingImageHandler(t *testing.T) {
 			name:    "negative case - file delete error",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -148,14 +151,19 @@ func TestDeleteThingImageHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -177,15 +185,19 @@ func TestDeleteThingImageHandler(t *testing.T) {
 			fiberApp := fiber.New()
 
 			fiberApp.Delete("/v1/images/thing/:imageId", DeleteThingImageHandler(
+				tt.tmMock(mc),
 				tt.fileRepoMock(mc),
 				tt.thingImageRepoMock(mc),
 			))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 9 - 5
internal/api/v1/image/get_place_images.go

@@ -3,9 +3,11 @@ package image
 import (
 	"sort"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
@@ -27,19 +29,23 @@ func GetPlaceImagesHandler(
 	return func(fctx *fiber.Ctx) error {
 		var res []models.Image
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("placeId")
+
+		id, err := request.ConvertToUint64(fctx, "placeId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		placesRes, err := placeImageRepository.GetByPlaceID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 		res = append(res, placesRes...)
 
 		thingsRes, err := thingImageRepository.GetByPlaceID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 		res = append(res, thingsRes...)
@@ -48,8 +54,6 @@ func GetPlaceImagesHandler(
 			return res[i].CreatedAt.After(res[j].CreatedAt)
 		})
 
-		res = helpers.ApplyLocation(fctx, res)
-
-		return fctx.JSON(mappers.ToImagesResponse(res))
+		return fctx.JSON(mappers.ToImagesResponse(location.ApplyLocation(fctx, res)))
 	}
 }

+ 18 - 17
internal/api/v1/image/get_place_images_test.go

@@ -3,7 +3,6 @@ package image
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -14,10 +13,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,28 +28,28 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		thingID   = gofakeit.Number(1, 1000)
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		thingID   = uint64(gofakeit.Number(1, 1000))
 		date1     = gofakeit.Date()
 		date2     = date1.Add(time.Hour)
 		date3     = date2.Add(time.Hour)
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/images/place/" + strconv.Itoa(placeID),
+			route:  "/v1/images/place/" + strconv.FormatUint(placeID, 10),
 		}
 
 		placeImageRepoRes = []models.Image{
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				PlaceID:   sql.NullInt64{Valid: true, Int64: int64(placeID)},
 				CreatedAt: date1,
 			},
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				PlaceID:   sql.NullInt64{Valid: true, Int64: int64(placeID)},
 				CreatedAt: date2,
@@ -60,7 +58,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 
 		thingImageRepoRes = []models.Image{
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				ThingID:   sql.NullInt64{Valid: true, Int64: int64(thingID)},
 				CreatedAt: date3,
@@ -120,7 +118,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -137,7 +135,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, nil)
 
@@ -146,7 +144,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -161,7 +159,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 			placeImageRepoMock: func(mc *minimock.Controller) PlaceImageRepository {
 				mock := mocks.NewPlaceImageRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(placeImageRepoRes, nil)
 
@@ -170,7 +168,7 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(thingImageRepoRes, nil)
 
@@ -191,11 +189,14 @@ func TestGetPlaceImagesHandler(t *testing.T) {
 				tt.placeImageRepoMock(mc),
 			))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 5
internal/api/v1/image/get_thing_images.go

@@ -1,9 +1,11 @@
 package image
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -22,18 +24,19 @@ func GetThingImagesHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := thingImageRepository.GetByThingID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
-
-		return fctx.JSON(mappers.ToImagesResponse(res))
+		return fctx.JSON(mappers.ToImagesResponse(location.ApplyLocation(fctx, res)))
 	}
 }

+ 14 - 13
internal/api/v1/image/get_thing_images_test.go

@@ -3,7 +3,6 @@ package image
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,30 +27,30 @@ func TestGetThingImagesHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/images/thing/" + strconv.Itoa(thingID),
+			route:  "/v1/images/thing/" + strconv.FormatUint(thingID, 10),
 		}
 
 		imageRepoRes = []models.Image{
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				CreatedAt: gofakeit.Date(),
 				ThingID:   sql.NullInt64{Valid: true, Int64: int64(thingID)},
 			},
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				CreatedAt: gofakeit.Date(),
 				ThingID:   sql.NullInt64{Valid: true, Int64: int64(thingID)},
 			},
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        gofakeit.Uint64(),
 				Image:     gofakeit.URL(),
 				CreatedAt: gofakeit.Date(),
 				ThingID:   sql.NullInt64{Valid: true, Int64: int64(thingID)},
@@ -108,7 +106,7 @@ func TestGetThingImagesHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -123,7 +121,7 @@ func TestGetThingImagesHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(imageRepoRes, nil)
 
@@ -141,11 +139,14 @@ func TestGetThingImagesHandler(t *testing.T) {
 
 			fiberApp.Get("/v1/images/thing/:thingId", GetThingImagesHandler(tt.thingImageRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 1 - 1
internal/api/v1/image/mocks/file_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 

Різницю між файлами не показано, бо вона завелика
+ 42 - 730
internal/api/v1/image/mocks/place_image_repository_minimock.go


Різницю між файлами не показано, бо вона завелика
+ 42 - 730
internal/api/v1/image/mocks/thing_image_repository_minimock.go


+ 393 - 0
internal/api/v1/image/mocks/transaction_manager_minimock.go

@@ -0,0 +1,393 @@
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
+
+package mocks
+
+//go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/image.TransactionManager -o transaction_manager_minimock.go -n TransactionManagerMock -p mocks
+
+import (
+	"context"
+	"sync"
+	mm_atomic "sync/atomic"
+	mm_time "time"
+
+	"github.com/gojuno/minimock/v3"
+)
+
+// TransactionManagerMock implements image.TransactionManager
+type TransactionManagerMock struct {
+	t          minimock.Tester
+	finishOnce sync.Once
+
+	funcReadCommitted          func(ctx context.Context, f1 func(ctx context.Context) error) (err error)
+	inspectFuncReadCommitted   func(ctx context.Context, f1 func(ctx context.Context) error)
+	afterReadCommittedCounter  uint64
+	beforeReadCommittedCounter uint64
+	ReadCommittedMock          mTransactionManagerMockReadCommitted
+}
+
+// NewTransactionManagerMock returns a mock for image.TransactionManager
+func NewTransactionManagerMock(t minimock.Tester) *TransactionManagerMock {
+	m := &TransactionManagerMock{t: t}
+
+	if controller, ok := t.(minimock.MockController); ok {
+		controller.RegisterMocker(m)
+	}
+
+	m.ReadCommittedMock = mTransactionManagerMockReadCommitted{mock: m}
+	m.ReadCommittedMock.callArgs = []*TransactionManagerMockReadCommittedParams{}
+
+	t.Cleanup(m.MinimockFinish)
+
+	return m
+}
+
+type mTransactionManagerMockReadCommitted struct {
+	optional           bool
+	mock               *TransactionManagerMock
+	defaultExpectation *TransactionManagerMockReadCommittedExpectation
+	expectations       []*TransactionManagerMockReadCommittedExpectation
+
+	callArgs []*TransactionManagerMockReadCommittedParams
+	mutex    sync.RWMutex
+
+	expectedInvocations uint64
+}
+
+// TransactionManagerMockReadCommittedExpectation specifies expectation struct of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedExpectation struct {
+	mock      *TransactionManagerMock
+	params    *TransactionManagerMockReadCommittedParams
+	paramPtrs *TransactionManagerMockReadCommittedParamPtrs
+	results   *TransactionManagerMockReadCommittedResults
+	Counter   uint64
+}
+
+// TransactionManagerMockReadCommittedParams contains parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParams struct {
+	ctx context.Context
+	f1  func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedParamPtrs contains pointers to parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParamPtrs struct {
+	ctx *context.Context
+	f1  *func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedResults contains results of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedResults struct {
+	err error
+}
+
+// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
+// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
+// Optional() makes method check to work in '0 or more' mode.
+// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
+// catch the problems when the expected method call is totally skipped during test run.
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Optional() *mTransactionManagerMockReadCommitted {
+	mmReadCommitted.optional = true
+	return mmReadCommitted
+}
+
+// Expect sets up expected params for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Expect(ctx context.Context, f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by ExpectParams functions")
+	}
+
+	mmReadCommitted.defaultExpectation.params = &TransactionManagerMockReadCommittedParams{ctx, f1}
+	for _, e := range mmReadCommitted.expectations {
+		if minimock.Equal(e.params, mmReadCommitted.defaultExpectation.params) {
+			mmReadCommitted.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmReadCommitted.defaultExpectation.params)
+		}
+	}
+
+	return mmReadCommitted
+}
+
+// ExpectCtxParam1 sets up expected param ctx for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectCtxParam1(ctx context.Context) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.ctx = &ctx
+
+	return mmReadCommitted
+}
+
+// ExpectF1Param2 sets up expected param f1 for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectF1Param2(f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.f1 = &f1
+
+	return mmReadCommitted
+}
+
+// Inspect accepts an inspector function that has same arguments as the TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Inspect(f func(ctx context.Context, f1 func(ctx context.Context) error)) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.inspectFuncReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("Inspect function is already set for TransactionManagerMock.ReadCommitted")
+	}
+
+	mmReadCommitted.mock.inspectFuncReadCommitted = f
+
+	return mmReadCommitted
+}
+
+// Return sets up results that will be returned by TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Return(err error) *TransactionManagerMock {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{mock: mmReadCommitted.mock}
+	}
+	mmReadCommitted.defaultExpectation.results = &TransactionManagerMockReadCommittedResults{err}
+	return mmReadCommitted.mock
+}
+
+// Set uses given function f to mock the TransactionManager.ReadCommitted method
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Set(f func(ctx context.Context, f1 func(ctx context.Context) error) (err error)) *TransactionManagerMock {
+	if mmReadCommitted.defaultExpectation != nil {
+		mmReadCommitted.mock.t.Fatalf("Default expectation is already set for the TransactionManager.ReadCommitted method")
+	}
+
+	if len(mmReadCommitted.expectations) > 0 {
+		mmReadCommitted.mock.t.Fatalf("Some expectations are already set for the TransactionManager.ReadCommitted method")
+	}
+
+	mmReadCommitted.mock.funcReadCommitted = f
+	return mmReadCommitted.mock
+}
+
+// When sets expectation for the TransactionManager.ReadCommitted which will trigger the result defined by the following
+// Then helper
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) When(ctx context.Context, f1 func(ctx context.Context) error) *TransactionManagerMockReadCommittedExpectation {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	expectation := &TransactionManagerMockReadCommittedExpectation{
+		mock:   mmReadCommitted.mock,
+		params: &TransactionManagerMockReadCommittedParams{ctx, f1},
+	}
+	mmReadCommitted.expectations = append(mmReadCommitted.expectations, expectation)
+	return expectation
+}
+
+// Then sets up TransactionManager.ReadCommitted return parameters for the expectation previously defined by the When method
+func (e *TransactionManagerMockReadCommittedExpectation) Then(err error) *TransactionManagerMock {
+	e.results = &TransactionManagerMockReadCommittedResults{err}
+	return e.mock
+}
+
+// Times sets number of times TransactionManager.ReadCommitted should be invoked
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Times(n uint64) *mTransactionManagerMockReadCommitted {
+	if n == 0 {
+		mmReadCommitted.mock.t.Fatalf("Times of TransactionManagerMock.ReadCommitted mock can not be zero")
+	}
+	mm_atomic.StoreUint64(&mmReadCommitted.expectedInvocations, n)
+	return mmReadCommitted
+}
+
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) invocationsDone() bool {
+	if len(mmReadCommitted.expectations) == 0 && mmReadCommitted.defaultExpectation == nil && mmReadCommitted.mock.funcReadCommitted == nil {
+		return true
+	}
+
+	totalInvocations := mm_atomic.LoadUint64(&mmReadCommitted.mock.afterReadCommittedCounter)
+	expectedInvocations := mm_atomic.LoadUint64(&mmReadCommitted.expectedInvocations)
+
+	return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
+}
+
+// ReadCommitted implements image.TransactionManager
+func (mmReadCommitted *TransactionManagerMock) ReadCommitted(ctx context.Context, f1 func(ctx context.Context) error) (err error) {
+	mm_atomic.AddUint64(&mmReadCommitted.beforeReadCommittedCounter, 1)
+	defer mm_atomic.AddUint64(&mmReadCommitted.afterReadCommittedCounter, 1)
+
+	if mmReadCommitted.inspectFuncReadCommitted != nil {
+		mmReadCommitted.inspectFuncReadCommitted(ctx, f1)
+	}
+
+	mm_params := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+	// Record call args
+	mmReadCommitted.ReadCommittedMock.mutex.Lock()
+	mmReadCommitted.ReadCommittedMock.callArgs = append(mmReadCommitted.ReadCommittedMock.callArgs, &mm_params)
+	mmReadCommitted.ReadCommittedMock.mutex.Unlock()
+
+	for _, e := range mmReadCommitted.ReadCommittedMock.expectations {
+		if minimock.Equal(*e.params, mm_params) {
+			mm_atomic.AddUint64(&e.Counter, 1)
+			return e.results.err
+		}
+	}
+
+	if mmReadCommitted.ReadCommittedMock.defaultExpectation != nil {
+		mm_atomic.AddUint64(&mmReadCommitted.ReadCommittedMock.defaultExpectation.Counter, 1)
+		mm_want := mmReadCommitted.ReadCommittedMock.defaultExpectation.params
+		mm_want_ptrs := mmReadCommitted.ReadCommittedMock.defaultExpectation.paramPtrs
+
+		mm_got := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+		if mm_want_ptrs != nil {
+
+			if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
+			}
+
+			if mm_want_ptrs.f1 != nil && !minimock.Equal(*mm_want_ptrs.f1, mm_got.f1) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter f1, want: %#v, got: %#v%s\n", *mm_want_ptrs.f1, mm_got.f1, minimock.Diff(*mm_want_ptrs.f1, mm_got.f1))
+			}
+
+		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
+			mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
+		}
+
+		mm_results := mmReadCommitted.ReadCommittedMock.defaultExpectation.results
+		if mm_results == nil {
+			mmReadCommitted.t.Fatal("No results are set for the TransactionManagerMock.ReadCommitted")
+		}
+		return (*mm_results).err
+	}
+	if mmReadCommitted.funcReadCommitted != nil {
+		return mmReadCommitted.funcReadCommitted(ctx, f1)
+	}
+	mmReadCommitted.t.Fatalf("Unexpected call to TransactionManagerMock.ReadCommitted. %v %v", ctx, f1)
+	return
+}
+
+// ReadCommittedAfterCounter returns a count of finished TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedAfterCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.afterReadCommittedCounter)
+}
+
+// ReadCommittedBeforeCounter returns a count of TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedBeforeCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.beforeReadCommittedCounter)
+}
+
+// Calls returns a list of arguments used in each call to TransactionManagerMock.ReadCommitted.
+// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Calls() []*TransactionManagerMockReadCommittedParams {
+	mmReadCommitted.mutex.RLock()
+
+	argCopy := make([]*TransactionManagerMockReadCommittedParams, len(mmReadCommitted.callArgs))
+	copy(argCopy, mmReadCommitted.callArgs)
+
+	mmReadCommitted.mutex.RUnlock()
+
+	return argCopy
+}
+
+// MinimockReadCommittedDone returns true if the count of the ReadCommitted invocations corresponds
+// the number of defined expectations
+func (m *TransactionManagerMock) MinimockReadCommittedDone() bool {
+	if m.ReadCommittedMock.optional {
+		// Optional methods provide '0 or more' call count restriction.
+		return true
+	}
+
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			return false
+		}
+	}
+
+	return m.ReadCommittedMock.invocationsDone()
+}
+
+// MinimockReadCommittedInspect logs each unmet expectation
+func (m *TransactionManagerMock) MinimockReadCommittedInspect() {
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *e.params)
+		}
+	}
+
+	afterReadCommittedCounter := mm_atomic.LoadUint64(&m.afterReadCommittedCounter)
+	// if default expectation was set then invocations count should be greater than zero
+	if m.ReadCommittedMock.defaultExpectation != nil && afterReadCommittedCounter < 1 {
+		if m.ReadCommittedMock.defaultExpectation.params == nil {
+			m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+		} else {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *m.ReadCommittedMock.defaultExpectation.params)
+		}
+	}
+	// if func was set then invocations count should be greater than zero
+	if m.funcReadCommitted != nil && afterReadCommittedCounter < 1 {
+		m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+	}
+
+	if !m.ReadCommittedMock.invocationsDone() && afterReadCommittedCounter > 0 {
+		m.t.Errorf("Expected %d calls to TransactionManagerMock.ReadCommitted but found %d calls",
+			mm_atomic.LoadUint64(&m.ReadCommittedMock.expectedInvocations), afterReadCommittedCounter)
+	}
+}
+
+// MinimockFinish checks that all mocked methods have been called the expected number of times
+func (m *TransactionManagerMock) MinimockFinish() {
+	m.finishOnce.Do(func() {
+		if !m.minimockDone() {
+			m.MinimockReadCommittedInspect()
+		}
+	})
+}
+
+// MinimockWait waits for all mocked methods to be called the expected number of times
+func (m *TransactionManagerMock) MinimockWait(timeout mm_time.Duration) {
+	timeoutCh := mm_time.After(timeout)
+	for {
+		if m.minimockDone() {
+			return
+		}
+		select {
+		case <-timeoutCh:
+			m.MinimockFinish()
+			return
+		case <-mm_time.After(10 * mm_time.Millisecond):
+		}
+	}
+}
+
+func (m *TransactionManagerMock) minimockDone() bool {
+	done := true
+	return done &&
+		m.MinimockReadCommittedDone()
+}

+ 14 - 8
internal/api/v1/notification/add_thing_notification.go

@@ -6,14 +6,14 @@ package notification
 
 import (
 	"context"
-	"database/sql"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/repositories"
@@ -21,10 +21,10 @@ import (
 
 type (
 	ThingNotificationRepository interface {
-		Add(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) error
-		Update(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) error
-		Delete(ctx context.Context, thingID int, tx *sql.Tx) error
-		Get(ctx context.Context, thingID int) (*models.ThingNotification, error)
+		Add(ctx context.Context, req models.AddThingNotificationRequest) error
+		Update(ctx context.Context, req models.UpdateThingNotificationRequest) error
+		Delete(ctx context.Context, id uint64) error
+		Get(ctx context.Context, id uint64) (*models.ThingNotification, error)
 		GetExpired(ctx context.Context) ([]models.ExtThingNotification, error)
 	}
 )
@@ -47,33 +47,39 @@ func AddThingNotificationHandler(
 
 		req := dto.AddThingNotificationRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
 		dbReq, err := mappers.ToAddThingNotificationRequest(req)
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		if err = thingNotificationRepository.Add(ctx, *dbReq, nil); err != nil {
+		if err = thingNotificationRepository.Add(ctx, *dbReq); err != nil {
 			if repositories.IsFKViolationError(err) || repositories.IsDuplicateKeyError(err) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := thingNotificationRepository.Get(ctx, req.ThingID)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingNotificationResponse(*res))
 	}

+ 12 - 15
internal/api/v1/notification/add_thing_notification_test.go

@@ -2,8 +2,6 @@ package notification
 
 import (
 	"context"
-	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 	"time"
@@ -14,10 +12,9 @@ import (
 	"github.com/lib/pq"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/notification/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/repositories"
 )
@@ -33,9 +30,9 @@ func TestAddThingNotificationHandler(t *testing.T) {
 	}
 
 	var (
-		thingID          = gofakeit.Number(1, 1000)
+		thingID          = uint64(gofakeit.Number(1, 1000))
 		notificationDate = gofakeit.Date().Truncate(time.Second)
-		testError        = errors.New(gofakeit.Phrase())
+		testError        = gofakeit.Error()
 		layout           = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -78,12 +75,12 @@ func TestAddThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoRes, nil)
 
@@ -139,7 +136,7 @@ func TestAddThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(testError)
@@ -154,7 +151,7 @@ func TestAddThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(&pq.Error{Code: repositories.DuplicateKeyErrorCode})
@@ -169,12 +166,12 @@ func TestAddThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -191,13 +188,13 @@ func TestAddThingNotificationHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Post("/v1/things/notifications", AddThingNotificationHandler(tt.repoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 2
internal/api/v1/notification/delete_thing_notification.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 )
 
 // @Router 		/api/v1/things/notifications/{thingId} [delete]
@@ -24,21 +26,25 @@ func DeleteThingNotificationHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		_, err = thingNotificationRepository.Get(ctx, id)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		if err = thingNotificationRepository.Delete(ctx, id, nil); err != nil {
+		if err = thingNotificationRepository.Delete(ctx, id); err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 13 - 15
internal/api/v1/notification/delete_thing_notification_test.go

@@ -3,7 +3,6 @@ package notification
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -14,9 +13,8 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/notification/mocks"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,17 +28,17 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 
 		correctReq = req{
 			method:      fiber.MethodDelete,
-			route:       "/v1/things/notifications/" + strconv.Itoa(thingID),
+			route:       "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 			contentType: fiber.MIMEApplicationJSON,
 		}
 
 		repoRes = models.ThingNotification{
-			ThingID:          thingID,
+			ThingID:          uint64(thingID),
 			NotificationDate: gofakeit.Date().Truncate(time.Second),
 			CreatedAt:        gofakeit.Date(),
 			UpdatedAt:        gofakeit.Date(),
@@ -61,11 +59,11 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -91,7 +89,7 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -105,7 +103,7 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -119,11 +117,11 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(testError)
 
@@ -142,11 +140,11 @@ func Test_DeleteThingNotificationHandler(t *testing.T) {
 
 			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, nil)
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 3
internal/api/v1/notification/get_expired_thing_notifications.go

@@ -1,9 +1,10 @@
 package notification
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -20,12 +21,14 @@ func GetExpiredThingNotificationsHandler(
 	thingNotificationRepository ThingNotificationRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
-		res, err := thingNotificationRepository.GetExpired(fctx.Context())
+		ctx := fctx.Context()
+		res, err := thingNotificationRepository.GetExpired(ctx)
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingNotificationsExtResponse(res))
 	}

+ 9 - 8
internal/api/v1/notification/get_expired_thing_notifications_test.go

@@ -1,7 +1,6 @@
 package notification
 
 import (
-	"errors"
 	"net/http/httptest"
 	"testing"
 	"time"
@@ -11,10 +10,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/notification/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -27,7 +25,7 @@ func TestGetExpiredThingNotificationsHandler(t *testing.T) {
 	}
 
 	var (
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -37,8 +35,8 @@ func TestGetExpiredThingNotificationsHandler(t *testing.T) {
 
 		repoRes = []models.ExtThingNotification{
 			{
-				ThingID:          gofakeit.Number(1, 1000),
-				PlaceID:          gofakeit.Number(1, 1000),
+				ThingID:          uint64(gofakeit.Number(1, 1000)),
+				PlaceID:          uint64(gofakeit.Number(1, 1000)),
 				ThingTitle:       gofakeit.Phrase(),
 				PlaceTitle:       gofakeit.Phrase(),
 				NotificationDate: gofakeit.Date().Truncate(time.Second),
@@ -100,10 +98,13 @@ func TestGetExpiredThingNotificationsHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/things/notifications/expired", GetExpiredThingNotificationsHandler(tt.repoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 3
internal/api/v1/notification/get_thing_notification.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -26,21 +28,24 @@ func GetThingNotificationHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := thingNotificationRepository.Get(ctx, id)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusNotFound, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingNotificationResponse(*res))
 	}

+ 12 - 11
internal/api/v1/notification/get_thing_notification_test.go

@@ -3,7 +3,6 @@ package notification
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -14,10 +13,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/notification/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,13 +28,13 @@ func TestGetThingNotificationHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/things/notifications/" + strconv.Itoa(thingID),
+			route:  "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 		}
 
 		repoRes = models.ThingNotification{
@@ -69,7 +67,7 @@ func TestGetThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoRes, nil)
 
@@ -83,7 +81,7 @@ func TestGetThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -97,7 +95,7 @@ func TestGetThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -125,10 +123,13 @@ func TestGetThingNotificationHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/things/notifications/:thingId", GetThingNotificationHandler(tt.repoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 75 - 160
internal/api/v1/notification/mocks/thing_notification_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,20 +19,20 @@ type ThingNotificationRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcAdd          func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) (err error)
-	inspectFuncAdd   func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx)
+	funcAdd          func(ctx context.Context, req models.AddThingNotificationRequest) (err error)
+	inspectFuncAdd   func(ctx context.Context, req models.AddThingNotificationRequest)
 	afterAddCounter  uint64
 	beforeAddCounter uint64
 	AddMock          mThingNotificationRepositoryMockAdd
 
-	funcDelete          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingNotificationRepositoryMockDelete
 
-	funcGet          func(ctx context.Context, thingID int) (tp1 *models.ThingNotification, err error)
-	inspectFuncGet   func(ctx context.Context, thingID int)
+	funcGet          func(ctx context.Context, id uint64) (tp1 *models.ThingNotification, err error)
+	inspectFuncGet   func(ctx context.Context, id uint64)
 	afterGetCounter  uint64
 	beforeGetCounter uint64
 	GetMock          mThingNotificationRepositoryMockGet
@@ -44,8 +43,8 @@ type ThingNotificationRepositoryMock struct {
 	beforeGetExpiredCounter uint64
 	GetExpiredMock          mThingNotificationRepositoryMockGetExpired
 
-	funcUpdate          func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) (err error)
-	inspectFuncUpdate   func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx)
+	funcUpdate          func(ctx context.Context, req models.UpdateThingNotificationRequest) (err error)
+	inspectFuncUpdate   func(ctx context.Context, req models.UpdateThingNotificationRequest)
 	afterUpdateCounter  uint64
 	beforeUpdateCounter uint64
 	UpdateMock          mThingNotificationRepositoryMockUpdate
@@ -104,14 +103,12 @@ type ThingNotificationRepositoryMockAddExpectation struct {
 type ThingNotificationRepositoryMockAddParams struct {
 	ctx context.Context
 	req models.AddThingNotificationRequest
-	tx  *sql.Tx
 }
 
 // ThingNotificationRepositoryMockAddParamPtrs contains pointers to parameters of the ThingNotificationRepository.Add
 type ThingNotificationRepositoryMockAddParamPtrs struct {
 	ctx *context.Context
 	req *models.AddThingNotificationRequest
-	tx  **sql.Tx
 }
 
 // ThingNotificationRepositoryMockAddResults contains results of the ThingNotificationRepository.Add
@@ -130,7 +127,7 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) Optional() *mThingNotification
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Add
-func (mmAdd *mThingNotificationRepositoryMockAdd) Expect(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) *mThingNotificationRepositoryMockAdd {
+func (mmAdd *mThingNotificationRepositoryMockAdd) Expect(ctx context.Context, req models.AddThingNotificationRequest) *mThingNotificationRepositoryMockAdd {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("ThingNotificationRepositoryMock.Add mock is already set by Set")
 	}
@@ -143,7 +140,7 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) Expect(ctx context.Context, re
 		mmAdd.mock.t.Fatalf("ThingNotificationRepositoryMock.Add mock is already set by ExpectParams functions")
 	}
 
-	mmAdd.defaultExpectation.params = &ThingNotificationRepositoryMockAddParams{ctx, req, tx}
+	mmAdd.defaultExpectation.params = &ThingNotificationRepositoryMockAddParams{ctx, req}
 	for _, e := range mmAdd.expectations {
 		if minimock.Equal(e.params, mmAdd.defaultExpectation.params) {
 			mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params)
@@ -197,30 +194,8 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) ExpectReqParam2(req models.Add
 	return mmAdd
 }
 
-// ExpectTxParam3 sets up expected param tx for ThingNotificationRepository.Add
-func (mmAdd *mThingNotificationRepositoryMockAdd) ExpectTxParam3(tx *sql.Tx) *mThingNotificationRepositoryMockAdd {
-	if mmAdd.mock.funcAdd != nil {
-		mmAdd.mock.t.Fatalf("ThingNotificationRepositoryMock.Add mock is already set by Set")
-	}
-
-	if mmAdd.defaultExpectation == nil {
-		mmAdd.defaultExpectation = &ThingNotificationRepositoryMockAddExpectation{}
-	}
-
-	if mmAdd.defaultExpectation.params != nil {
-		mmAdd.mock.t.Fatalf("ThingNotificationRepositoryMock.Add mock is already set by Expect")
-	}
-
-	if mmAdd.defaultExpectation.paramPtrs == nil {
-		mmAdd.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockAddParamPtrs{}
-	}
-	mmAdd.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmAdd
-}
-
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Add
-func (mmAdd *mThingNotificationRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx)) *mThingNotificationRepositoryMockAdd {
+func (mmAdd *mThingNotificationRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddThingNotificationRequest)) *mThingNotificationRepositoryMockAdd {
 	if mmAdd.mock.inspectFuncAdd != nil {
 		mmAdd.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Add")
 	}
@@ -244,7 +219,7 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) Return(err error) *ThingNotifi
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Add method
-func (mmAdd *mThingNotificationRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) (err error)) *ThingNotificationRepositoryMock {
+func (mmAdd *mThingNotificationRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddThingNotificationRequest) (err error)) *ThingNotificationRepositoryMock {
 	if mmAdd.defaultExpectation != nil {
 		mmAdd.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Add method")
 	}
@@ -259,14 +234,14 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) Set(f func(ctx context.Context
 
 // When sets expectation for the ThingNotificationRepository.Add which will trigger the result defined by the following
 // Then helper
-func (mmAdd *mThingNotificationRepositoryMockAdd) When(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) *ThingNotificationRepositoryMockAddExpectation {
+func (mmAdd *mThingNotificationRepositoryMockAdd) When(ctx context.Context, req models.AddThingNotificationRequest) *ThingNotificationRepositoryMockAddExpectation {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("ThingNotificationRepositoryMock.Add mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockAddExpectation{
 		mock:   mmAdd.mock,
-		params: &ThingNotificationRepositoryMockAddParams{ctx, req, tx},
+		params: &ThingNotificationRepositoryMockAddParams{ctx, req},
 	}
 	mmAdd.expectations = append(mmAdd.expectations, expectation)
 	return expectation
@@ -299,15 +274,15 @@ func (mmAdd *mThingNotificationRepositoryMockAdd) invocationsDone() bool {
 }
 
 // Add implements notification.ThingNotificationRepository
-func (mmAdd *ThingNotificationRepositoryMock) Add(ctx context.Context, req models.AddThingNotificationRequest, tx *sql.Tx) (err error) {
+func (mmAdd *ThingNotificationRepositoryMock) Add(ctx context.Context, req models.AddThingNotificationRequest) (err error) {
 	mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1)
 	defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1)
 
 	if mmAdd.inspectFuncAdd != nil {
-		mmAdd.inspectFuncAdd(ctx, req, tx)
+		mmAdd.inspectFuncAdd(ctx, req)
 	}
 
-	mm_params := ThingNotificationRepositoryMockAddParams{ctx, req, tx}
+	mm_params := ThingNotificationRepositoryMockAddParams{ctx, req}
 
 	// Record call args
 	mmAdd.AddMock.mutex.Lock()
@@ -326,7 +301,7 @@ func (mmAdd *ThingNotificationRepositoryMock) Add(ctx context.Context, req model
 		mm_want := mmAdd.AddMock.defaultExpectation.params
 		mm_want_ptrs := mmAdd.AddMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockAddParams{ctx, req, tx}
+		mm_got := ThingNotificationRepositoryMockAddParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -338,10 +313,6 @@ func (mmAdd *ThingNotificationRepositoryMock) Add(ctx context.Context, req model
 				mmAdd.t.Errorf("ThingNotificationRepositoryMock.Add got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmAdd.t.Errorf("ThingNotificationRepositoryMock.Add got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmAdd.t.Errorf("ThingNotificationRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -353,9 +324,9 @@ func (mmAdd *ThingNotificationRepositoryMock) Add(ctx context.Context, req model
 		return (*mm_results).err
 	}
 	if mmAdd.funcAdd != nil {
-		return mmAdd.funcAdd(ctx, req, tx)
+		return mmAdd.funcAdd(ctx, req)
 	}
-	mmAdd.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Add. %v %v %v", ctx, req, tx)
+	mmAdd.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Add. %v %v", ctx, req)
 	return
 }
 
@@ -450,16 +421,14 @@ type ThingNotificationRepositoryMockDeleteExpectation struct {
 
 // ThingNotificationRepositoryMockDeleteParams contains parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingNotificationRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingNotificationRepositoryMockDeleteResults contains results of the ThingNotificationRepository.Delete
@@ -478,7 +447,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Optional() *mThingNotifi
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -491,7 +460,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Conte
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -523,8 +492,8 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectCtxParam1(ctx cont
 	return mmDelete
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thingID int) *mThingNotificationRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingNotificationRepository.Delete
+func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -540,35 +509,13 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thin
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Delete")
 	}
@@ -592,7 +539,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Return(err error) *Thing
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Delete method
-func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingNotificationRepositoryMock {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingNotificationRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Delete method")
 	}
@@ -607,14 +554,14 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.C
 
 // When sets expectation for the ThingNotificationRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingNotificationRepositoryMockDeleteExpectation {
+func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingNotificationRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx},
+		params: &ThingNotificationRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -647,15 +594,15 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements notification.ThingNotificationRepository
-func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, thingID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -674,7 +621,7 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -682,12 +629,8 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -701,9 +644,9 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, thingID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v %v", ctx, thingID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 
@@ -798,14 +741,14 @@ type ThingNotificationRepositoryMockGetExpectation struct {
 
 // ThingNotificationRepositoryMockGetParams contains parameters of the ThingNotificationRepository.Get
 type ThingNotificationRepositoryMockGetParams struct {
-	ctx     context.Context
-	thingID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingNotificationRepositoryMockGetParamPtrs contains pointers to parameters of the ThingNotificationRepository.Get
 type ThingNotificationRepositoryMockGetParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingNotificationRepositoryMockGetResults contains results of the ThingNotificationRepository.Get
@@ -825,7 +768,7 @@ func (mmGet *mThingNotificationRepositoryMockGet) Optional() *mThingNotification
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Get
-func (mmGet *mThingNotificationRepositoryMockGet) Expect(ctx context.Context, thingID int) *mThingNotificationRepositoryMockGet {
+func (mmGet *mThingNotificationRepositoryMockGet) Expect(ctx context.Context, id uint64) *mThingNotificationRepositoryMockGet {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingNotificationRepositoryMock.Get mock is already set by Set")
 	}
@@ -838,7 +781,7 @@ func (mmGet *mThingNotificationRepositoryMockGet) Expect(ctx context.Context, th
 		mmGet.mock.t.Fatalf("ThingNotificationRepositoryMock.Get mock is already set by ExpectParams functions")
 	}
 
-	mmGet.defaultExpectation.params = &ThingNotificationRepositoryMockGetParams{ctx, thingID}
+	mmGet.defaultExpectation.params = &ThingNotificationRepositoryMockGetParams{ctx, id}
 	for _, e := range mmGet.expectations {
 		if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
 			mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
@@ -870,8 +813,8 @@ func (mmGet *mThingNotificationRepositoryMockGet) ExpectCtxParam1(ctx context.Co
 	return mmGet
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingNotificationRepository.Get
-func (mmGet *mThingNotificationRepositoryMockGet) ExpectThingIDParam2(thingID int) *mThingNotificationRepositoryMockGet {
+// ExpectIdParam2 sets up expected param id for ThingNotificationRepository.Get
+func (mmGet *mThingNotificationRepositoryMockGet) ExpectIdParam2(id uint64) *mThingNotificationRepositoryMockGet {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingNotificationRepositoryMock.Get mock is already set by Set")
 	}
@@ -887,13 +830,13 @@ func (mmGet *mThingNotificationRepositoryMockGet) ExpectThingIDParam2(thingID in
 	if mmGet.defaultExpectation.paramPtrs == nil {
 		mmGet.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockGetParamPtrs{}
 	}
-	mmGet.defaultExpectation.paramPtrs.thingID = &thingID
+	mmGet.defaultExpectation.paramPtrs.id = &id
 
 	return mmGet
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Get
-func (mmGet *mThingNotificationRepositoryMockGet) Inspect(f func(ctx context.Context, thingID int)) *mThingNotificationRepositoryMockGet {
+func (mmGet *mThingNotificationRepositoryMockGet) Inspect(f func(ctx context.Context, id uint64)) *mThingNotificationRepositoryMockGet {
 	if mmGet.mock.inspectFuncGet != nil {
 		mmGet.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Get")
 	}
@@ -917,7 +860,7 @@ func (mmGet *mThingNotificationRepositoryMockGet) Return(tp1 *models.ThingNotifi
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Get method
-func (mmGet *mThingNotificationRepositoryMockGet) Set(f func(ctx context.Context, thingID int) (tp1 *models.ThingNotification, err error)) *ThingNotificationRepositoryMock {
+func (mmGet *mThingNotificationRepositoryMockGet) Set(f func(ctx context.Context, id uint64) (tp1 *models.ThingNotification, err error)) *ThingNotificationRepositoryMock {
 	if mmGet.defaultExpectation != nil {
 		mmGet.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Get method")
 	}
@@ -932,14 +875,14 @@ func (mmGet *mThingNotificationRepositoryMockGet) Set(f func(ctx context.Context
 
 // When sets expectation for the ThingNotificationRepository.Get which will trigger the result defined by the following
 // Then helper
-func (mmGet *mThingNotificationRepositoryMockGet) When(ctx context.Context, thingID int) *ThingNotificationRepositoryMockGetExpectation {
+func (mmGet *mThingNotificationRepositoryMockGet) When(ctx context.Context, id uint64) *ThingNotificationRepositoryMockGetExpectation {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingNotificationRepositoryMock.Get mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockGetExpectation{
 		mock:   mmGet.mock,
-		params: &ThingNotificationRepositoryMockGetParams{ctx, thingID},
+		params: &ThingNotificationRepositoryMockGetParams{ctx, id},
 	}
 	mmGet.expectations = append(mmGet.expectations, expectation)
 	return expectation
@@ -972,15 +915,15 @@ func (mmGet *mThingNotificationRepositoryMockGet) invocationsDone() bool {
 }
 
 // Get implements notification.ThingNotificationRepository
-func (mmGet *ThingNotificationRepositoryMock) Get(ctx context.Context, thingID int) (tp1 *models.ThingNotification, err error) {
+func (mmGet *ThingNotificationRepositoryMock) Get(ctx context.Context, id uint64) (tp1 *models.ThingNotification, err error) {
 	mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
 	defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
 
 	if mmGet.inspectFuncGet != nil {
-		mmGet.inspectFuncGet(ctx, thingID)
+		mmGet.inspectFuncGet(ctx, id)
 	}
 
-	mm_params := ThingNotificationRepositoryMockGetParams{ctx, thingID}
+	mm_params := ThingNotificationRepositoryMockGetParams{ctx, id}
 
 	// Record call args
 	mmGet.GetMock.mutex.Lock()
@@ -999,7 +942,7 @@ func (mmGet *ThingNotificationRepositoryMock) Get(ctx context.Context, thingID i
 		mm_want := mmGet.GetMock.defaultExpectation.params
 		mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockGetParams{ctx, thingID}
+		mm_got := ThingNotificationRepositoryMockGetParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -1007,8 +950,8 @@ func (mmGet *ThingNotificationRepositoryMock) Get(ctx context.Context, thingID i
 				mmGet.t.Errorf("ThingNotificationRepositoryMock.Get got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmGet.t.Errorf("ThingNotificationRepositoryMock.Get got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGet.t.Errorf("ThingNotificationRepositoryMock.Get got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -1022,9 +965,9 @@ func (mmGet *ThingNotificationRepositoryMock) Get(ctx context.Context, thingID i
 		return (*mm_results).tp1, (*mm_results).err
 	}
 	if mmGet.funcGet != nil {
-		return mmGet.funcGet(ctx, thingID)
+		return mmGet.funcGet(ctx, id)
 	}
-	mmGet.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Get. %v %v", ctx, thingID)
+	mmGet.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Get. %v %v", ctx, id)
 	return
 }
 
@@ -1414,14 +1357,12 @@ type ThingNotificationRepositoryMockUpdateExpectation struct {
 type ThingNotificationRepositoryMockUpdateParams struct {
 	ctx context.Context
 	req models.UpdateThingNotificationRequest
-	tx  *sql.Tx
 }
 
 // ThingNotificationRepositoryMockUpdateParamPtrs contains pointers to parameters of the ThingNotificationRepository.Update
 type ThingNotificationRepositoryMockUpdateParamPtrs struct {
 	ctx *context.Context
 	req *models.UpdateThingNotificationRequest
-	tx  **sql.Tx
 }
 
 // ThingNotificationRepositoryMockUpdateResults contains results of the ThingNotificationRepository.Update
@@ -1440,7 +1381,7 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) Optional() *mThingNotifi
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Update
-func (mmUpdate *mThingNotificationRepositoryMockUpdate) Expect(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) *mThingNotificationRepositoryMockUpdate {
+func (mmUpdate *mThingNotificationRepositoryMockUpdate) Expect(ctx context.Context, req models.UpdateThingNotificationRequest) *mThingNotificationRepositoryMockUpdate {
 	if mmUpdate.mock.funcUpdate != nil {
 		mmUpdate.mock.t.Fatalf("ThingNotificationRepositoryMock.Update mock is already set by Set")
 	}
@@ -1453,7 +1394,7 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) Expect(ctx context.Conte
 		mmUpdate.mock.t.Fatalf("ThingNotificationRepositoryMock.Update mock is already set by ExpectParams functions")
 	}
 
-	mmUpdate.defaultExpectation.params = &ThingNotificationRepositoryMockUpdateParams{ctx, req, tx}
+	mmUpdate.defaultExpectation.params = &ThingNotificationRepositoryMockUpdateParams{ctx, req}
 	for _, e := range mmUpdate.expectations {
 		if minimock.Equal(e.params, mmUpdate.defaultExpectation.params) {
 			mmUpdate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdate.defaultExpectation.params)
@@ -1507,30 +1448,8 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) ExpectReqParam2(req mode
 	return mmUpdate
 }
 
-// ExpectTxParam3 sets up expected param tx for ThingNotificationRepository.Update
-func (mmUpdate *mThingNotificationRepositoryMockUpdate) ExpectTxParam3(tx *sql.Tx) *mThingNotificationRepositoryMockUpdate {
-	if mmUpdate.mock.funcUpdate != nil {
-		mmUpdate.mock.t.Fatalf("ThingNotificationRepositoryMock.Update mock is already set by Set")
-	}
-
-	if mmUpdate.defaultExpectation == nil {
-		mmUpdate.defaultExpectation = &ThingNotificationRepositoryMockUpdateExpectation{}
-	}
-
-	if mmUpdate.defaultExpectation.params != nil {
-		mmUpdate.mock.t.Fatalf("ThingNotificationRepositoryMock.Update mock is already set by Expect")
-	}
-
-	if mmUpdate.defaultExpectation.paramPtrs == nil {
-		mmUpdate.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockUpdateParamPtrs{}
-	}
-	mmUpdate.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmUpdate
-}
-
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Update
-func (mmUpdate *mThingNotificationRepositoryMockUpdate) Inspect(f func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx)) *mThingNotificationRepositoryMockUpdate {
+func (mmUpdate *mThingNotificationRepositoryMockUpdate) Inspect(f func(ctx context.Context, req models.UpdateThingNotificationRequest)) *mThingNotificationRepositoryMockUpdate {
 	if mmUpdate.mock.inspectFuncUpdate != nil {
 		mmUpdate.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Update")
 	}
@@ -1554,7 +1473,7 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) Return(err error) *Thing
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Update method
-func (mmUpdate *mThingNotificationRepositoryMockUpdate) Set(f func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) (err error)) *ThingNotificationRepositoryMock {
+func (mmUpdate *mThingNotificationRepositoryMockUpdate) Set(f func(ctx context.Context, req models.UpdateThingNotificationRequest) (err error)) *ThingNotificationRepositoryMock {
 	if mmUpdate.defaultExpectation != nil {
 		mmUpdate.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Update method")
 	}
@@ -1569,14 +1488,14 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) Set(f func(ctx context.C
 
 // When sets expectation for the ThingNotificationRepository.Update which will trigger the result defined by the following
 // Then helper
-func (mmUpdate *mThingNotificationRepositoryMockUpdate) When(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) *ThingNotificationRepositoryMockUpdateExpectation {
+func (mmUpdate *mThingNotificationRepositoryMockUpdate) When(ctx context.Context, req models.UpdateThingNotificationRequest) *ThingNotificationRepositoryMockUpdateExpectation {
 	if mmUpdate.mock.funcUpdate != nil {
 		mmUpdate.mock.t.Fatalf("ThingNotificationRepositoryMock.Update mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockUpdateExpectation{
 		mock:   mmUpdate.mock,
-		params: &ThingNotificationRepositoryMockUpdateParams{ctx, req, tx},
+		params: &ThingNotificationRepositoryMockUpdateParams{ctx, req},
 	}
 	mmUpdate.expectations = append(mmUpdate.expectations, expectation)
 	return expectation
@@ -1609,15 +1528,15 @@ func (mmUpdate *mThingNotificationRepositoryMockUpdate) invocationsDone() bool {
 }
 
 // Update implements notification.ThingNotificationRepository
-func (mmUpdate *ThingNotificationRepositoryMock) Update(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) (err error) {
+func (mmUpdate *ThingNotificationRepositoryMock) Update(ctx context.Context, req models.UpdateThingNotificationRequest) (err error) {
 	mm_atomic.AddUint64(&mmUpdate.beforeUpdateCounter, 1)
 	defer mm_atomic.AddUint64(&mmUpdate.afterUpdateCounter, 1)
 
 	if mmUpdate.inspectFuncUpdate != nil {
-		mmUpdate.inspectFuncUpdate(ctx, req, tx)
+		mmUpdate.inspectFuncUpdate(ctx, req)
 	}
 
-	mm_params := ThingNotificationRepositoryMockUpdateParams{ctx, req, tx}
+	mm_params := ThingNotificationRepositoryMockUpdateParams{ctx, req}
 
 	// Record call args
 	mmUpdate.UpdateMock.mutex.Lock()
@@ -1636,7 +1555,7 @@ func (mmUpdate *ThingNotificationRepositoryMock) Update(ctx context.Context, req
 		mm_want := mmUpdate.UpdateMock.defaultExpectation.params
 		mm_want_ptrs := mmUpdate.UpdateMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockUpdateParams{ctx, req, tx}
+		mm_got := ThingNotificationRepositoryMockUpdateParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -1648,10 +1567,6 @@ func (mmUpdate *ThingNotificationRepositoryMock) Update(ctx context.Context, req
 				mmUpdate.t.Errorf("ThingNotificationRepositoryMock.Update got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmUpdate.t.Errorf("ThingNotificationRepositoryMock.Update got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmUpdate.t.Errorf("ThingNotificationRepositoryMock.Update got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -1663,9 +1578,9 @@ func (mmUpdate *ThingNotificationRepositoryMock) Update(ctx context.Context, req
 		return (*mm_results).err
 	}
 	if mmUpdate.funcUpdate != nil {
-		return mmUpdate.funcUpdate(ctx, req, tx)
+		return mmUpdate.funcUpdate(ctx, req)
 	}
-	mmUpdate.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Update. %v %v %v", ctx, req, tx)
+	mmUpdate.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Update. %v %v", ctx, req)
 	return
 }
 

+ 16 - 5
internal/api/v1/notification/update_thing_notification.go

@@ -2,13 +2,16 @@ package notification
 
 import (
 	"database/sql"
+	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -28,45 +31,53 @@ func UpdateThingNotificationHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		req := dto.UpdateThingNotificationRequest{}
 		if err = fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err = validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
 		_, err = thingNotificationRepository.Get(ctx, id)
 		if err != nil {
-			if err == sql.ErrNoRows {
+			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		dbReq, err := mappers.ToUpdateThingNotificationRequest(id, req)
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		if err = thingNotificationRepository.Update(ctx, *dbReq, nil); err != nil {
+		if err = thingNotificationRepository.Update(ctx, *dbReq); err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := thingNotificationRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingNotificationResponse(*res))
 	}

+ 19 - 21
internal/api/v1/notification/update_thing_notification_test.go

@@ -3,7 +3,6 @@ package notification
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -14,10 +13,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/notification/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -32,14 +30,14 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 	}
 
 	var (
-		thingID          = gofakeit.Number(1, 1000)
+		thingID          = uint64(gofakeit.Number(1, 1000))
 		notificationDate = gofakeit.Date().Truncate(time.Second)
-		testError        = errors.New(gofakeit.Phrase())
+		testError        = gofakeit.Error()
 		layout           = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodPut,
-			route:  "/v1/things/notifications/" + strconv.Itoa(thingID),
+			route:  "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 			body: &dto.UpdateThingNotificationRequest{
 				NotificationDate: notificationDate.Format(time.RFC3339),
 			},
@@ -76,12 +74,12 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(nil)
 
-				mock.GetMock.Set(func(ctx context.Context, id int) (*models.ThingNotification, error) {
+				mock.GetMock.Set(func(ctx context.Context, id uint64) (*models.ThingNotification, error) {
 					assert.Equal(mc, thingID, id)
 					if mock.GetAfterCounter() == 0 {
 						return nil, nil
@@ -107,7 +105,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			name: "negative case - body parse error",
 			req: req{
 				method: fiber.MethodPut,
-				route:  "/v1/things/notifications/" + strconv.Itoa(thingID),
+				route:  "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 			},
 			resCode: fiber.StatusBadRequest,
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
@@ -118,7 +116,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			name: "negative case - validate request error",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/things/notifications/" + strconv.Itoa(thingID),
+				route:       "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
@@ -133,7 +131,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -147,7 +145,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -158,7 +156,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			name: "negative case - bad request (notification not found)",
 			req: req{
 				method: fiber.MethodPut,
-				route:  "/v1/things/notifications/" + strconv.Itoa(thingID),
+				route:  "/v1/things/notifications/" + strconv.FormatUint(thingID, 10),
 				body: &dto.UpdateThingNotificationRequest{
 					NotificationDate: notificationDate.String(),
 				},
@@ -168,7 +166,7 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
@@ -182,11 +180,11 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(testError)
@@ -201,12 +199,12 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			repoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingNotificationRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, notificationDate, req.NotificationDate)
 				}).Return(nil)
 
-				mock.GetMock.Set(func(ctx context.Context, id int) (*models.ThingNotification, error) {
+				mock.GetMock.Set(func(ctx context.Context, id uint64) (*models.ThingNotification, error) {
 					assert.Equal(mc, thingID, id)
 					if mock.GetAfterCounter() == 0 {
 						return nil, nil
@@ -227,13 +225,13 @@ func TestUpdateThingNotificationHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Put("/v1/things/notifications/:thingId", UpdateThingNotificationHandler(tt.repoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 27 - 21
internal/api/v1/place/add_place.go

@@ -2,59 +2,61 @@ package place
 
 //go:generate mkdir -p mocks
 //go:generate rm -rf ./mocks/*_minimock.go
-//go:generate minimock -i PlaceRepository,ThingRepository,PlaceImageRepository,ThingImageRepository,PlaceThingRepository,ThingTagRepository,ThingNotificationRepository,FileRepository -o ./mocks/ -s "_minimock.go"
+//go:generate minimock -i TransactionManager,PlaceRepository,ThingRepository,PlaceImageRepository,ThingImageRepository,PlaceThingRepository,ThingTagRepository,ThingNotificationRepository,FileRepository -o ./mocks/ -s "_minimock.go"
 
 import (
 	"context"
-	"database/sql"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
 type (
+	TransactionManager interface {
+		ReadCommitted(context.Context, func(ctx context.Context) error) error
+	}
+
 	PlaceRepository interface {
 		GetAll(ctx context.Context) ([]models.Place, error)
-		Get(ctx context.Context, placeID int) (*models.Place, error)
-		GetNestedPlaces(ctx context.Context, placeID int) ([]models.Place, error)
-		Add(ctx context.Context, req models.AddPlaceRequest, tx *sql.Tx) (int, error)
-		Update(ctx context.Context, req models.UpdatePlaceRequest, tx *sql.Tx) error
-		Delete(ctx context.Context, placeID int, tx *sql.Tx) error
-		BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
-		CommitTx(tx *sql.Tx) error
+		Get(ctx context.Context, id uint64) (*models.Place, error)
+		GetNestedPlaces(ctx context.Context, id uint64) ([]models.Place, error)
+		Add(ctx context.Context, req models.AddPlaceRequest) (uint64, error)
+		Update(ctx context.Context, req models.UpdatePlaceRequest) error
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	ThingRepository interface {
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.Thing, error)
-		Delete(ctx context.Context, thingID int, tx *sql.Tx) error
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.Thing, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	PlaceImageRepository interface {
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.Image, error)
-		Delete(ctx context.Context, imageID int, tx *sql.Tx) error
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.Image, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	ThingImageRepository interface {
-		GetByThingID(ctx context.Context, thingID int) ([]models.Image, error)
-		Delete(ctx context.Context, imageID int, tx *sql.Tx) error
+		GetByThingID(ctx context.Context, id uint64) ([]models.Image, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	PlaceThingRepository interface {
-		DeleteThing(ctx context.Context, thingID int, tx *sql.Tx) error
+		DeleteThing(ctx context.Context, id uint64) error
 	}
 
 	ThingTagRepository interface {
-		DeleteByThingID(ctx context.Context, thingID int, tx *sql.Tx) error
+		DeleteByThingID(ctx context.Context, id uint64) error
 	}
 
 	ThingNotificationRepository interface {
-		Delete(ctx context.Context, thingID int, tx *sql.Tx) error
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	FileRepository interface {
@@ -79,25 +81,29 @@ func AddPlaceHandler(
 		ctx := fctx.Context()
 		req := dto.AddPlaceRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		id, err := placeRepository.Add(ctx, mappers.ToAddPlaceRequest(req), nil)
+		id, err := placeRepository.Add(ctx, mappers.ToAddPlaceRequest(req))
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := placeRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlaceResponse(*res))
 	}

+ 15 - 17
internal/api/v1/place/add_place_test.go

@@ -3,7 +3,6 @@ package place
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,10 +28,10 @@ func TestAddPlaceHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		parentID  = gofakeit.Number(1, 1000)
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		parentID  = uint64(gofakeit.Number(1, 1000))
 		title     = gofakeit.Phrase()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -78,12 +76,12 @@ func TestAddPlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, int64(parentID), req.ParentID.Int64)
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(placeID, nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(&repoRes, nil)
 
@@ -127,9 +125,9 @@ func TestAddPlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, int64(parentID), req.ParentID.Int64)
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(0, testError)
 
 				return mock
@@ -142,12 +140,12 @@ func TestAddPlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, int64(parentID), req.ParentID.Int64)
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(placeID, nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -164,13 +162,13 @@ func TestAddPlaceHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Post("/v1/places", AddPlaceHandler(tt.placeRepoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 71 - 64
internal/api/v1/place/delete_place.go

@@ -1,12 +1,15 @@
 package place
 
 import (
+	"context"
 	"database/sql"
+	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -21,6 +24,7 @@ import (
 // @Accept      json
 // @Produce     json
 func DeletePlaceHandler(
+	tm TransactionManager,
 	placeRepository PlaceRepository,
 	thingRepository ThingRepository,
 	placeImageRepository PlaceImageRepository,
@@ -32,22 +36,26 @@ func DeletePlaceHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("placeId")
+		id, err := request.ConvertToUint64(fctx, "placeId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		_, err = placeRepository.Get(ctx, id)
 		if err != nil {
-			if err == sql.ErrNoRows {
+			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		nestedRes, err := placeRepository.GetNestedPlaces(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
@@ -55,88 +63,87 @@ func DeletePlaceHandler(
 			return fiber.NewError(fiber.StatusBadRequest, "")
 		}
 
-		placeImages, err := placeImageRepository.GetByPlaceID(ctx, id)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
-
-		things, err := thingRepository.GetByPlaceID(ctx, id)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
-
-		var thingImages []models.Image
-		thingIDs := make([]int, 0, len(things))
-
-		for _, thing := range things {
-			thingIDs = append(thingIDs, thing.ID)
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			placeImages, txErr := placeImageRepository.GetByPlaceID(ctx, id)
+			if txErr != nil {
+				return txErr
+			}
 
-			thingImagesRes, thingImagesErr := thingImageRepository.GetByThingID(ctx, thing.ID)
-			if thingImagesErr != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, thingImagesErr.Error())
+			things, txErr := thingRepository.GetByPlaceID(ctx, id)
+			if txErr != nil {
+				return txErr
 			}
 
-			thingImages = append(thingImages, thingImagesRes...)
-		}
+			var thingImages []models.Image
+			thingIDs := make([]uint64, 0, len(things))
 
-		tx, err := placeRepository.BeginTx(ctx, API.DefaultTxLevel)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			for _, thing := range things {
+				thingIDs = append(thingIDs, thing.ID)
 
-		placeImageURLs := make([]string, 0, len(placeImages))
-		for i := range placeImages {
-			placeImageURLs = append(placeImageURLs, placeImages[i].Image)
+				thingImagesRes, thingImagesErr := thingImageRepository.GetByThingID(ctx, thing.ID)
+				if thingImagesErr != nil {
+					return thingImagesErr
+				}
 
-			if err = placeImageRepository.Delete(ctx, placeImages[i].ID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+				thingImages = append(thingImages, thingImagesRes...)
 			}
-		}
 
-		for i := range thingImages {
-			if err = thingImageRepository.Delete(ctx, thingImages[i].ID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			placeImageURLs := make([]string, 0, len(placeImages))
+			for i := range placeImages {
+				placeImageURLs = append(placeImageURLs, placeImages[i].Image)
+				if txErr = placeImageRepository.Delete(ctx, placeImages[i].ID); txErr != nil {
+					return txErr
+				}
 			}
-		}
 
-		for _, thingID := range thingIDs {
-			if err = placeThingRepository.DeleteThing(ctx, thingID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			for i := range thingImages {
+				if txErr = thingImageRepository.Delete(ctx, thingImages[i].ID); txErr != nil {
+					return txErr
+				}
 			}
 
-			if err = thingTagRepository.DeleteByThingID(ctx, thingID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
+			for _, thingID := range thingIDs {
+				if txErr = placeThingRepository.DeleteThing(ctx, thingID); txErr != nil {
+					return txErr
+				}
 
-			if err = thingNotificationRepository.Delete(ctx, thingID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
+				if txErr = thingTagRepository.DeleteByThingID(ctx, thingID); txErr != nil {
+					return txErr
+				}
 
-			if err = thingRepository.Delete(ctx, thingID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-			}
-		}
+				if txErr = thingNotificationRepository.Delete(ctx, thingID); txErr != nil {
+					return txErr
+				}
 
-		if err = placeRepository.Delete(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+				if txErr = thingRepository.Delete(ctx, thingID); txErr != nil {
+					return txErr
+				}
+			}
 
-		if err = placeRepository.CommitTx(tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = placeRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if len(placeImageURLs) > 0 {
-			for i := range placeImageURLs {
-				if err = fileRepository.Delete(placeImageURLs[i]); err != nil {
-					return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			if len(placeImageURLs) > 0 {
+				for i := range placeImageURLs {
+					if txErr = fileRepository.Delete(placeImageURLs[i]); txErr != nil {
+						return txErr
+					}
 				}
 			}
-		}
 
-		for i := range thingImages {
-			if err = fileRepository.Delete(thingImages[i].Image); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			for i := range thingImages {
+				if txErr = fileRepository.Delete(thingImages[i].Image); txErr != nil {
+					return txErr
+				}
 			}
+
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
+			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		return fctx.JSON(factory.CreateEmptyResponse())

Різницю між файлами не показано, бо вона завелика
+ 248 - 254
internal/api/v1/place/delete_place_test.go


+ 8 - 3
internal/api/v1/place/get_place.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -24,21 +26,24 @@ import (
 func GetPlaceHandler(placeRepository PlaceRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("placeId")
+		id, err := request.ConvertToUint64(fctx, "placeId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := placeRepository.Get(ctx, id)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusNotFound, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlaceResponse(*res))
 	}

+ 7 - 3
internal/api/v1/place/get_place_nested.go

@@ -1,9 +1,11 @@
 package place
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -20,17 +22,19 @@ import (
 func GetNestedPlacesHandler(placeRepository PlaceRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("parentPlaceId")
+		id, err := request.ConvertToUint64(fctx, "parentPlaceId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := placeRepository.GetNestedPlaces(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlacesResponse(res))
 	}

+ 11 - 10
internal/api/v1/place/get_place_nested_test.go

@@ -3,7 +3,6 @@ package place
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,13 +27,13 @@ func TestGetNestedPlacesHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/places/" + strconv.Itoa(placeID) + "/nested",
+			route:  "/v1/places/" + strconv.FormatUint(placeID, 10) + "/nested",
 		}
 
 		repoRes = []models.Place{
@@ -76,7 +74,7 @@ func TestGetNestedPlacesHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(repoRes, nil)
 
@@ -90,7 +88,7 @@ func TestGetNestedPlacesHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -119,10 +117,13 @@ func TestGetNestedPlacesHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/places/:parentPlaceId/nested", GetNestedPlacesHandler(tt.placeRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 21 - 21
internal/api/v1/place/get_place_test.go

@@ -3,7 +3,6 @@ package place
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,28 +27,27 @@ func TestGetPlaceHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		parentID  = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/places/" + strconv.Itoa(placeID),
+			route:  "/v1/places/" + strconv.FormatUint(placeID, 10),
 		}
 
 		repoRes = models.Place{
 			ID:        placeID,
-			ParentID:  sql.NullInt64{Int64: int64(parentID), Valid: true},
+			ParentID:  sql.NullInt64{Int64: int64(placeID), Valid: true},
 			Title:     gofakeit.Phrase(),
 			CreatedAt: gofakeit.Date(),
 			UpdatedAt: gofakeit.Date(),
 		}
 
 		expectedRes = dto.PlaceResponse{
-			ID:        placeID,
+			ID:        repoRes.ID,
+			ParentID:  &placeID,
 			Title:     repoRes.Title,
-			ParentID:  &parentID,
 			CreatedAt: repoRes.CreatedAt.Format(layout),
 			UpdatedAt: repoRes.UpdatedAt.Format(layout),
 		}
@@ -71,7 +68,7 @@ func TestGetPlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(&repoRes, nil)
 
@@ -79,29 +76,29 @@ func TestGetPlaceHandler(t *testing.T) {
 			},
 		},
 		{
-			name:    "negative case - not found",
+			name:    "negative case - repository error",
 			req:     correctReq,
-			resCode: fiber.StatusNotFound,
+			resCode: fiber.StatusInternalServerError,
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
-				}).Return(nil, sql.ErrNoRows)
+				}).Return(nil, testError)
 
 				return mock
 			},
 		},
 		{
-			name:    "negative case - repository error",
+			name:    "negative case - not found",
 			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
+			resCode: fiber.StatusNotFound,
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
-				}).Return(nil, testError)
+				}).Return(nil, sql.ErrNoRows)
 
 				return mock
 			},
@@ -128,10 +125,13 @@ func TestGetPlaceHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/places/:placeId", GetPlaceHandler(tt.placeRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 3
internal/api/v1/place/get_place_tree.go

@@ -1,9 +1,10 @@
 package place
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -17,12 +18,14 @@ import (
 // @Produce     json
 func GetPlaceTreeHandler(placeRepository PlaceRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
-		res, err := placeRepository.GetAll(fctx.Context())
+		ctx := fctx.Context()
+		res, err := placeRepository.GetAll(ctx)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlaceTreeResponse(res))
 	}

+ 10 - 9
internal/api/v1/place/get_place_tree_test.go

@@ -2,7 +2,6 @@ package place
 
 import (
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -11,10 +10,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -27,12 +25,12 @@ func TestGetPlaceTreeHandler(t *testing.T) {
 	}
 
 	var (
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
-		id1 = gofakeit.Number(1, 1000)
-		id2 = gofakeit.Number(1, 1000)
-		id3 = gofakeit.Number(1, 1000)
+		id1 = uint64(gofakeit.Number(1, 1000))
+		id2 = uint64(gofakeit.Number(1, 1000))
+		id3 = uint64(gofakeit.Number(1, 1000))
 
 		correctReq = req{
 			method: fiber.MethodGet,
@@ -137,10 +135,13 @@ func TestGetPlaceTreeHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/places/tree", GetPlaceTreeHandler(tt.placeRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 3
internal/api/v1/place/get_places.go

@@ -1,9 +1,10 @@
 package place
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -17,12 +18,14 @@ import (
 // @Produce     json
 func GetPlacesHandler(placeRepository PlaceRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
-		res, err := placeRepository.GetAll(fctx.Context())
+		ctx := fctx.Context()
+		res, err := placeRepository.GetAll(ctx)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlacesResponse(res))
 	}

+ 10 - 9
internal/api/v1/place/get_places_test.go

@@ -2,7 +2,6 @@ package place
 
 import (
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -11,10 +10,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -27,12 +25,12 @@ func TestGetPlacesHandler(t *testing.T) {
 	}
 
 	var (
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
-		id1 = gofakeit.Number(1, 1000)
-		id2 = gofakeit.Number(1, 1000)
-		id3 = gofakeit.Number(1, 1000)
+		id1 = uint64(gofakeit.Number(1, 1000))
+		id2 = uint64(gofakeit.Number(1, 1000))
+		id3 = uint64(gofakeit.Number(1, 1000))
 
 		correctReq = req{
 			method: fiber.MethodGet,
@@ -127,10 +125,13 @@ func TestGetPlacesHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/places", GetPlacesHandler(tt.placeRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 1 - 1
internal/api/v1/place/mocks/file_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 

+ 47 - 76
internal/api/v1/place/mocks/place_image_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,14 +19,14 @@ type PlaceImageRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, imageID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, imageID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mPlaceImageRepositoryMockDelete
 
-	funcGetByPlaceID          func(ctx context.Context, placeID int) (ia1 []models.Image, err error)
-	inspectFuncGetByPlaceID   func(ctx context.Context, placeID int)
+	funcGetByPlaceID          func(ctx context.Context, id uint64) (ia1 []models.Image, err error)
+	inspectFuncGetByPlaceID   func(ctx context.Context, id uint64)
 	afterGetByPlaceIDCounter  uint64
 	beforeGetByPlaceIDCounter uint64
 	GetByPlaceIDMock          mPlaceImageRepositoryMockGetByPlaceID
@@ -75,16 +74,14 @@ type PlaceImageRepositoryMockDeleteExpectation struct {
 
 // PlaceImageRepositoryMockDeleteParams contains parameters of the PlaceImageRepository.Delete
 type PlaceImageRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	imageID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // PlaceImageRepositoryMockDeleteParamPtrs contains pointers to parameters of the PlaceImageRepository.Delete
 type PlaceImageRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	imageID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // PlaceImageRepositoryMockDeleteResults contains results of the PlaceImageRepository.Delete
@@ -103,7 +100,7 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) Optional() *mPlaceImageReposito
 }
 
 // Expect sets up expected params for PlaceImageRepository.Delete
-func (mmDelete *mPlaceImageRepositoryMockDelete) Expect(ctx context.Context, imageID int, tx *sql.Tx) *mPlaceImageRepositoryMockDelete {
+func (mmDelete *mPlaceImageRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mPlaceImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -116,7 +113,7 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) Expect(ctx context.Context, ima
 		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &PlaceImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mmDelete.defaultExpectation.params = &PlaceImageRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -148,8 +145,8 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) ExpectCtxParam1(ctx context.Con
 	return mmDelete
 }
 
-// ExpectImageIDParam2 sets up expected param imageID for PlaceImageRepository.Delete
-func (mmDelete *mPlaceImageRepositoryMockDelete) ExpectImageIDParam2(imageID int) *mPlaceImageRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for PlaceImageRepository.Delete
+func (mmDelete *mPlaceImageRepositoryMockDelete) ExpectIdParam2(id uint64) *mPlaceImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -165,35 +162,13 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) ExpectImageIDParam2(imageID int
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &PlaceImageRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.imageID = &imageID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for PlaceImageRepository.Delete
-func (mmDelete *mPlaceImageRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mPlaceImageRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &PlaceImageRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &PlaceImageRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the PlaceImageRepository.Delete
-func (mmDelete *mPlaceImageRepositoryMockDelete) Inspect(f func(ctx context.Context, imageID int, tx *sql.Tx)) *mPlaceImageRepositoryMockDelete {
+func (mmDelete *mPlaceImageRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mPlaceImageRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for PlaceImageRepositoryMock.Delete")
 	}
@@ -217,7 +192,7 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) Return(err error) *PlaceImageRe
 }
 
 // Set uses given function f to mock the PlaceImageRepository.Delete method
-func (mmDelete *mPlaceImageRepositoryMockDelete) Set(f func(ctx context.Context, imageID int, tx *sql.Tx) (err error)) *PlaceImageRepositoryMock {
+func (mmDelete *mPlaceImageRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *PlaceImageRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the PlaceImageRepository.Delete method")
 	}
@@ -232,14 +207,14 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) Set(f func(ctx context.Context,
 
 // When sets expectation for the PlaceImageRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mPlaceImageRepositoryMockDelete) When(ctx context.Context, imageID int, tx *sql.Tx) *PlaceImageRepositoryMockDeleteExpectation {
+func (mmDelete *mPlaceImageRepositoryMockDelete) When(ctx context.Context, id uint64) *PlaceImageRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("PlaceImageRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &PlaceImageRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &PlaceImageRepositoryMockDeleteParams{ctx, imageID, tx},
+		params: &PlaceImageRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -272,15 +247,15 @@ func (mmDelete *mPlaceImageRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements place.PlaceImageRepository
-func (mmDelete *PlaceImageRepositoryMock) Delete(ctx context.Context, imageID int, tx *sql.Tx) (err error) {
+func (mmDelete *PlaceImageRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, imageID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := PlaceImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mm_params := PlaceImageRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -299,7 +274,7 @@ func (mmDelete *PlaceImageRepositoryMock) Delete(ctx context.Context, imageID in
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceImageRepositoryMockDeleteParams{ctx, imageID, tx}
+		mm_got := PlaceImageRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -307,12 +282,8 @@ func (mmDelete *PlaceImageRepositoryMock) Delete(ctx context.Context, imageID in
 				mmDelete.t.Errorf("PlaceImageRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.imageID != nil && !minimock.Equal(*mm_want_ptrs.imageID, mm_got.imageID) {
-				mmDelete.t.Errorf("PlaceImageRepositoryMock.Delete got unexpected parameter imageID, want: %#v, got: %#v%s\n", *mm_want_ptrs.imageID, mm_got.imageID, minimock.Diff(*mm_want_ptrs.imageID, mm_got.imageID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("PlaceImageRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("PlaceImageRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -326,9 +297,9 @@ func (mmDelete *PlaceImageRepositoryMock) Delete(ctx context.Context, imageID in
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, imageID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to PlaceImageRepositoryMock.Delete. %v %v %v", ctx, imageID, tx)
+	mmDelete.t.Fatalf("Unexpected call to PlaceImageRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 
@@ -423,14 +394,14 @@ type PlaceImageRepositoryMockGetByPlaceIDExpectation struct {
 
 // PlaceImageRepositoryMockGetByPlaceIDParams contains parameters of the PlaceImageRepository.GetByPlaceID
 type PlaceImageRepositoryMockGetByPlaceIDParams struct {
-	ctx     context.Context
-	placeID int
+	ctx context.Context
+	id  uint64
 }
 
 // PlaceImageRepositoryMockGetByPlaceIDParamPtrs contains pointers to parameters of the PlaceImageRepository.GetByPlaceID
 type PlaceImageRepositoryMockGetByPlaceIDParamPtrs struct {
-	ctx     *context.Context
-	placeID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // PlaceImageRepositoryMockGetByPlaceIDResults contains results of the PlaceImageRepository.GetByPlaceID
@@ -450,7 +421,7 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Optional() *mPlaceI
 }
 
 // Expect sets up expected params for PlaceImageRepository.GetByPlaceID
-func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Expect(ctx context.Context, placeID int) *mPlaceImageRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Expect(ctx context.Context, id uint64) *mPlaceImageRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("PlaceImageRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -463,7 +434,7 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Expect(ctx context.
 		mmGetByPlaceID.mock.t.Fatalf("PlaceImageRepositoryMock.GetByPlaceID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByPlaceID.defaultExpectation.params = &PlaceImageRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mmGetByPlaceID.defaultExpectation.params = &PlaceImageRepositoryMockGetByPlaceIDParams{ctx, id}
 	for _, e := range mmGetByPlaceID.expectations {
 		if minimock.Equal(e.params, mmGetByPlaceID.defaultExpectation.params) {
 			mmGetByPlaceID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByPlaceID.defaultExpectation.params)
@@ -495,8 +466,8 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) ExpectCtxParam1(ctx
 	return mmGetByPlaceID
 }
 
-// ExpectPlaceIDParam2 sets up expected param placeID for PlaceImageRepository.GetByPlaceID
-func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) ExpectPlaceIDParam2(placeID int) *mPlaceImageRepositoryMockGetByPlaceID {
+// ExpectIdParam2 sets up expected param id for PlaceImageRepository.GetByPlaceID
+func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) ExpectIdParam2(id uint64) *mPlaceImageRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("PlaceImageRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -512,13 +483,13 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) ExpectPlaceIDParam2
 	if mmGetByPlaceID.defaultExpectation.paramPtrs == nil {
 		mmGetByPlaceID.defaultExpectation.paramPtrs = &PlaceImageRepositoryMockGetByPlaceIDParamPtrs{}
 	}
-	mmGetByPlaceID.defaultExpectation.paramPtrs.placeID = &placeID
+	mmGetByPlaceID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByPlaceID
 }
 
 // Inspect accepts an inspector function that has same arguments as the PlaceImageRepository.GetByPlaceID
-func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, placeID int)) *mPlaceImageRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, id uint64)) *mPlaceImageRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.inspectFuncGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Inspect function is already set for PlaceImageRepositoryMock.GetByPlaceID")
 	}
@@ -542,7 +513,7 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Return(ia1 []models
 }
 
 // Set uses given function f to mock the PlaceImageRepository.GetByPlaceID method
-func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, placeID int) (ia1 []models.Image, err error)) *PlaceImageRepositoryMock {
+func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, id uint64) (ia1 []models.Image, err error)) *PlaceImageRepositoryMock {
 	if mmGetByPlaceID.defaultExpectation != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Default expectation is already set for the PlaceImageRepository.GetByPlaceID method")
 	}
@@ -557,14 +528,14 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) Set(f func(ctx cont
 
 // When sets expectation for the PlaceImageRepository.GetByPlaceID which will trigger the result defined by the following
 // Then helper
-func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) When(ctx context.Context, placeID int) *PlaceImageRepositoryMockGetByPlaceIDExpectation {
+func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) When(ctx context.Context, id uint64) *PlaceImageRepositoryMockGetByPlaceIDExpectation {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("PlaceImageRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
 
 	expectation := &PlaceImageRepositoryMockGetByPlaceIDExpectation{
 		mock:   mmGetByPlaceID.mock,
-		params: &PlaceImageRepositoryMockGetByPlaceIDParams{ctx, placeID},
+		params: &PlaceImageRepositoryMockGetByPlaceIDParams{ctx, id},
 	}
 	mmGetByPlaceID.expectations = append(mmGetByPlaceID.expectations, expectation)
 	return expectation
@@ -597,15 +568,15 @@ func (mmGetByPlaceID *mPlaceImageRepositoryMockGetByPlaceID) invocationsDone() b
 }
 
 // GetByPlaceID implements place.PlaceImageRepository
-func (mmGetByPlaceID *PlaceImageRepositoryMock) GetByPlaceID(ctx context.Context, placeID int) (ia1 []models.Image, err error) {
+func (mmGetByPlaceID *PlaceImageRepositoryMock) GetByPlaceID(ctx context.Context, id uint64) (ia1 []models.Image, err error) {
 	mm_atomic.AddUint64(&mmGetByPlaceID.beforeGetByPlaceIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByPlaceID.afterGetByPlaceIDCounter, 1)
 
 	if mmGetByPlaceID.inspectFuncGetByPlaceID != nil {
-		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, placeID)
+		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, id)
 	}
 
-	mm_params := PlaceImageRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mm_params := PlaceImageRepositoryMockGetByPlaceIDParams{ctx, id}
 
 	// Record call args
 	mmGetByPlaceID.GetByPlaceIDMock.mutex.Lock()
@@ -624,7 +595,7 @@ func (mmGetByPlaceID *PlaceImageRepositoryMock) GetByPlaceID(ctx context.Context
 		mm_want := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceImageRepositoryMockGetByPlaceIDParams{ctx, placeID}
+		mm_got := PlaceImageRepositoryMockGetByPlaceIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -632,8 +603,8 @@ func (mmGetByPlaceID *PlaceImageRepositoryMock) GetByPlaceID(ctx context.Context
 				mmGetByPlaceID.t.Errorf("PlaceImageRepositoryMock.GetByPlaceID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.placeID != nil && !minimock.Equal(*mm_want_ptrs.placeID, mm_got.placeID) {
-				mmGetByPlaceID.t.Errorf("PlaceImageRepositoryMock.GetByPlaceID got unexpected parameter placeID, want: %#v, got: %#v%s\n", *mm_want_ptrs.placeID, mm_got.placeID, minimock.Diff(*mm_want_ptrs.placeID, mm_got.placeID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByPlaceID.t.Errorf("PlaceImageRepositoryMock.GetByPlaceID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -647,9 +618,9 @@ func (mmGetByPlaceID *PlaceImageRepositoryMock) GetByPlaceID(ctx context.Context
 		return (*mm_results).ia1, (*mm_results).err
 	}
 	if mmGetByPlaceID.funcGetByPlaceID != nil {
-		return mmGetByPlaceID.funcGetByPlaceID(ctx, placeID)
+		return mmGetByPlaceID.funcGetByPlaceID(ctx, id)
 	}
-	mmGetByPlaceID.t.Fatalf("Unexpected call to PlaceImageRepositoryMock.GetByPlaceID. %v %v", ctx, placeID)
+	mmGetByPlaceID.t.Fatalf("Unexpected call to PlaceImageRepositoryMock.GetByPlaceID. %v %v", ctx, id)
 	return
 }
 

Різницю між файлами не показано, бо вона завелика
+ 43 - 727
internal/api/v1/place/mocks/place_repository_minimock.go


+ 24 - 53
internal/api/v1/place/mocks/place_thing_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -19,8 +18,8 @@ type PlaceThingRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDeleteThing          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDeleteThing   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDeleteThing          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDeleteThing   func(ctx context.Context, id uint64)
 	afterDeleteThingCounter  uint64
 	beforeDeleteThingCounter uint64
 	DeleteThingMock          mPlaceThingRepositoryMockDeleteThing
@@ -65,16 +64,14 @@ type PlaceThingRepositoryMockDeleteThingExpectation struct {
 
 // PlaceThingRepositoryMockDeleteThingParams contains parameters of the PlaceThingRepository.DeleteThing
 type PlaceThingRepositoryMockDeleteThingParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // PlaceThingRepositoryMockDeleteThingParamPtrs contains pointers to parameters of the PlaceThingRepository.DeleteThing
 type PlaceThingRepositoryMockDeleteThingParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // PlaceThingRepositoryMockDeleteThingResults contains results of the PlaceThingRepository.DeleteThing
@@ -93,7 +90,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Optional() *mPlaceThi
 }
 
 // Expect sets up expected params for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mPlaceThingRepositoryMockDeleteThing {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, id uint64) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
@@ -106,7 +103,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Co
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by ExpectParams functions")
 	}
 
-	mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+	mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 	for _, e := range mmDeleteThing.expectations {
 		if minimock.Equal(e.params, mmDeleteThing.defaultExpectation.params) {
 			mmDeleteThing.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteThing.defaultExpectation.params)
@@ -138,8 +135,8 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectCtxParam1(ctx c
 	return mmDeleteThing
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectThingIDParam2(thingID int) *mPlaceThingRepositoryMockDeleteThing {
+// ExpectIdParam2 sets up expected param id for PlaceThingRepository.DeleteThing
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectIdParam2(id uint64) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
@@ -155,35 +152,13 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectThingIDParam2(t
 	if mmDeleteThing.defaultExpectation.paramPtrs == nil {
 		mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
 	}
-	mmDeleteThing.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDeleteThing
-}
-
-// ExpectTxParam3 sets up expected param tx for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectTxParam3(tx *sql.Tx) *mPlaceThingRepositoryMockDeleteThing {
-	if mmDeleteThing.mock.funcDeleteThing != nil {
-		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
-	}
-
-	if mmDeleteThing.defaultExpectation == nil {
-		mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{}
-	}
-
-	if mmDeleteThing.defaultExpectation.params != nil {
-		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect")
-	}
-
-	if mmDeleteThing.defaultExpectation.paramPtrs == nil {
-		mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
-	}
-	mmDeleteThing.defaultExpectation.paramPtrs.tx = &tx
+	mmDeleteThing.defaultExpectation.paramPtrs.id = &id
 
 	return mmDeleteThing
 }
 
 // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mPlaceThingRepositoryMockDeleteThing {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, id uint64)) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.inspectFuncDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.DeleteThing")
 	}
@@ -207,7 +182,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Return(err error) *Pl
 }
 
 // Set uses given function f to mock the PlaceThingRepository.DeleteThing method
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *PlaceThingRepositoryMock {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, id uint64) (err error)) *PlaceThingRepositoryMock {
 	if mmDeleteThing.defaultExpectation != nil {
 		mmDeleteThing.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.DeleteThing method")
 	}
@@ -222,14 +197,14 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx contex
 
 // When sets expectation for the PlaceThingRepository.DeleteThing which will trigger the result defined by the following
 // Then helper
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, thingID int, tx *sql.Tx) *PlaceThingRepositoryMockDeleteThingExpectation {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, id uint64) *PlaceThingRepositoryMockDeleteThingExpectation {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
 
 	expectation := &PlaceThingRepositoryMockDeleteThingExpectation{
 		mock:   mmDeleteThing.mock,
-		params: &PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx},
+		params: &PlaceThingRepositoryMockDeleteThingParams{ctx, id},
 	}
 	mmDeleteThing.expectations = append(mmDeleteThing.expectations, expectation)
 	return expectation
@@ -262,15 +237,15 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) invocationsDone() boo
 }
 
 // DeleteThing implements place.PlaceThingRepository
-func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDeleteThing.beforeDeleteThingCounter, 1)
 	defer mm_atomic.AddUint64(&mmDeleteThing.afterDeleteThingCounter, 1)
 
 	if mmDeleteThing.inspectFuncDeleteThing != nil {
-		mmDeleteThing.inspectFuncDeleteThing(ctx, thingID, tx)
+		mmDeleteThing.inspectFuncDeleteThing(ctx, id)
 	}
 
-	mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+	mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 
 	// Record call args
 	mmDeleteThing.DeleteThingMock.mutex.Lock()
@@ -289,7 +264,7 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 		mm_want := mmDeleteThing.DeleteThingMock.defaultExpectation.params
 		mm_want_ptrs := mmDeleteThing.DeleteThingMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+		mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -297,12 +272,8 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -316,9 +287,9 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 		return (*mm_results).err
 	}
 	if mmDeleteThing.funcDeleteThing != nil {
-		return mmDeleteThing.funcDeleteThing(ctx, thingID, tx)
+		return mmDeleteThing.funcDeleteThing(ctx, id)
 	}
-	mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v %v", ctx, thingID, tx)
+	mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v", ctx, id)
 	return
 }
 

+ 47 - 76
internal/api/v1/place/mocks/thing_image_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,14 +19,14 @@ type ThingImageRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, imageID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, imageID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingImageRepositoryMockDelete
 
-	funcGetByThingID          func(ctx context.Context, thingID int) (ia1 []models.Image, err error)
-	inspectFuncGetByThingID   func(ctx context.Context, thingID int)
+	funcGetByThingID          func(ctx context.Context, id uint64) (ia1 []models.Image, err error)
+	inspectFuncGetByThingID   func(ctx context.Context, id uint64)
 	afterGetByThingIDCounter  uint64
 	beforeGetByThingIDCounter uint64
 	GetByThingIDMock          mThingImageRepositoryMockGetByThingID
@@ -75,16 +74,14 @@ type ThingImageRepositoryMockDeleteExpectation struct {
 
 // ThingImageRepositoryMockDeleteParams contains parameters of the ThingImageRepository.Delete
 type ThingImageRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	imageID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingImageRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingImageRepository.Delete
 type ThingImageRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	imageID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingImageRepositoryMockDeleteResults contains results of the ThingImageRepository.Delete
@@ -103,7 +100,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Optional() *mThingImageReposito
 }
 
 // Expect sets up expected params for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, imageID int, tx *sql.Tx) *mThingImageRepositoryMockDelete {
+func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -116,7 +113,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, ima
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mmDelete.defaultExpectation.params = &ThingImageRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -148,8 +145,8 @@ func (mmDelete *mThingImageRepositoryMockDelete) ExpectCtxParam1(ctx context.Con
 	return mmDelete
 }
 
-// ExpectImageIDParam2 sets up expected param imageID for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) ExpectImageIDParam2(imageID int) *mThingImageRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingImageRepository.Delete
+func (mmDelete *mThingImageRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -165,35 +162,13 @@ func (mmDelete *mThingImageRepositoryMockDelete) ExpectImageIDParam2(imageID int
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.imageID = &imageID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingImageRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) Inspect(f func(ctx context.Context, imageID int, tx *sql.Tx)) *mThingImageRepositoryMockDelete {
+func (mmDelete *mThingImageRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.Delete")
 	}
@@ -217,7 +192,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Return(err error) *ThingImageRe
 }
 
 // Set uses given function f to mock the ThingImageRepository.Delete method
-func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context, imageID int, tx *sql.Tx) (err error)) *ThingImageRepositoryMock {
+func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingImageRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.Delete method")
 	}
@@ -232,14 +207,14 @@ func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context,
 
 // When sets expectation for the ThingImageRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingImageRepositoryMockDelete) When(ctx context.Context, imageID int, tx *sql.Tx) *ThingImageRepositoryMockDeleteExpectation {
+func (mmDelete *mThingImageRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingImageRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingImageRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx},
+		params: &ThingImageRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -272,15 +247,15 @@ func (mmDelete *mThingImageRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements place.ThingImageRepository
-func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, imageID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mm_params := ThingImageRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -299,7 +274,7 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+		mm_got := ThingImageRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -307,12 +282,8 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.imageID != nil && !minimock.Equal(*mm_want_ptrs.imageID, mm_got.imageID) {
-				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter imageID, want: %#v, got: %#v%s\n", *mm_want_ptrs.imageID, mm_got.imageID, minimock.Diff(*mm_want_ptrs.imageID, mm_got.imageID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -326,9 +297,9 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, imageID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingImageRepositoryMock.Delete. %v %v %v", ctx, imageID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingImageRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 
@@ -423,14 +394,14 @@ type ThingImageRepositoryMockGetByThingIDExpectation struct {
 
 // ThingImageRepositoryMockGetByThingIDParams contains parameters of the ThingImageRepository.GetByThingID
 type ThingImageRepositoryMockGetByThingIDParams struct {
-	ctx     context.Context
-	thingID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingImageRepositoryMockGetByThingIDParamPtrs contains pointers to parameters of the ThingImageRepository.GetByThingID
 type ThingImageRepositoryMockGetByThingIDParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingImageRepositoryMockGetByThingIDResults contains results of the ThingImageRepository.GetByThingID
@@ -450,7 +421,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Optional() *mThingI
 }
 
 // Expect sets up expected params for ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.Context, thingID int) *mThingImageRepositoryMockGetByThingID {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.Context, id uint64) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -463,7 +434,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByThingID.defaultExpectation.params = &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+	mmGetByThingID.defaultExpectation.params = &ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 	for _, e := range mmGetByThingID.expectations {
 		if minimock.Equal(e.params, mmGetByThingID.defaultExpectation.params) {
 			mmGetByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByThingID.defaultExpectation.params)
@@ -495,8 +466,8 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectCtxParam1(ctx
 	return mmGetByThingID
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectThingIDParam2(thingID int) *mThingImageRepositoryMockGetByThingID {
+// ExpectIdParam2 sets up expected param id for ThingImageRepository.GetByThingID
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectIdParam2(id uint64) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -512,13 +483,13 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectThingIDParam2
 	if mmGetByThingID.defaultExpectation.paramPtrs == nil {
 		mmGetByThingID.defaultExpectation.paramPtrs = &ThingImageRepositoryMockGetByThingIDParamPtrs{}
 	}
-	mmGetByThingID.defaultExpectation.paramPtrs.thingID = &thingID
+	mmGetByThingID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByThingID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, thingID int)) *mThingImageRepositoryMockGetByThingID {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, id uint64)) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.inspectFuncGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.GetByThingID")
 	}
@@ -542,7 +513,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Return(ia1 []models
 }
 
 // Set uses given function f to mock the ThingImageRepository.GetByThingID method
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx context.Context, thingID int) (ia1 []models.Image, err error)) *ThingImageRepositoryMock {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx context.Context, id uint64) (ia1 []models.Image, err error)) *ThingImageRepositoryMock {
 	if mmGetByThingID.defaultExpectation != nil {
 		mmGetByThingID.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.GetByThingID method")
 	}
@@ -557,14 +528,14 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx cont
 
 // When sets expectation for the ThingImageRepository.GetByThingID which will trigger the result defined by the following
 // Then helper
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) When(ctx context.Context, thingID int) *ThingImageRepositoryMockGetByThingIDExpectation {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) When(ctx context.Context, id uint64) *ThingImageRepositoryMockGetByThingIDExpectation {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
 
 	expectation := &ThingImageRepositoryMockGetByThingIDExpectation{
 		mock:   mmGetByThingID.mock,
-		params: &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID},
+		params: &ThingImageRepositoryMockGetByThingIDParams{ctx, id},
 	}
 	mmGetByThingID.expectations = append(mmGetByThingID.expectations, expectation)
 	return expectation
@@ -597,15 +568,15 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) invocationsDone() b
 }
 
 // GetByThingID implements place.ThingImageRepository
-func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context, thingID int) (ia1 []models.Image, err error) {
+func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context, id uint64) (ia1 []models.Image, err error) {
 	mm_atomic.AddUint64(&mmGetByThingID.beforeGetByThingIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByThingID.afterGetByThingIDCounter, 1)
 
 	if mmGetByThingID.inspectFuncGetByThingID != nil {
-		mmGetByThingID.inspectFuncGetByThingID(ctx, thingID)
+		mmGetByThingID.inspectFuncGetByThingID(ctx, id)
 	}
 
-	mm_params := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+	mm_params := ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 
 	// Record call args
 	mmGetByThingID.GetByThingIDMock.mutex.Lock()
@@ -624,7 +595,7 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 		mm_want := mmGetByThingID.GetByThingIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByThingID.GetByThingIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+		mm_got := ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -632,8 +603,8 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -647,9 +618,9 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 		return (*mm_results).ia1, (*mm_results).err
 	}
 	if mmGetByThingID.funcGetByThingID != nil {
-		return mmGetByThingID.funcGetByThingID(ctx, thingID)
+		return mmGetByThingID.funcGetByThingID(ctx, id)
 	}
-	mmGetByThingID.t.Fatalf("Unexpected call to ThingImageRepositoryMock.GetByThingID. %v %v", ctx, thingID)
+	mmGetByThingID.t.Fatalf("Unexpected call to ThingImageRepositoryMock.GetByThingID. %v %v", ctx, id)
 	return
 }
 

+ 24 - 53
internal/api/v1/place/mocks/thing_notification_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -19,8 +18,8 @@ type ThingNotificationRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingNotificationRepositoryMockDelete
@@ -65,16 +64,14 @@ type ThingNotificationRepositoryMockDeleteExpectation struct {
 
 // ThingNotificationRepositoryMockDeleteParams contains parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingNotificationRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingNotificationRepositoryMockDeleteResults contains results of the ThingNotificationRepository.Delete
@@ -93,7 +90,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Optional() *mThingNotifi
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -106,7 +103,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Conte
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -138,8 +135,8 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectCtxParam1(ctx cont
 	return mmDelete
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thingID int) *mThingNotificationRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingNotificationRepository.Delete
+func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -155,35 +152,13 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thin
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Delete")
 	}
@@ -207,7 +182,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Return(err error) *Thing
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Delete method
-func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingNotificationRepositoryMock {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingNotificationRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Delete method")
 	}
@@ -222,14 +197,14 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.C
 
 // When sets expectation for the ThingNotificationRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingNotificationRepositoryMockDeleteExpectation {
+func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingNotificationRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx},
+		params: &ThingNotificationRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -262,15 +237,15 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements place.ThingNotificationRepository
-func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, thingID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -289,7 +264,7 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -297,12 +272,8 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -316,9 +287,9 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, thingID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v %v", ctx, thingID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 

+ 47 - 76
internal/api/v1/place/mocks/thing_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,14 +19,14 @@ type ThingRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingRepositoryMockDelete
 
-	funcGetByPlaceID          func(ctx context.Context, placeID int) (ta1 []models.Thing, err error)
-	inspectFuncGetByPlaceID   func(ctx context.Context, placeID int)
+	funcGetByPlaceID          func(ctx context.Context, id uint64) (ta1 []models.Thing, err error)
+	inspectFuncGetByPlaceID   func(ctx context.Context, id uint64)
 	afterGetByPlaceIDCounter  uint64
 	beforeGetByPlaceIDCounter uint64
 	GetByPlaceIDMock          mThingRepositoryMockGetByPlaceID
@@ -75,16 +74,14 @@ type ThingRepositoryMockDeleteExpectation struct {
 
 // ThingRepositoryMockDeleteParams contains parameters of the ThingRepository.Delete
 type ThingRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingRepository.Delete
 type ThingRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingRepositoryMockDeleteResults contains results of the ThingRepository.Delete
@@ -103,7 +100,7 @@ func (mmDelete *mThingRepositoryMockDelete) Optional() *mThingRepositoryMockDele
 }
 
 // Expect sets up expected params for ThingRepository.Delete
-func (mmDelete *mThingRepositoryMockDelete) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingRepositoryMockDelete {
+func (mmDelete *mThingRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by Set")
 	}
@@ -116,7 +113,7 @@ func (mmDelete *mThingRepositoryMockDelete) Expect(ctx context.Context, thingID
 		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingRepositoryMockDeleteParams{ctx, thingID, tx}
+	mmDelete.defaultExpectation.params = &ThingRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -148,8 +145,8 @@ func (mmDelete *mThingRepositoryMockDelete) ExpectCtxParam1(ctx context.Context)
 	return mmDelete
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingRepository.Delete
-func (mmDelete *mThingRepositoryMockDelete) ExpectThingIDParam2(thingID int) *mThingRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingRepository.Delete
+func (mmDelete *mThingRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by Set")
 	}
@@ -165,35 +162,13 @@ func (mmDelete *mThingRepositoryMockDelete) ExpectThingIDParam2(thingID int) *mT
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingRepository.Delete
-func (mmDelete *mThingRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingRepository.Delete
-func (mmDelete *mThingRepositoryMockDelete) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingRepositoryMockDelete {
+func (mmDelete *mThingRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingRepositoryMock.Delete")
 	}
@@ -217,7 +192,7 @@ func (mmDelete *mThingRepositoryMockDelete) Return(err error) *ThingRepositoryMo
 }
 
 // Set uses given function f to mock the ThingRepository.Delete method
-func (mmDelete *mThingRepositoryMockDelete) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingRepositoryMock {
+func (mmDelete *mThingRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingRepository.Delete method")
 	}
@@ -232,14 +207,14 @@ func (mmDelete *mThingRepositoryMockDelete) Set(f func(ctx context.Context, thin
 
 // When sets expectation for the ThingRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingRepositoryMockDelete) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingRepositoryMockDeleteExpectation {
+func (mmDelete *mThingRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingRepositoryMockDeleteParams{ctx, thingID, tx},
+		params: &ThingRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -272,15 +247,15 @@ func (mmDelete *mThingRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements place.ThingRepository
-func (mmDelete *ThingRepositoryMock) Delete(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, thingID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingRepositoryMockDeleteParams{ctx, thingID, tx}
+	mm_params := ThingRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -299,7 +274,7 @@ func (mmDelete *ThingRepositoryMock) Delete(ctx context.Context, thingID int, tx
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingRepositoryMockDeleteParams{ctx, thingID, tx}
+		mm_got := ThingRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -307,12 +282,8 @@ func (mmDelete *ThingRepositoryMock) Delete(ctx context.Context, thingID int, tx
 				mmDelete.t.Errorf("ThingRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDelete.t.Errorf("ThingRepositoryMock.Delete got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -326,9 +297,9 @@ func (mmDelete *ThingRepositoryMock) Delete(ctx context.Context, thingID int, tx
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, thingID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingRepositoryMock.Delete. %v %v %v", ctx, thingID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 
@@ -423,14 +394,14 @@ type ThingRepositoryMockGetByPlaceIDExpectation struct {
 
 // ThingRepositoryMockGetByPlaceIDParams contains parameters of the ThingRepository.GetByPlaceID
 type ThingRepositoryMockGetByPlaceIDParams struct {
-	ctx     context.Context
-	placeID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingRepositoryMockGetByPlaceIDParamPtrs contains pointers to parameters of the ThingRepository.GetByPlaceID
 type ThingRepositoryMockGetByPlaceIDParamPtrs struct {
-	ctx     *context.Context
-	placeID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingRepositoryMockGetByPlaceIDResults contains results of the ThingRepository.GetByPlaceID
@@ -450,7 +421,7 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Optional() *mThingReposi
 }
 
 // Expect sets up expected params for ThingRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Expect(ctx context.Context, placeID int) *mThingRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Expect(ctx context.Context, id uint64) *mThingRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -463,7 +434,7 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Expect(ctx context.Conte
 		mmGetByPlaceID.mock.t.Fatalf("ThingRepositoryMock.GetByPlaceID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByPlaceID.defaultExpectation.params = &ThingRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mmGetByPlaceID.defaultExpectation.params = &ThingRepositoryMockGetByPlaceIDParams{ctx, id}
 	for _, e := range mmGetByPlaceID.expectations {
 		if minimock.Equal(e.params, mmGetByPlaceID.defaultExpectation.params) {
 			mmGetByPlaceID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByPlaceID.defaultExpectation.params)
@@ -495,8 +466,8 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) ExpectCtxParam1(ctx cont
 	return mmGetByPlaceID
 }
 
-// ExpectPlaceIDParam2 sets up expected param placeID for ThingRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) ExpectPlaceIDParam2(placeID int) *mThingRepositoryMockGetByPlaceID {
+// ExpectIdParam2 sets up expected param id for ThingRepository.GetByPlaceID
+func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) ExpectIdParam2(id uint64) *mThingRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -512,13 +483,13 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) ExpectPlaceIDParam2(plac
 	if mmGetByPlaceID.defaultExpectation.paramPtrs == nil {
 		mmGetByPlaceID.defaultExpectation.paramPtrs = &ThingRepositoryMockGetByPlaceIDParamPtrs{}
 	}
-	mmGetByPlaceID.defaultExpectation.paramPtrs.placeID = &placeID
+	mmGetByPlaceID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByPlaceID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, placeID int)) *mThingRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, id uint64)) *mThingRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.inspectFuncGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Inspect function is already set for ThingRepositoryMock.GetByPlaceID")
 	}
@@ -542,7 +513,7 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Return(ta1 []models.Thin
 }
 
 // Set uses given function f to mock the ThingRepository.GetByPlaceID method
-func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, placeID int) (ta1 []models.Thing, err error)) *ThingRepositoryMock {
+func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, id uint64) (ta1 []models.Thing, err error)) *ThingRepositoryMock {
 	if mmGetByPlaceID.defaultExpectation != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Default expectation is already set for the ThingRepository.GetByPlaceID method")
 	}
@@ -557,14 +528,14 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) Set(f func(ctx context.C
 
 // When sets expectation for the ThingRepository.GetByPlaceID which will trigger the result defined by the following
 // Then helper
-func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) When(ctx context.Context, placeID int) *ThingRepositoryMockGetByPlaceIDExpectation {
+func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) When(ctx context.Context, id uint64) *ThingRepositoryMockGetByPlaceIDExpectation {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
 
 	expectation := &ThingRepositoryMockGetByPlaceIDExpectation{
 		mock:   mmGetByPlaceID.mock,
-		params: &ThingRepositoryMockGetByPlaceIDParams{ctx, placeID},
+		params: &ThingRepositoryMockGetByPlaceIDParams{ctx, id},
 	}
 	mmGetByPlaceID.expectations = append(mmGetByPlaceID.expectations, expectation)
 	return expectation
@@ -597,15 +568,15 @@ func (mmGetByPlaceID *mThingRepositoryMockGetByPlaceID) invocationsDone() bool {
 }
 
 // GetByPlaceID implements place.ThingRepository
-func (mmGetByPlaceID *ThingRepositoryMock) GetByPlaceID(ctx context.Context, placeID int) (ta1 []models.Thing, err error) {
+func (mmGetByPlaceID *ThingRepositoryMock) GetByPlaceID(ctx context.Context, id uint64) (ta1 []models.Thing, err error) {
 	mm_atomic.AddUint64(&mmGetByPlaceID.beforeGetByPlaceIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByPlaceID.afterGetByPlaceIDCounter, 1)
 
 	if mmGetByPlaceID.inspectFuncGetByPlaceID != nil {
-		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, placeID)
+		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, id)
 	}
 
-	mm_params := ThingRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mm_params := ThingRepositoryMockGetByPlaceIDParams{ctx, id}
 
 	// Record call args
 	mmGetByPlaceID.GetByPlaceIDMock.mutex.Lock()
@@ -624,7 +595,7 @@ func (mmGetByPlaceID *ThingRepositoryMock) GetByPlaceID(ctx context.Context, pla
 		mm_want := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingRepositoryMockGetByPlaceIDParams{ctx, placeID}
+		mm_got := ThingRepositoryMockGetByPlaceIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -632,8 +603,8 @@ func (mmGetByPlaceID *ThingRepositoryMock) GetByPlaceID(ctx context.Context, pla
 				mmGetByPlaceID.t.Errorf("ThingRepositoryMock.GetByPlaceID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.placeID != nil && !minimock.Equal(*mm_want_ptrs.placeID, mm_got.placeID) {
-				mmGetByPlaceID.t.Errorf("ThingRepositoryMock.GetByPlaceID got unexpected parameter placeID, want: %#v, got: %#v%s\n", *mm_want_ptrs.placeID, mm_got.placeID, minimock.Diff(*mm_want_ptrs.placeID, mm_got.placeID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByPlaceID.t.Errorf("ThingRepositoryMock.GetByPlaceID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -647,9 +618,9 @@ func (mmGetByPlaceID *ThingRepositoryMock) GetByPlaceID(ctx context.Context, pla
 		return (*mm_results).ta1, (*mm_results).err
 	}
 	if mmGetByPlaceID.funcGetByPlaceID != nil {
-		return mmGetByPlaceID.funcGetByPlaceID(ctx, placeID)
+		return mmGetByPlaceID.funcGetByPlaceID(ctx, id)
 	}
-	mmGetByPlaceID.t.Fatalf("Unexpected call to ThingRepositoryMock.GetByPlaceID. %v %v", ctx, placeID)
+	mmGetByPlaceID.t.Fatalf("Unexpected call to ThingRepositoryMock.GetByPlaceID. %v %v", ctx, id)
 	return
 }
 

+ 24 - 53
internal/api/v1/place/mocks/thing_tag_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -19,8 +18,8 @@ type ThingTagRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDeleteByThingID          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDeleteByThingID   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDeleteByThingID          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDeleteByThingID   func(ctx context.Context, id uint64)
 	afterDeleteByThingIDCounter  uint64
 	beforeDeleteByThingIDCounter uint64
 	DeleteByThingIDMock          mThingTagRepositoryMockDeleteByThingID
@@ -65,16 +64,14 @@ type ThingTagRepositoryMockDeleteByThingIDExpectation struct {
 
 // ThingTagRepositoryMockDeleteByThingIDParams contains parameters of the ThingTagRepository.DeleteByThingID
 type ThingTagRepositoryMockDeleteByThingIDParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingTagRepositoryMockDeleteByThingIDParamPtrs contains pointers to parameters of the ThingTagRepository.DeleteByThingID
 type ThingTagRepositoryMockDeleteByThingIDParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingTagRepositoryMockDeleteByThingIDResults contains results of the ThingTagRepository.DeleteByThingID
@@ -93,7 +90,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Optional() *mTh
 }
 
 // Expect sets up expected params for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingTagRepositoryMockDeleteByThingID {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx context.Context, id uint64) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
@@ -106,7 +103,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx cont
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by ExpectParams functions")
 	}
 
-	mmDeleteByThingID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+	mmDeleteByThingID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 	for _, e := range mmDeleteByThingID.expectations {
 		if minimock.Equal(e.params, mmDeleteByThingID.defaultExpectation.params) {
 			mmDeleteByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteByThingID.defaultExpectation.params)
@@ -138,8 +135,8 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectCtxParam1
 	return mmDeleteByThingID
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectThingIDParam2(thingID int) *mThingTagRepositoryMockDeleteByThingID {
+// ExpectIdParam2 sets up expected param id for ThingTagRepository.DeleteByThingID
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectIdParam2(id uint64) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
@@ -155,35 +152,13 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectThingIDPa
 	if mmDeleteByThingID.defaultExpectation.paramPtrs == nil {
 		mmDeleteByThingID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByThingIDParamPtrs{}
 	}
-	mmDeleteByThingID.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDeleteByThingID
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectTxParam3(tx *sql.Tx) *mThingTagRepositoryMockDeleteByThingID {
-	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
-		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
-	}
-
-	if mmDeleteByThingID.defaultExpectation == nil {
-		mmDeleteByThingID.defaultExpectation = &ThingTagRepositoryMockDeleteByThingIDExpectation{}
-	}
-
-	if mmDeleteByThingID.defaultExpectation.params != nil {
-		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Expect")
-	}
-
-	if mmDeleteByThingID.defaultExpectation.paramPtrs == nil {
-		mmDeleteByThingID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByThingIDParamPtrs{}
-	}
-	mmDeleteByThingID.defaultExpectation.paramPtrs.tx = &tx
+	mmDeleteByThingID.defaultExpectation.paramPtrs.id = &id
 
 	return mmDeleteByThingID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingTagRepositoryMockDeleteByThingID {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Inspect(f func(ctx context.Context, id uint64)) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.inspectFuncDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.DeleteByThingID")
 	}
@@ -207,7 +182,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Return(err erro
 }
 
 // Set uses given function f to mock the ThingTagRepository.DeleteByThingID method
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingTagRepositoryMock {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx context.Context, id uint64) (err error)) *ThingTagRepositoryMock {
 	if mmDeleteByThingID.defaultExpectation != nil {
 		mmDeleteByThingID.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.DeleteByThingID method")
 	}
@@ -222,14 +197,14 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx
 
 // When sets expectation for the ThingTagRepository.DeleteByThingID which will trigger the result defined by the following
 // Then helper
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingTagRepositoryMockDeleteByThingIDExpectation {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) When(ctx context.Context, id uint64) *ThingTagRepositoryMockDeleteByThingIDExpectation {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockDeleteByThingIDExpectation{
 		mock:   mmDeleteByThingID.mock,
-		params: &ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx},
+		params: &ThingTagRepositoryMockDeleteByThingIDParams{ctx, id},
 	}
 	mmDeleteByThingID.expectations = append(mmDeleteByThingID.expectations, expectation)
 	return expectation
@@ -262,15 +237,15 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) invocationsDone
 }
 
 // DeleteByThingID implements place.ThingTagRepository
-func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDeleteByThingID.beforeDeleteByThingIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmDeleteByThingID.afterDeleteByThingIDCounter, 1)
 
 	if mmDeleteByThingID.inspectFuncDeleteByThingID != nil {
-		mmDeleteByThingID.inspectFuncDeleteByThingID(ctx, thingID, tx)
+		mmDeleteByThingID.inspectFuncDeleteByThingID(ctx, id)
 	}
 
-	mm_params := ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+	mm_params := ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 
 	// Record call args
 	mmDeleteByThingID.DeleteByThingIDMock.mutex.Lock()
@@ -289,7 +264,7 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 		mm_want := mmDeleteByThingID.DeleteByThingIDMock.defaultExpectation.params
 		mm_want_ptrs := mmDeleteByThingID.DeleteByThingIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+		mm_got := ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -297,12 +272,8 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -316,9 +287,9 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 		return (*mm_results).err
 	}
 	if mmDeleteByThingID.funcDeleteByThingID != nil {
-		return mmDeleteByThingID.funcDeleteByThingID(ctx, thingID, tx)
+		return mmDeleteByThingID.funcDeleteByThingID(ctx, id)
 	}
-	mmDeleteByThingID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByThingID. %v %v %v", ctx, thingID, tx)
+	mmDeleteByThingID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByThingID. %v %v", ctx, id)
 	return
 }
 

+ 393 - 0
internal/api/v1/place/mocks/transaction_manager_minimock.go

@@ -0,0 +1,393 @@
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
+
+package mocks
+
+//go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place.TransactionManager -o transaction_manager_minimock.go -n TransactionManagerMock -p mocks
+
+import (
+	"context"
+	"sync"
+	mm_atomic "sync/atomic"
+	mm_time "time"
+
+	"github.com/gojuno/minimock/v3"
+)
+
+// TransactionManagerMock implements place.TransactionManager
+type TransactionManagerMock struct {
+	t          minimock.Tester
+	finishOnce sync.Once
+
+	funcReadCommitted          func(ctx context.Context, f1 func(ctx context.Context) error) (err error)
+	inspectFuncReadCommitted   func(ctx context.Context, f1 func(ctx context.Context) error)
+	afterReadCommittedCounter  uint64
+	beforeReadCommittedCounter uint64
+	ReadCommittedMock          mTransactionManagerMockReadCommitted
+}
+
+// NewTransactionManagerMock returns a mock for place.TransactionManager
+func NewTransactionManagerMock(t minimock.Tester) *TransactionManagerMock {
+	m := &TransactionManagerMock{t: t}
+
+	if controller, ok := t.(minimock.MockController); ok {
+		controller.RegisterMocker(m)
+	}
+
+	m.ReadCommittedMock = mTransactionManagerMockReadCommitted{mock: m}
+	m.ReadCommittedMock.callArgs = []*TransactionManagerMockReadCommittedParams{}
+
+	t.Cleanup(m.MinimockFinish)
+
+	return m
+}
+
+type mTransactionManagerMockReadCommitted struct {
+	optional           bool
+	mock               *TransactionManagerMock
+	defaultExpectation *TransactionManagerMockReadCommittedExpectation
+	expectations       []*TransactionManagerMockReadCommittedExpectation
+
+	callArgs []*TransactionManagerMockReadCommittedParams
+	mutex    sync.RWMutex
+
+	expectedInvocations uint64
+}
+
+// TransactionManagerMockReadCommittedExpectation specifies expectation struct of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedExpectation struct {
+	mock      *TransactionManagerMock
+	params    *TransactionManagerMockReadCommittedParams
+	paramPtrs *TransactionManagerMockReadCommittedParamPtrs
+	results   *TransactionManagerMockReadCommittedResults
+	Counter   uint64
+}
+
+// TransactionManagerMockReadCommittedParams contains parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParams struct {
+	ctx context.Context
+	f1  func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedParamPtrs contains pointers to parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParamPtrs struct {
+	ctx *context.Context
+	f1  *func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedResults contains results of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedResults struct {
+	err error
+}
+
+// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
+// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
+// Optional() makes method check to work in '0 or more' mode.
+// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
+// catch the problems when the expected method call is totally skipped during test run.
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Optional() *mTransactionManagerMockReadCommitted {
+	mmReadCommitted.optional = true
+	return mmReadCommitted
+}
+
+// Expect sets up expected params for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Expect(ctx context.Context, f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by ExpectParams functions")
+	}
+
+	mmReadCommitted.defaultExpectation.params = &TransactionManagerMockReadCommittedParams{ctx, f1}
+	for _, e := range mmReadCommitted.expectations {
+		if minimock.Equal(e.params, mmReadCommitted.defaultExpectation.params) {
+			mmReadCommitted.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmReadCommitted.defaultExpectation.params)
+		}
+	}
+
+	return mmReadCommitted
+}
+
+// ExpectCtxParam1 sets up expected param ctx for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectCtxParam1(ctx context.Context) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.ctx = &ctx
+
+	return mmReadCommitted
+}
+
+// ExpectF1Param2 sets up expected param f1 for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectF1Param2(f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.f1 = &f1
+
+	return mmReadCommitted
+}
+
+// Inspect accepts an inspector function that has same arguments as the TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Inspect(f func(ctx context.Context, f1 func(ctx context.Context) error)) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.inspectFuncReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("Inspect function is already set for TransactionManagerMock.ReadCommitted")
+	}
+
+	mmReadCommitted.mock.inspectFuncReadCommitted = f
+
+	return mmReadCommitted
+}
+
+// Return sets up results that will be returned by TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Return(err error) *TransactionManagerMock {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{mock: mmReadCommitted.mock}
+	}
+	mmReadCommitted.defaultExpectation.results = &TransactionManagerMockReadCommittedResults{err}
+	return mmReadCommitted.mock
+}
+
+// Set uses given function f to mock the TransactionManager.ReadCommitted method
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Set(f func(ctx context.Context, f1 func(ctx context.Context) error) (err error)) *TransactionManagerMock {
+	if mmReadCommitted.defaultExpectation != nil {
+		mmReadCommitted.mock.t.Fatalf("Default expectation is already set for the TransactionManager.ReadCommitted method")
+	}
+
+	if len(mmReadCommitted.expectations) > 0 {
+		mmReadCommitted.mock.t.Fatalf("Some expectations are already set for the TransactionManager.ReadCommitted method")
+	}
+
+	mmReadCommitted.mock.funcReadCommitted = f
+	return mmReadCommitted.mock
+}
+
+// When sets expectation for the TransactionManager.ReadCommitted which will trigger the result defined by the following
+// Then helper
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) When(ctx context.Context, f1 func(ctx context.Context) error) *TransactionManagerMockReadCommittedExpectation {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	expectation := &TransactionManagerMockReadCommittedExpectation{
+		mock:   mmReadCommitted.mock,
+		params: &TransactionManagerMockReadCommittedParams{ctx, f1},
+	}
+	mmReadCommitted.expectations = append(mmReadCommitted.expectations, expectation)
+	return expectation
+}
+
+// Then sets up TransactionManager.ReadCommitted return parameters for the expectation previously defined by the When method
+func (e *TransactionManagerMockReadCommittedExpectation) Then(err error) *TransactionManagerMock {
+	e.results = &TransactionManagerMockReadCommittedResults{err}
+	return e.mock
+}
+
+// Times sets number of times TransactionManager.ReadCommitted should be invoked
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Times(n uint64) *mTransactionManagerMockReadCommitted {
+	if n == 0 {
+		mmReadCommitted.mock.t.Fatalf("Times of TransactionManagerMock.ReadCommitted mock can not be zero")
+	}
+	mm_atomic.StoreUint64(&mmReadCommitted.expectedInvocations, n)
+	return mmReadCommitted
+}
+
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) invocationsDone() bool {
+	if len(mmReadCommitted.expectations) == 0 && mmReadCommitted.defaultExpectation == nil && mmReadCommitted.mock.funcReadCommitted == nil {
+		return true
+	}
+
+	totalInvocations := mm_atomic.LoadUint64(&mmReadCommitted.mock.afterReadCommittedCounter)
+	expectedInvocations := mm_atomic.LoadUint64(&mmReadCommitted.expectedInvocations)
+
+	return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
+}
+
+// ReadCommitted implements place.TransactionManager
+func (mmReadCommitted *TransactionManagerMock) ReadCommitted(ctx context.Context, f1 func(ctx context.Context) error) (err error) {
+	mm_atomic.AddUint64(&mmReadCommitted.beforeReadCommittedCounter, 1)
+	defer mm_atomic.AddUint64(&mmReadCommitted.afterReadCommittedCounter, 1)
+
+	if mmReadCommitted.inspectFuncReadCommitted != nil {
+		mmReadCommitted.inspectFuncReadCommitted(ctx, f1)
+	}
+
+	mm_params := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+	// Record call args
+	mmReadCommitted.ReadCommittedMock.mutex.Lock()
+	mmReadCommitted.ReadCommittedMock.callArgs = append(mmReadCommitted.ReadCommittedMock.callArgs, &mm_params)
+	mmReadCommitted.ReadCommittedMock.mutex.Unlock()
+
+	for _, e := range mmReadCommitted.ReadCommittedMock.expectations {
+		if minimock.Equal(*e.params, mm_params) {
+			mm_atomic.AddUint64(&e.Counter, 1)
+			return e.results.err
+		}
+	}
+
+	if mmReadCommitted.ReadCommittedMock.defaultExpectation != nil {
+		mm_atomic.AddUint64(&mmReadCommitted.ReadCommittedMock.defaultExpectation.Counter, 1)
+		mm_want := mmReadCommitted.ReadCommittedMock.defaultExpectation.params
+		mm_want_ptrs := mmReadCommitted.ReadCommittedMock.defaultExpectation.paramPtrs
+
+		mm_got := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+		if mm_want_ptrs != nil {
+
+			if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
+			}
+
+			if mm_want_ptrs.f1 != nil && !minimock.Equal(*mm_want_ptrs.f1, mm_got.f1) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter f1, want: %#v, got: %#v%s\n", *mm_want_ptrs.f1, mm_got.f1, minimock.Diff(*mm_want_ptrs.f1, mm_got.f1))
+			}
+
+		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
+			mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
+		}
+
+		mm_results := mmReadCommitted.ReadCommittedMock.defaultExpectation.results
+		if mm_results == nil {
+			mmReadCommitted.t.Fatal("No results are set for the TransactionManagerMock.ReadCommitted")
+		}
+		return (*mm_results).err
+	}
+	if mmReadCommitted.funcReadCommitted != nil {
+		return mmReadCommitted.funcReadCommitted(ctx, f1)
+	}
+	mmReadCommitted.t.Fatalf("Unexpected call to TransactionManagerMock.ReadCommitted. %v %v", ctx, f1)
+	return
+}
+
+// ReadCommittedAfterCounter returns a count of finished TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedAfterCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.afterReadCommittedCounter)
+}
+
+// ReadCommittedBeforeCounter returns a count of TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedBeforeCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.beforeReadCommittedCounter)
+}
+
+// Calls returns a list of arguments used in each call to TransactionManagerMock.ReadCommitted.
+// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Calls() []*TransactionManagerMockReadCommittedParams {
+	mmReadCommitted.mutex.RLock()
+
+	argCopy := make([]*TransactionManagerMockReadCommittedParams, len(mmReadCommitted.callArgs))
+	copy(argCopy, mmReadCommitted.callArgs)
+
+	mmReadCommitted.mutex.RUnlock()
+
+	return argCopy
+}
+
+// MinimockReadCommittedDone returns true if the count of the ReadCommitted invocations corresponds
+// the number of defined expectations
+func (m *TransactionManagerMock) MinimockReadCommittedDone() bool {
+	if m.ReadCommittedMock.optional {
+		// Optional methods provide '0 or more' call count restriction.
+		return true
+	}
+
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			return false
+		}
+	}
+
+	return m.ReadCommittedMock.invocationsDone()
+}
+
+// MinimockReadCommittedInspect logs each unmet expectation
+func (m *TransactionManagerMock) MinimockReadCommittedInspect() {
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *e.params)
+		}
+	}
+
+	afterReadCommittedCounter := mm_atomic.LoadUint64(&m.afterReadCommittedCounter)
+	// if default expectation was set then invocations count should be greater than zero
+	if m.ReadCommittedMock.defaultExpectation != nil && afterReadCommittedCounter < 1 {
+		if m.ReadCommittedMock.defaultExpectation.params == nil {
+			m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+		} else {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *m.ReadCommittedMock.defaultExpectation.params)
+		}
+	}
+	// if func was set then invocations count should be greater than zero
+	if m.funcReadCommitted != nil && afterReadCommittedCounter < 1 {
+		m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+	}
+
+	if !m.ReadCommittedMock.invocationsDone() && afterReadCommittedCounter > 0 {
+		m.t.Errorf("Expected %d calls to TransactionManagerMock.ReadCommitted but found %d calls",
+			mm_atomic.LoadUint64(&m.ReadCommittedMock.expectedInvocations), afterReadCommittedCounter)
+	}
+}
+
+// MinimockFinish checks that all mocked methods have been called the expected number of times
+func (m *TransactionManagerMock) MinimockFinish() {
+	m.finishOnce.Do(func() {
+		if !m.minimockDone() {
+			m.MinimockReadCommittedInspect()
+		}
+	})
+}
+
+// MinimockWait waits for all mocked methods to be called the expected number of times
+func (m *TransactionManagerMock) MinimockWait(timeout mm_time.Duration) {
+	timeoutCh := mm_time.After(timeout)
+	for {
+		if m.minimockDone() {
+			return
+		}
+		select {
+		case <-timeoutCh:
+			m.MinimockFinish()
+			return
+		case <-mm_time.After(10 * mm_time.Millisecond):
+		}
+	}
+}
+
+func (m *TransactionManagerMock) minimockDone() bool {
+	done := true
+	return done &&
+		m.MinimockReadCommittedDone()
+}

+ 11 - 4
internal/api/v1/place/update_place.go

@@ -1,12 +1,14 @@
 package place
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -24,32 +26,37 @@ import (
 func UpdatePlaceHandler(placeRepository PlaceRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("placeId")
+		id, err := request.ConvertToUint64(fctx, "placeId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		req := dto.UpdatePlaceRequest{}
 		if err = fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err = validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		err = placeRepository.Update(ctx, mappers.ToUpdatePlaceRequest(id, req), nil)
+		err = placeRepository.Update(ctx, mappers.ToUpdatePlaceRequest(id, req))
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := placeRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToPlaceResponse(*res))
 	}

+ 18 - 20
internal/api/v1/place/update_place_test.go

@@ -3,7 +3,6 @@ package place
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/place/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -31,15 +29,15 @@ func TestUpdatePlaceHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		parentID  = gofakeit.Number(1, 1000)
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		parentID  = uint64(gofakeit.Number(1, 1000))
 		title     = gofakeit.Phrase()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodPut,
-			route:  "/v1/places/" + strconv.Itoa(placeID),
+			route:  "/v1/places/" + strconv.FormatUint(placeID, 10),
 			body: &dto.UpdatePlaceRequest{
 				Title:    title,
 				ParentID: &parentID,
@@ -79,12 +77,12 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, parentID, int(req.ParentID.Int64))
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(&repoRes, nil)
 
@@ -106,7 +104,7 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			name: "negative case - body parse error",
 			req: req{
 				method: fiber.MethodPut,
-				route:  "/v1/places/" + strconv.Itoa(placeID),
+				route:  "/v1/places/" + strconv.FormatUint(placeID, 10),
 			},
 			resCode: fiber.StatusBadRequest,
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
@@ -117,7 +115,7 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			name: "negative case - request without title",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/places/" + strconv.Itoa(placeID),
+				route:       "/v1/places/" + strconv.FormatUint(placeID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 				body:        &dto.UpdatePlaceRequest{},
 			},
@@ -139,9 +137,9 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, parentID, int(req.ParentID.Int64))
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(testError)
 
 				return mock
@@ -154,12 +152,12 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			placeRepoMock: func(mc *minimock.Controller) PlaceRepository {
 				mock := mocks.NewPlaceRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdatePlaceRequest) {
 					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, parentID, int(req.ParentID.Int64))
+					assert.Equal(mc, parentID, uint64(req.ParentID.Int64))
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -176,13 +174,13 @@ func TestUpdatePlaceHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Put("/v1/places/:placeId", UpdatePlaceHandler(tt.placeRepoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 22 - 16
internal/api/v1/tag/add_tag.go

@@ -2,42 +2,44 @@ package tag
 
 //go:generate mkdir -p mocks
 //go:generate rm -rf ./mocks/*_minimock.go
-//go:generate minimock -i TagRepository,ThingRepository,ThingTagRepository -o ./mocks/ -s "_minimock.go"
+//go:generate minimock -i TagRepository,ThingRepository,ThingTagRepository,TransactionManager -o ./mocks/ -s "_minimock.go"
 
 import (
 	"context"
-	"database/sql"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
 type (
+	TransactionManager interface {
+		ReadCommitted(context.Context, func(ctx context.Context) error) error
+	}
+
 	TagRepository interface {
 		GetAll(ctx context.Context) ([]models.Tag, error)
-		Get(ctx context.Context, tagID int) (*models.Tag, error)
-		GetByThingID(ctx context.Context, thingID int) ([]models.Tag, error)
-		Add(ctx context.Context, req models.AddTagRequest, tx *sql.Tx) (int, error)
-		Update(ctx context.Context, req models.UpdateTagRequest, tx *sql.Tx) error
-		Delete(ctx context.Context, tagID int, tx *sql.Tx) error
-		BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
-		CommitTx(tx *sql.Tx) error
+		Get(ctx context.Context, id uint64) (*models.Tag, error)
+		GetByThingID(ctx context.Context, id uint64) ([]models.Tag, error)
+		Add(ctx context.Context, req models.AddTagRequest) (uint64, error)
+		Update(ctx context.Context, req models.UpdateTagRequest) error
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	ThingRepository interface {
-		Get(ctx context.Context, thingID int) (*models.Thing, error)
+		Get(ctx context.Context, id uint64) (*models.Thing, error)
 	}
 
 	ThingTagRepository interface {
-		Add(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) error
-		Delete(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) error
-		DeleteByTagID(ctx context.Context, tagID int, tx *sql.Tx) error
+		Add(ctx context.Context, req models.AddThingTagRequest) error
+		Delete(ctx context.Context, req models.DeleteThingTagRequest) error
+		DeleteByTagID(ctx context.Context, id uint64) error
 	}
 )
 
@@ -56,25 +58,29 @@ func AddTagHandler(tagRepository TagRepository) fiber.Handler {
 		ctx := fctx.Context()
 		req := dto.AddTagRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		id, err := tagRepository.Add(ctx, mappers.ToAddTagRequest(req), nil)
+		id, err := tagRepository.Add(ctx, mappers.ToAddTagRequest(req))
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := tagRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToTagResponse(*res))
 	}

+ 11 - 14
internal/api/v1/tag/add_tag_test.go

@@ -2,8 +2,6 @@ package tag
 
 import (
 	"context"
-	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -12,10 +10,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,10 +27,10 @@ func TestAddTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
+		tagID     = uint64(gofakeit.Number(1, 1000))
 		title     = gofakeit.Phrase()
 		style     = gofakeit.Phrase()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -78,12 +75,12 @@ func TestAddTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
 				}).Return(tagID, nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(&repoRes, nil)
 
@@ -150,7 +147,7 @@ func TestAddTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
 				}).Return(0, testError)
@@ -165,12 +162,12 @@ func TestAddTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddTagRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
 				}).Return(tagID, nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -187,13 +184,13 @@ func TestAddTagHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Post("/v1/tags", AddTagHandler(tt.tagRepoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 18 - 6
internal/api/v1/tag/add_thing_tag.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -28,36 +30,46 @@ func AddThingTagHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		tagID, err := fctx.ParamsInt("tagId")
+
+		tagID, err := request.ConvertToUint64(fctx, "tagId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		thingID, err := fctx.ParamsInt("thingId")
+		thingID, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		tag, err := tagRepository.Get(ctx, tagID)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
+
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		if _, err = thingRepository.Get(ctx, thingID); err != nil {
-			if err == sql.ErrNoRows {
+			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
+
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		if err = thingTagRepository.Add(ctx, mappers.ToAddThingTagRequest(tagID, thingID), nil); err != nil {
+		if err = thingTagRepository.Add(ctx, mappers.ToAddThingTagRequest(tagID, thingID)); err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		tag = helpers.ApplyLocation(fctx, tag)
+		tag = location.ApplyLocation(fctx, tag)
 
 		return fctx.JSON(mappers.ToTagResponse(*tag))
 	}

+ 23 - 24
internal/api/v1/tag/add_thing_tag_test.go

@@ -3,7 +3,6 @@ package tag
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,14 +28,15 @@ func TestAddThingTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		tagID     = uint64(gofakeit.Number(1, 1000))
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
-			method:      fiber.MethodPost,
-			route:       "/v1/tags/" + strconv.Itoa(tagID) + "/thing/" + strconv.Itoa(thingID),
+			method: fiber.MethodPost,
+			route: "/v1/tags/" + strconv.FormatUint(tagID, 10) +
+				"/thing/" + strconv.FormatUint(thingID, 10),
 			contentType: fiber.MIMEApplicationJSON,
 		}
 
@@ -75,7 +74,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(&tagRepoRes, nil)
 
@@ -84,7 +83,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
@@ -93,7 +92,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingTagRequest) {
 					assert.Equal(mc, tagID, req.TagID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(nil)
@@ -105,7 +104,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			name: "negative case - request without tagID",
 			req: req{
 				method:      fiber.MethodPost,
-				route:       "/v1/tags/" + gofakeit.Word() + "/thing/" + strconv.Itoa(thingID),
+				route:       "/v1/tags/" + gofakeit.Word() + "/thing/" + strconv.FormatUint(thingID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
@@ -123,7 +122,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			name: "negative case - request without thingID",
 			req: req{
 				method:      fiber.MethodPost,
-				route:       "/v1/tags/" + strconv.Itoa(tagID) + "/thing/" + gofakeit.Word(),
+				route:       "/v1/tags/" + strconv.FormatUint(tagID, 10) + "/thing/" + gofakeit.Word(),
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
@@ -144,7 +143,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -164,7 +163,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -184,7 +183,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -193,7 +192,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -210,7 +209,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -219,7 +218,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -236,7 +235,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -245,7 +244,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
@@ -254,7 +253,7 @@ func TestAddThingTagHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingTagRequest) {
 					assert.Equal(mc, tagID, req.TagID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(testError)
@@ -279,11 +278,11 @@ func TestAddThingTagHandler(t *testing.T) {
 
 			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, nil)
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 20 - 13
internal/api/v1/tag/delete_tag.go

@@ -1,13 +1,15 @@
 package tag
 
 import (
+	"context"
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 )
 
 // @Router 		/api/v1/tags/{tagId} [delete]
@@ -21,37 +23,42 @@ import (
 // @Accept      json
 // @Produce     json
 func DeleteTagHandler(
+	tm TransactionManager,
 	tagRepository TagRepository,
 	thingTagRepository ThingTagRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("tagId")
+		id, err := request.ConvertToUint64(fctx, "tagId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		if _, err = tagRepository.Get(ctx, id); err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
 
-		tx, err := tagRepository.BeginTx(ctx, API.DefaultTxLevel)
-		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		if err = thingTagRepository.DeleteByTagID(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			if txErr := thingTagRepository.DeleteByTagID(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = tagRepository.Delete(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr := tagRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = tagRepository.CommitTx(tx); err != nil {
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 48 - 75
internal/api/v1/tag/delete_tag_test.go

@@ -3,7 +3,6 @@ package tag
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 )
 
 func TestDeleteTagHandler(t *testing.T) {
@@ -29,12 +27,16 @@ func TestDeleteTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		tagID     = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
+
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
 
 		correctReq = req{
 			method:      fiber.MethodDelete,
-			route:       "/v1/tags/" + strconv.Itoa(tagID),
+			route:       "/v1/tags/" + strconv.FormatUint(tagID, 10),
 			contentType: fiber.MIMEApplicationJSON,
 		}
 	)
@@ -44,6 +46,7 @@ func TestDeleteTagHandler(t *testing.T) {
 		req              req
 		resCode          int
 		resBody          interface{}
+		tmMock           func(mc *minimock.Controller) TransactionManager
 		tagRepoMock      func(mc *minimock.Controller) TagRepository
 		thingTagRepoMock func(mc *minimock.Controller) ThingTagRepository
 	}{
@@ -55,6 +58,9 @@ func TestDeleteTagHandler(t *testing.T) {
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				return mocks.NewTagRepositoryMock(mc)
 			},
@@ -66,10 +72,13 @@ func TestDeleteTagHandler(t *testing.T) {
 			name:    "negative case - tag is not exist",
 			req:     correctReq,
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -83,10 +92,13 @@ func TestDeleteTagHandler(t *testing.T) {
 			name:    "negative case - tag repository error (get)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -97,43 +109,27 @@ func TestDeleteTagHandler(t *testing.T) {
 			},
 		},
 		{
-			name:    "negative case - tag repository error (begin tx)",
+			name:    "negative case - thing tag repository error (delete)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			tagRepoMock: func(mc *minimock.Controller) TagRepository {
-				mock := mocks.NewTagRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, tagID, id)
-				}).Return(nil, nil)
-
-				mock.BeginTxMock.Return(nil, testError)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
-				return mocks.NewThingTagRepositoryMock(mc)
-			},
-		},
-		{
-			name:    "negative case - thing tag repository error (delete)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(testError)
 
@@ -144,56 +140,28 @@ func TestDeleteTagHandler(t *testing.T) {
 			name:    "negative case - tag repository error (delete)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			tagRepoMock: func(mc *minimock.Controller) TagRepository {
-				mock := mocks.NewTagRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, tagID, id)
-				}).Return(nil, nil)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, tagID, id)
-				}).Return(testError)
-
-				return mock
-			},
-			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
-				mock := mocks.NewThingTagRepositoryMock(mc)
-
-				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, tagID, id)
-				}).Return(nil)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-		},
-		{
-			name:    "negative case - tag repository error (commit tx)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
-				}).Return(nil)
-
-				mock.CommitTxMock.Return(testError)
+				}).Return(testError)
 
 				return mock
 			},
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil)
 
@@ -205,27 +173,28 @@ func TestDeleteTagHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByTagIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil)
 
@@ -240,15 +209,19 @@ func TestDeleteTagHandler(t *testing.T) {
 
 			mc := minimock.NewController(t)
 			fiberApp := fiber.New()
-			fiberApp.Delete("/v1/tags/:tagId", DeleteTagHandler(tt.tagRepoMock(mc), tt.thingTagRepoMock(mc)))
+			fiberApp.Delete("/v1/tags/:tagId", DeleteTagHandler(
+				tt.tmMock(mc),
+				tt.tagRepoMock(mc),
+				tt.thingTagRepoMock(mc),
+			))
 
 			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, nil)
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 14 - 3
internal/api/v1/tag/delete_thing_tag.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -28,31 +30,40 @@ func DeleteThingTagHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		tagID, err := fctx.ParamsInt("tagId")
+		tagID, err := request.ConvertToUint64(fctx, "tagId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
-		thingID, err := fctx.ParamsInt("thingId")
+		thingID, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		if _, err = tagRepository.Get(ctx, tagID); err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
+
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		if _, err = thingRepository.Get(ctx, thingID); err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
+
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		if err = thingTagRepository.Delete(ctx, mappers.ToDeleteThingTagRequest(tagID, thingID), nil); err != nil {
+		if err = thingTagRepository.Delete(ctx, mappers.ToDeleteThingTagRequest(tagID, thingID)); err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

+ 23 - 24
internal/api/v1/tag/delete_thing_tag_test.go

@@ -3,7 +3,6 @@ package tag
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,13 +28,14 @@ func TestDeleteThingTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		tagID     = uint64(gofakeit.Number(1, 1000))
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 
 		correctReq = req{
-			method:      fiber.MethodDelete,
-			route:       "/v1/tags/" + strconv.Itoa(tagID) + "/thing/" + strconv.Itoa(thingID),
+			method: fiber.MethodDelete,
+			route: "/v1/tags/" + strconv.FormatUint(tagID, 10) +
+				"/thing/" + strconv.FormatUint(thingID, 10),
 			contentType: fiber.MIMEApplicationJSON,
 		}
 	)
@@ -58,7 +57,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -67,7 +66,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
@@ -76,7 +75,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, req models.DeleteThingTagRequest) {
 					assert.Equal(mc, tagID, req.TagID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(nil)
@@ -88,7 +87,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			name: "negative case - request without tagID",
 			req: req{
 				method:      fiber.MethodDelete,
-				route:       "/v1/tags/" + gofakeit.Word() + "/thing/" + strconv.Itoa(thingID),
+				route:       "/v1/tags/" + gofakeit.Word() + "/thing/" + strconv.FormatUint(thingID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
@@ -106,7 +105,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			name: "negative case - request without thingID",
 			req: req{
 				method:      fiber.MethodDelete,
-				route:       "/v1/tags/" + strconv.Itoa(tagID) + "/thing/" + gofakeit.Word(),
+				route:       "/v1/tags/" + strconv.FormatUint(tagID, 10) + "/thing/" + gofakeit.Word(),
 				contentType: fiber.MIMEApplicationJSON,
 			},
 			resCode: fiber.StatusBadRequest,
@@ -127,7 +126,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -147,7 +146,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -167,7 +166,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -176,7 +175,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -193,7 +192,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -202,7 +201,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -219,7 +218,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, nil)
 
@@ -228,7 +227,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
@@ -237,7 +236,7 @@ func TestDeleteThingTagHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, req models.DeleteThingTagRequest) {
 					assert.Equal(mc, tagID, req.TagID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(testError)
@@ -262,11 +261,11 @@ func TestDeleteThingTagHandler(t *testing.T) {
 
 			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, nil)
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 3
internal/api/v1/tag/get_tag.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -24,21 +26,24 @@ import (
 func GetTagHandler(tagRepository TagRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("tagId")
+		id, err := request.ConvertToUint64(fctx, "tagId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := tagRepository.Get(ctx, id)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusNotFound, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToTagResponse(*res))
 	}

+ 12 - 11
internal/api/v1/tag/get_tag_test.go

@@ -3,7 +3,6 @@ package tag
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,13 +27,13 @@ func TestGetTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		tagID     = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/tags/" + strconv.Itoa(tagID),
+			route:  "/v1/tags/" + strconv.FormatUint(tagID, 10),
 		}
 
 		tagRepoRes = models.Tag{
@@ -70,7 +68,7 @@ func TestGetTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(&tagRepoRes, nil)
 
@@ -84,7 +82,7 @@ func TestGetTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -98,7 +96,7 @@ func TestGetTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -127,10 +125,13 @@ func TestGetTagHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/tags/:tagId", GetTagHandler(tt.tagRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 3
internal/api/v1/tag/get_tags.go

@@ -1,9 +1,10 @@
 package tag
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -18,12 +19,14 @@ import (
 // @Produce     json
 func GetTagsHandler(tagRepository TagRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
-		res, err := tagRepository.GetAll(fctx.Context())
+		ctx := fctx.Context()
+		res, err := tagRepository.GetAll(ctx)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToTagsResponse(res))
 	}

+ 9 - 8
internal/api/v1/tag/get_tags_test.go

@@ -1,7 +1,6 @@
 package tag
 
 import (
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -10,10 +9,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -26,7 +24,7 @@ func TestGetTagsHandler(t *testing.T) {
 	}
 
 	var (
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -36,14 +34,14 @@ func TestGetTagsHandler(t *testing.T) {
 
 		tagRepoRes = []models.Tag{
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        uint64(gofakeit.Number(1, 1000)),
 				Title:     "A" + gofakeit.Phrase(),
 				Style:     gofakeit.Phrase(),
 				CreatedAt: gofakeit.Date(),
 				UpdatedAt: gofakeit.Date(),
 			},
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        uint64(gofakeit.Number(1, 1000)),
 				Title:     "B" + gofakeit.Phrase(),
 				Style:     gofakeit.Phrase(),
 				CreatedAt: gofakeit.Date(),
@@ -109,10 +107,13 @@ func TestGetTagsHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/tags", GetTagsHandler(tt.tagRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 3
internal/api/v1/tag/get_thing_tags.go

@@ -1,9 +1,11 @@
 package tag
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -20,17 +22,20 @@ import (
 func GetThingTagsHandler(tagRepository TagRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := tagRepository.GetByThingID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToTagsResponse(res))
 	}

+ 13 - 12
internal/api/v1/tag/get_thing_tags_test.go

@@ -2,7 +2,6 @@ package tag
 
 import (
 	"context"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -28,25 +26,25 @@ func TestGetThingTagsHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/tags/thing/" + strconv.Itoa(thingID),
+			route:  "/v1/tags/thing/" + strconv.FormatUint(thingID, 10),
 		}
 
 		tagRepoRes = []models.Tag{
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        uint64(gofakeit.Number(1, 1000)),
 				Title:     "A" + gofakeit.Phrase(),
 				Style:     gofakeit.Phrase(),
 				CreatedAt: gofakeit.Date(),
 				UpdatedAt: gofakeit.Date(),
 			},
 			{
-				ID:        gofakeit.Number(1, 1000),
+				ID:        uint64(gofakeit.Number(1, 1000)),
 				Title:     "B" + gofakeit.Phrase(),
 				Style:     gofakeit.Phrase(),
 				CreatedAt: gofakeit.Date(),
@@ -89,7 +87,7 @@ func TestGetThingTagsHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(tagRepoRes, nil)
 
@@ -103,7 +101,7 @@ func TestGetThingTagsHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -132,10 +130,13 @@ func TestGetThingTagsHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/tags/thing/:thingId", GetThingTagsHandler(tt.tagRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

Різницю між файлами не показано, бо вона завелика
+ 43 - 727
internal/api/v1/tag/mocks/tag_repository_minimock.go


+ 24 - 24
internal/api/v1/tag/mocks/thing_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -19,8 +19,8 @@ type ThingRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcGet          func(ctx context.Context, thingID int) (tp1 *models.Thing, err error)
-	inspectFuncGet   func(ctx context.Context, thingID int)
+	funcGet          func(ctx context.Context, id uint64) (tp1 *models.Thing, err error)
+	inspectFuncGet   func(ctx context.Context, id uint64)
 	afterGetCounter  uint64
 	beforeGetCounter uint64
 	GetMock          mThingRepositoryMockGet
@@ -65,14 +65,14 @@ type ThingRepositoryMockGetExpectation struct {
 
 // ThingRepositoryMockGetParams contains parameters of the ThingRepository.Get
 type ThingRepositoryMockGetParams struct {
-	ctx     context.Context
-	thingID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingRepositoryMockGetParamPtrs contains pointers to parameters of the ThingRepository.Get
 type ThingRepositoryMockGetParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingRepositoryMockGetResults contains results of the ThingRepository.Get
@@ -92,7 +92,7 @@ func (mmGet *mThingRepositoryMockGet) Optional() *mThingRepositoryMockGet {
 }
 
 // Expect sets up expected params for ThingRepository.Get
-func (mmGet *mThingRepositoryMockGet) Expect(ctx context.Context, thingID int) *mThingRepositoryMockGet {
+func (mmGet *mThingRepositoryMockGet) Expect(ctx context.Context, id uint64) *mThingRepositoryMockGet {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingRepositoryMock.Get mock is already set by Set")
 	}
@@ -105,7 +105,7 @@ func (mmGet *mThingRepositoryMockGet) Expect(ctx context.Context, thingID int) *
 		mmGet.mock.t.Fatalf("ThingRepositoryMock.Get mock is already set by ExpectParams functions")
 	}
 
-	mmGet.defaultExpectation.params = &ThingRepositoryMockGetParams{ctx, thingID}
+	mmGet.defaultExpectation.params = &ThingRepositoryMockGetParams{ctx, id}
 	for _, e := range mmGet.expectations {
 		if minimock.Equal(e.params, mmGet.defaultExpectation.params) {
 			mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params)
@@ -137,8 +137,8 @@ func (mmGet *mThingRepositoryMockGet) ExpectCtxParam1(ctx context.Context) *mThi
 	return mmGet
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingRepository.Get
-func (mmGet *mThingRepositoryMockGet) ExpectThingIDParam2(thingID int) *mThingRepositoryMockGet {
+// ExpectIdParam2 sets up expected param id for ThingRepository.Get
+func (mmGet *mThingRepositoryMockGet) ExpectIdParam2(id uint64) *mThingRepositoryMockGet {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingRepositoryMock.Get mock is already set by Set")
 	}
@@ -154,13 +154,13 @@ func (mmGet *mThingRepositoryMockGet) ExpectThingIDParam2(thingID int) *mThingRe
 	if mmGet.defaultExpectation.paramPtrs == nil {
 		mmGet.defaultExpectation.paramPtrs = &ThingRepositoryMockGetParamPtrs{}
 	}
-	mmGet.defaultExpectation.paramPtrs.thingID = &thingID
+	mmGet.defaultExpectation.paramPtrs.id = &id
 
 	return mmGet
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingRepository.Get
-func (mmGet *mThingRepositoryMockGet) Inspect(f func(ctx context.Context, thingID int)) *mThingRepositoryMockGet {
+func (mmGet *mThingRepositoryMockGet) Inspect(f func(ctx context.Context, id uint64)) *mThingRepositoryMockGet {
 	if mmGet.mock.inspectFuncGet != nil {
 		mmGet.mock.t.Fatalf("Inspect function is already set for ThingRepositoryMock.Get")
 	}
@@ -184,7 +184,7 @@ func (mmGet *mThingRepositoryMockGet) Return(tp1 *models.Thing, err error) *Thin
 }
 
 // Set uses given function f to mock the ThingRepository.Get method
-func (mmGet *mThingRepositoryMockGet) Set(f func(ctx context.Context, thingID int) (tp1 *models.Thing, err error)) *ThingRepositoryMock {
+func (mmGet *mThingRepositoryMockGet) Set(f func(ctx context.Context, id uint64) (tp1 *models.Thing, err error)) *ThingRepositoryMock {
 	if mmGet.defaultExpectation != nil {
 		mmGet.mock.t.Fatalf("Default expectation is already set for the ThingRepository.Get method")
 	}
@@ -199,14 +199,14 @@ func (mmGet *mThingRepositoryMockGet) Set(f func(ctx context.Context, thingID in
 
 // When sets expectation for the ThingRepository.Get which will trigger the result defined by the following
 // Then helper
-func (mmGet *mThingRepositoryMockGet) When(ctx context.Context, thingID int) *ThingRepositoryMockGetExpectation {
+func (mmGet *mThingRepositoryMockGet) When(ctx context.Context, id uint64) *ThingRepositoryMockGetExpectation {
 	if mmGet.mock.funcGet != nil {
 		mmGet.mock.t.Fatalf("ThingRepositoryMock.Get mock is already set by Set")
 	}
 
 	expectation := &ThingRepositoryMockGetExpectation{
 		mock:   mmGet.mock,
-		params: &ThingRepositoryMockGetParams{ctx, thingID},
+		params: &ThingRepositoryMockGetParams{ctx, id},
 	}
 	mmGet.expectations = append(mmGet.expectations, expectation)
 	return expectation
@@ -239,15 +239,15 @@ func (mmGet *mThingRepositoryMockGet) invocationsDone() bool {
 }
 
 // Get implements tag.ThingRepository
-func (mmGet *ThingRepositoryMock) Get(ctx context.Context, thingID int) (tp1 *models.Thing, err error) {
+func (mmGet *ThingRepositoryMock) Get(ctx context.Context, id uint64) (tp1 *models.Thing, err error) {
 	mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1)
 	defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1)
 
 	if mmGet.inspectFuncGet != nil {
-		mmGet.inspectFuncGet(ctx, thingID)
+		mmGet.inspectFuncGet(ctx, id)
 	}
 
-	mm_params := ThingRepositoryMockGetParams{ctx, thingID}
+	mm_params := ThingRepositoryMockGetParams{ctx, id}
 
 	// Record call args
 	mmGet.GetMock.mutex.Lock()
@@ -266,7 +266,7 @@ func (mmGet *ThingRepositoryMock) Get(ctx context.Context, thingID int) (tp1 *mo
 		mm_want := mmGet.GetMock.defaultExpectation.params
 		mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingRepositoryMockGetParams{ctx, thingID}
+		mm_got := ThingRepositoryMockGetParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -274,8 +274,8 @@ func (mmGet *ThingRepositoryMock) Get(ctx context.Context, thingID int) (tp1 *mo
 				mmGet.t.Errorf("ThingRepositoryMock.Get got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmGet.t.Errorf("ThingRepositoryMock.Get got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGet.t.Errorf("ThingRepositoryMock.Get got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -289,9 +289,9 @@ func (mmGet *ThingRepositoryMock) Get(ctx context.Context, thingID int) (tp1 *mo
 		return (*mm_results).tp1, (*mm_results).err
 	}
 	if mmGet.funcGet != nil {
-		return mmGet.funcGet(ctx, thingID)
+		return mmGet.funcGet(ctx, id)
 	}
-	mmGet.t.Fatalf("Unexpected call to ThingRepositoryMock.Get. %v %v", ctx, thingID)
+	mmGet.t.Fatalf("Unexpected call to ThingRepositoryMock.Get. %v %v", ctx, id)
 	return
 }
 

+ 52 - 137
internal/api/v1/tag/mocks/thing_tag_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,20 +19,20 @@ type ThingTagRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcAdd          func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) (err error)
-	inspectFuncAdd   func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx)
+	funcAdd          func(ctx context.Context, req models.AddThingTagRequest) (err error)
+	inspectFuncAdd   func(ctx context.Context, req models.AddThingTagRequest)
 	afterAddCounter  uint64
 	beforeAddCounter uint64
 	AddMock          mThingTagRepositoryMockAdd
 
-	funcDelete          func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, req models.DeleteThingTagRequest) (err error)
+	inspectFuncDelete   func(ctx context.Context, req models.DeleteThingTagRequest)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingTagRepositoryMockDelete
 
-	funcDeleteByTagID          func(ctx context.Context, tagID int, tx *sql.Tx) (err error)
-	inspectFuncDeleteByTagID   func(ctx context.Context, tagID int, tx *sql.Tx)
+	funcDeleteByTagID          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDeleteByTagID   func(ctx context.Context, id uint64)
 	afterDeleteByTagIDCounter  uint64
 	beforeDeleteByTagIDCounter uint64
 	DeleteByTagIDMock          mThingTagRepositoryMockDeleteByTagID
@@ -86,14 +85,12 @@ type ThingTagRepositoryMockAddExpectation struct {
 type ThingTagRepositoryMockAddParams struct {
 	ctx context.Context
 	req models.AddThingTagRequest
-	tx  *sql.Tx
 }
 
 // ThingTagRepositoryMockAddParamPtrs contains pointers to parameters of the ThingTagRepository.Add
 type ThingTagRepositoryMockAddParamPtrs struct {
 	ctx *context.Context
 	req *models.AddThingTagRequest
-	tx  **sql.Tx
 }
 
 // ThingTagRepositoryMockAddResults contains results of the ThingTagRepository.Add
@@ -112,7 +109,7 @@ func (mmAdd *mThingTagRepositoryMockAdd) Optional() *mThingTagRepositoryMockAdd
 }
 
 // Expect sets up expected params for ThingTagRepository.Add
-func (mmAdd *mThingTagRepositoryMockAdd) Expect(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) *mThingTagRepositoryMockAdd {
+func (mmAdd *mThingTagRepositoryMockAdd) Expect(ctx context.Context, req models.AddThingTagRequest) *mThingTagRepositoryMockAdd {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("ThingTagRepositoryMock.Add mock is already set by Set")
 	}
@@ -125,7 +122,7 @@ func (mmAdd *mThingTagRepositoryMockAdd) Expect(ctx context.Context, req models.
 		mmAdd.mock.t.Fatalf("ThingTagRepositoryMock.Add mock is already set by ExpectParams functions")
 	}
 
-	mmAdd.defaultExpectation.params = &ThingTagRepositoryMockAddParams{ctx, req, tx}
+	mmAdd.defaultExpectation.params = &ThingTagRepositoryMockAddParams{ctx, req}
 	for _, e := range mmAdd.expectations {
 		if minimock.Equal(e.params, mmAdd.defaultExpectation.params) {
 			mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params)
@@ -179,30 +176,8 @@ func (mmAdd *mThingTagRepositoryMockAdd) ExpectReqParam2(req models.AddThingTagR
 	return mmAdd
 }
 
-// ExpectTxParam3 sets up expected param tx for ThingTagRepository.Add
-func (mmAdd *mThingTagRepositoryMockAdd) ExpectTxParam3(tx *sql.Tx) *mThingTagRepositoryMockAdd {
-	if mmAdd.mock.funcAdd != nil {
-		mmAdd.mock.t.Fatalf("ThingTagRepositoryMock.Add mock is already set by Set")
-	}
-
-	if mmAdd.defaultExpectation == nil {
-		mmAdd.defaultExpectation = &ThingTagRepositoryMockAddExpectation{}
-	}
-
-	if mmAdd.defaultExpectation.params != nil {
-		mmAdd.mock.t.Fatalf("ThingTagRepositoryMock.Add mock is already set by Expect")
-	}
-
-	if mmAdd.defaultExpectation.paramPtrs == nil {
-		mmAdd.defaultExpectation.paramPtrs = &ThingTagRepositoryMockAddParamPtrs{}
-	}
-	mmAdd.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmAdd
-}
-
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.Add
-func (mmAdd *mThingTagRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx)) *mThingTagRepositoryMockAdd {
+func (mmAdd *mThingTagRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddThingTagRequest)) *mThingTagRepositoryMockAdd {
 	if mmAdd.mock.inspectFuncAdd != nil {
 		mmAdd.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.Add")
 	}
@@ -226,7 +201,7 @@ func (mmAdd *mThingTagRepositoryMockAdd) Return(err error) *ThingTagRepositoryMo
 }
 
 // Set uses given function f to mock the ThingTagRepository.Add method
-func (mmAdd *mThingTagRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) (err error)) *ThingTagRepositoryMock {
+func (mmAdd *mThingTagRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddThingTagRequest) (err error)) *ThingTagRepositoryMock {
 	if mmAdd.defaultExpectation != nil {
 		mmAdd.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.Add method")
 	}
@@ -241,14 +216,14 @@ func (mmAdd *mThingTagRepositoryMockAdd) Set(f func(ctx context.Context, req mod
 
 // When sets expectation for the ThingTagRepository.Add which will trigger the result defined by the following
 // Then helper
-func (mmAdd *mThingTagRepositoryMockAdd) When(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) *ThingTagRepositoryMockAddExpectation {
+func (mmAdd *mThingTagRepositoryMockAdd) When(ctx context.Context, req models.AddThingTagRequest) *ThingTagRepositoryMockAddExpectation {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("ThingTagRepositoryMock.Add mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockAddExpectation{
 		mock:   mmAdd.mock,
-		params: &ThingTagRepositoryMockAddParams{ctx, req, tx},
+		params: &ThingTagRepositoryMockAddParams{ctx, req},
 	}
 	mmAdd.expectations = append(mmAdd.expectations, expectation)
 	return expectation
@@ -281,15 +256,15 @@ func (mmAdd *mThingTagRepositoryMockAdd) invocationsDone() bool {
 }
 
 // Add implements tag.ThingTagRepository
-func (mmAdd *ThingTagRepositoryMock) Add(ctx context.Context, req models.AddThingTagRequest, tx *sql.Tx) (err error) {
+func (mmAdd *ThingTagRepositoryMock) Add(ctx context.Context, req models.AddThingTagRequest) (err error) {
 	mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1)
 	defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1)
 
 	if mmAdd.inspectFuncAdd != nil {
-		mmAdd.inspectFuncAdd(ctx, req, tx)
+		mmAdd.inspectFuncAdd(ctx, req)
 	}
 
-	mm_params := ThingTagRepositoryMockAddParams{ctx, req, tx}
+	mm_params := ThingTagRepositoryMockAddParams{ctx, req}
 
 	// Record call args
 	mmAdd.AddMock.mutex.Lock()
@@ -308,7 +283,7 @@ func (mmAdd *ThingTagRepositoryMock) Add(ctx context.Context, req models.AddThin
 		mm_want := mmAdd.AddMock.defaultExpectation.params
 		mm_want_ptrs := mmAdd.AddMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockAddParams{ctx, req, tx}
+		mm_got := ThingTagRepositoryMockAddParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -320,10 +295,6 @@ func (mmAdd *ThingTagRepositoryMock) Add(ctx context.Context, req models.AddThin
 				mmAdd.t.Errorf("ThingTagRepositoryMock.Add got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmAdd.t.Errorf("ThingTagRepositoryMock.Add got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmAdd.t.Errorf("ThingTagRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -335,9 +306,9 @@ func (mmAdd *ThingTagRepositoryMock) Add(ctx context.Context, req models.AddThin
 		return (*mm_results).err
 	}
 	if mmAdd.funcAdd != nil {
-		return mmAdd.funcAdd(ctx, req, tx)
+		return mmAdd.funcAdd(ctx, req)
 	}
-	mmAdd.t.Fatalf("Unexpected call to ThingTagRepositoryMock.Add. %v %v %v", ctx, req, tx)
+	mmAdd.t.Fatalf("Unexpected call to ThingTagRepositoryMock.Add. %v %v", ctx, req)
 	return
 }
 
@@ -434,14 +405,12 @@ type ThingTagRepositoryMockDeleteExpectation struct {
 type ThingTagRepositoryMockDeleteParams struct {
 	ctx context.Context
 	req models.DeleteThingTagRequest
-	tx  *sql.Tx
 }
 
 // ThingTagRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingTagRepository.Delete
 type ThingTagRepositoryMockDeleteParamPtrs struct {
 	ctx *context.Context
 	req *models.DeleteThingTagRequest
-	tx  **sql.Tx
 }
 
 // ThingTagRepositoryMockDeleteResults contains results of the ThingTagRepository.Delete
@@ -460,7 +429,7 @@ func (mmDelete *mThingTagRepositoryMockDelete) Optional() *mThingTagRepositoryMo
 }
 
 // Expect sets up expected params for ThingTagRepository.Delete
-func (mmDelete *mThingTagRepositoryMockDelete) Expect(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) *mThingTagRepositoryMockDelete {
+func (mmDelete *mThingTagRepositoryMockDelete) Expect(ctx context.Context, req models.DeleteThingTagRequest) *mThingTagRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingTagRepositoryMock.Delete mock is already set by Set")
 	}
@@ -473,7 +442,7 @@ func (mmDelete *mThingTagRepositoryMockDelete) Expect(ctx context.Context, req m
 		mmDelete.mock.t.Fatalf("ThingTagRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingTagRepositoryMockDeleteParams{ctx, req, tx}
+	mmDelete.defaultExpectation.params = &ThingTagRepositoryMockDeleteParams{ctx, req}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -527,30 +496,8 @@ func (mmDelete *mThingTagRepositoryMockDelete) ExpectReqParam2(req models.Delete
 	return mmDelete
 }
 
-// ExpectTxParam3 sets up expected param tx for ThingTagRepository.Delete
-func (mmDelete *mThingTagRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingTagRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingTagRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingTagRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingTagRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmDelete
-}
-
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.Delete
-func (mmDelete *mThingTagRepositoryMockDelete) Inspect(f func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx)) *mThingTagRepositoryMockDelete {
+func (mmDelete *mThingTagRepositoryMockDelete) Inspect(f func(ctx context.Context, req models.DeleteThingTagRequest)) *mThingTagRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.Delete")
 	}
@@ -574,7 +521,7 @@ func (mmDelete *mThingTagRepositoryMockDelete) Return(err error) *ThingTagReposi
 }
 
 // Set uses given function f to mock the ThingTagRepository.Delete method
-func (mmDelete *mThingTagRepositoryMockDelete) Set(f func(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) (err error)) *ThingTagRepositoryMock {
+func (mmDelete *mThingTagRepositoryMockDelete) Set(f func(ctx context.Context, req models.DeleteThingTagRequest) (err error)) *ThingTagRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.Delete method")
 	}
@@ -589,14 +536,14 @@ func (mmDelete *mThingTagRepositoryMockDelete) Set(f func(ctx context.Context, r
 
 // When sets expectation for the ThingTagRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingTagRepositoryMockDelete) When(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) *ThingTagRepositoryMockDeleteExpectation {
+func (mmDelete *mThingTagRepositoryMockDelete) When(ctx context.Context, req models.DeleteThingTagRequest) *ThingTagRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingTagRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingTagRepositoryMockDeleteParams{ctx, req, tx},
+		params: &ThingTagRepositoryMockDeleteParams{ctx, req},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -629,15 +576,15 @@ func (mmDelete *mThingTagRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements tag.ThingTagRepository
-func (mmDelete *ThingTagRepositoryMock) Delete(ctx context.Context, req models.DeleteThingTagRequest, tx *sql.Tx) (err error) {
+func (mmDelete *ThingTagRepositoryMock) Delete(ctx context.Context, req models.DeleteThingTagRequest) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, req, tx)
+		mmDelete.inspectFuncDelete(ctx, req)
 	}
 
-	mm_params := ThingTagRepositoryMockDeleteParams{ctx, req, tx}
+	mm_params := ThingTagRepositoryMockDeleteParams{ctx, req}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -656,7 +603,7 @@ func (mmDelete *ThingTagRepositoryMock) Delete(ctx context.Context, req models.D
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockDeleteParams{ctx, req, tx}
+		mm_got := ThingTagRepositoryMockDeleteParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -668,10 +615,6 @@ func (mmDelete *ThingTagRepositoryMock) Delete(ctx context.Context, req models.D
 				mmDelete.t.Errorf("ThingTagRepositoryMock.Delete got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingTagRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmDelete.t.Errorf("ThingTagRepositoryMock.Delete got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -683,9 +626,9 @@ func (mmDelete *ThingTagRepositoryMock) Delete(ctx context.Context, req models.D
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, req, tx)
+		return mmDelete.funcDelete(ctx, req)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingTagRepositoryMock.Delete. %v %v %v", ctx, req, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingTagRepositoryMock.Delete. %v %v", ctx, req)
 	return
 }
 
@@ -780,16 +723,14 @@ type ThingTagRepositoryMockDeleteByTagIDExpectation struct {
 
 // ThingTagRepositoryMockDeleteByTagIDParams contains parameters of the ThingTagRepository.DeleteByTagID
 type ThingTagRepositoryMockDeleteByTagIDParams struct {
-	ctx   context.Context
-	tagID int
-	tx    *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingTagRepositoryMockDeleteByTagIDParamPtrs contains pointers to parameters of the ThingTagRepository.DeleteByTagID
 type ThingTagRepositoryMockDeleteByTagIDParamPtrs struct {
-	ctx   *context.Context
-	tagID *int
-	tx    **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingTagRepositoryMockDeleteByTagIDResults contains results of the ThingTagRepository.DeleteByTagID
@@ -808,7 +749,7 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Optional() *mThingT
 }
 
 // Expect sets up expected params for ThingTagRepository.DeleteByTagID
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Expect(ctx context.Context, tagID int, tx *sql.Tx) *mThingTagRepositoryMockDeleteByTagID {
+func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Expect(ctx context.Context, id uint64) *mThingTagRepositoryMockDeleteByTagID {
 	if mmDeleteByTagID.mock.funcDeleteByTagID != nil {
 		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by Set")
 	}
@@ -821,7 +762,7 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Expect(ctx context.
 		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by ExpectParams functions")
 	}
 
-	mmDeleteByTagID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByTagIDParams{ctx, tagID, tx}
+	mmDeleteByTagID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByTagIDParams{ctx, id}
 	for _, e := range mmDeleteByTagID.expectations {
 		if minimock.Equal(e.params, mmDeleteByTagID.defaultExpectation.params) {
 			mmDeleteByTagID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteByTagID.defaultExpectation.params)
@@ -853,30 +794,8 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) ExpectCtxParam1(ctx
 	return mmDeleteByTagID
 }
 
-// ExpectTagIDParam2 sets up expected param tagID for ThingTagRepository.DeleteByTagID
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) ExpectTagIDParam2(tagID int) *mThingTagRepositoryMockDeleteByTagID {
-	if mmDeleteByTagID.mock.funcDeleteByTagID != nil {
-		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by Set")
-	}
-
-	if mmDeleteByTagID.defaultExpectation == nil {
-		mmDeleteByTagID.defaultExpectation = &ThingTagRepositoryMockDeleteByTagIDExpectation{}
-	}
-
-	if mmDeleteByTagID.defaultExpectation.params != nil {
-		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by Expect")
-	}
-
-	if mmDeleteByTagID.defaultExpectation.paramPtrs == nil {
-		mmDeleteByTagID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByTagIDParamPtrs{}
-	}
-	mmDeleteByTagID.defaultExpectation.paramPtrs.tagID = &tagID
-
-	return mmDeleteByTagID
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingTagRepository.DeleteByTagID
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) ExpectTxParam3(tx *sql.Tx) *mThingTagRepositoryMockDeleteByTagID {
+// ExpectIdParam2 sets up expected param id for ThingTagRepository.DeleteByTagID
+func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) ExpectIdParam2(id uint64) *mThingTagRepositoryMockDeleteByTagID {
 	if mmDeleteByTagID.mock.funcDeleteByTagID != nil {
 		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by Set")
 	}
@@ -892,13 +811,13 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) ExpectTxParam3(tx *
 	if mmDeleteByTagID.defaultExpectation.paramPtrs == nil {
 		mmDeleteByTagID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByTagIDParamPtrs{}
 	}
-	mmDeleteByTagID.defaultExpectation.paramPtrs.tx = &tx
+	mmDeleteByTagID.defaultExpectation.paramPtrs.id = &id
 
 	return mmDeleteByTagID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.DeleteByTagID
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Inspect(f func(ctx context.Context, tagID int, tx *sql.Tx)) *mThingTagRepositoryMockDeleteByTagID {
+func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Inspect(f func(ctx context.Context, id uint64)) *mThingTagRepositoryMockDeleteByTagID {
 	if mmDeleteByTagID.mock.inspectFuncDeleteByTagID != nil {
 		mmDeleteByTagID.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.DeleteByTagID")
 	}
@@ -922,7 +841,7 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Return(err error) *
 }
 
 // Set uses given function f to mock the ThingTagRepository.DeleteByTagID method
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Set(f func(ctx context.Context, tagID int, tx *sql.Tx) (err error)) *ThingTagRepositoryMock {
+func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Set(f func(ctx context.Context, id uint64) (err error)) *ThingTagRepositoryMock {
 	if mmDeleteByTagID.defaultExpectation != nil {
 		mmDeleteByTagID.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.DeleteByTagID method")
 	}
@@ -937,14 +856,14 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) Set(f func(ctx cont
 
 // When sets expectation for the ThingTagRepository.DeleteByTagID which will trigger the result defined by the following
 // Then helper
-func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) When(ctx context.Context, tagID int, tx *sql.Tx) *ThingTagRepositoryMockDeleteByTagIDExpectation {
+func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) When(ctx context.Context, id uint64) *ThingTagRepositoryMockDeleteByTagIDExpectation {
 	if mmDeleteByTagID.mock.funcDeleteByTagID != nil {
 		mmDeleteByTagID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByTagID mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockDeleteByTagIDExpectation{
 		mock:   mmDeleteByTagID.mock,
-		params: &ThingTagRepositoryMockDeleteByTagIDParams{ctx, tagID, tx},
+		params: &ThingTagRepositoryMockDeleteByTagIDParams{ctx, id},
 	}
 	mmDeleteByTagID.expectations = append(mmDeleteByTagID.expectations, expectation)
 	return expectation
@@ -977,15 +896,15 @@ func (mmDeleteByTagID *mThingTagRepositoryMockDeleteByTagID) invocationsDone() b
 }
 
 // DeleteByTagID implements tag.ThingTagRepository
-func (mmDeleteByTagID *ThingTagRepositoryMock) DeleteByTagID(ctx context.Context, tagID int, tx *sql.Tx) (err error) {
+func (mmDeleteByTagID *ThingTagRepositoryMock) DeleteByTagID(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDeleteByTagID.beforeDeleteByTagIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmDeleteByTagID.afterDeleteByTagIDCounter, 1)
 
 	if mmDeleteByTagID.inspectFuncDeleteByTagID != nil {
-		mmDeleteByTagID.inspectFuncDeleteByTagID(ctx, tagID, tx)
+		mmDeleteByTagID.inspectFuncDeleteByTagID(ctx, id)
 	}
 
-	mm_params := ThingTagRepositoryMockDeleteByTagIDParams{ctx, tagID, tx}
+	mm_params := ThingTagRepositoryMockDeleteByTagIDParams{ctx, id}
 
 	// Record call args
 	mmDeleteByTagID.DeleteByTagIDMock.mutex.Lock()
@@ -1004,7 +923,7 @@ func (mmDeleteByTagID *ThingTagRepositoryMock) DeleteByTagID(ctx context.Context
 		mm_want := mmDeleteByTagID.DeleteByTagIDMock.defaultExpectation.params
 		mm_want_ptrs := mmDeleteByTagID.DeleteByTagIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockDeleteByTagIDParams{ctx, tagID, tx}
+		mm_got := ThingTagRepositoryMockDeleteByTagIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -1012,12 +931,8 @@ func (mmDeleteByTagID *ThingTagRepositoryMock) DeleteByTagID(ctx context.Context
 				mmDeleteByTagID.t.Errorf("ThingTagRepositoryMock.DeleteByTagID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.tagID != nil && !minimock.Equal(*mm_want_ptrs.tagID, mm_got.tagID) {
-				mmDeleteByTagID.t.Errorf("ThingTagRepositoryMock.DeleteByTagID got unexpected parameter tagID, want: %#v, got: %#v%s\n", *mm_want_ptrs.tagID, mm_got.tagID, minimock.Diff(*mm_want_ptrs.tagID, mm_got.tagID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDeleteByTagID.t.Errorf("ThingTagRepositoryMock.DeleteByTagID got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDeleteByTagID.t.Errorf("ThingTagRepositoryMock.DeleteByTagID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -1031,9 +946,9 @@ func (mmDeleteByTagID *ThingTagRepositoryMock) DeleteByTagID(ctx context.Context
 		return (*mm_results).err
 	}
 	if mmDeleteByTagID.funcDeleteByTagID != nil {
-		return mmDeleteByTagID.funcDeleteByTagID(ctx, tagID, tx)
+		return mmDeleteByTagID.funcDeleteByTagID(ctx, id)
 	}
-	mmDeleteByTagID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByTagID. %v %v %v", ctx, tagID, tx)
+	mmDeleteByTagID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByTagID. %v %v", ctx, id)
 	return
 }
 

+ 393 - 0
internal/api/v1/tag/mocks/transaction_manager_minimock.go

@@ -0,0 +1,393 @@
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
+
+package mocks
+
+//go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag.TransactionManager -o transaction_manager_minimock.go -n TransactionManagerMock -p mocks
+
+import (
+	"context"
+	"sync"
+	mm_atomic "sync/atomic"
+	mm_time "time"
+
+	"github.com/gojuno/minimock/v3"
+)
+
+// TransactionManagerMock implements tag.TransactionManager
+type TransactionManagerMock struct {
+	t          minimock.Tester
+	finishOnce sync.Once
+
+	funcReadCommitted          func(ctx context.Context, f1 func(ctx context.Context) error) (err error)
+	inspectFuncReadCommitted   func(ctx context.Context, f1 func(ctx context.Context) error)
+	afterReadCommittedCounter  uint64
+	beforeReadCommittedCounter uint64
+	ReadCommittedMock          mTransactionManagerMockReadCommitted
+}
+
+// NewTransactionManagerMock returns a mock for tag.TransactionManager
+func NewTransactionManagerMock(t minimock.Tester) *TransactionManagerMock {
+	m := &TransactionManagerMock{t: t}
+
+	if controller, ok := t.(minimock.MockController); ok {
+		controller.RegisterMocker(m)
+	}
+
+	m.ReadCommittedMock = mTransactionManagerMockReadCommitted{mock: m}
+	m.ReadCommittedMock.callArgs = []*TransactionManagerMockReadCommittedParams{}
+
+	t.Cleanup(m.MinimockFinish)
+
+	return m
+}
+
+type mTransactionManagerMockReadCommitted struct {
+	optional           bool
+	mock               *TransactionManagerMock
+	defaultExpectation *TransactionManagerMockReadCommittedExpectation
+	expectations       []*TransactionManagerMockReadCommittedExpectation
+
+	callArgs []*TransactionManagerMockReadCommittedParams
+	mutex    sync.RWMutex
+
+	expectedInvocations uint64
+}
+
+// TransactionManagerMockReadCommittedExpectation specifies expectation struct of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedExpectation struct {
+	mock      *TransactionManagerMock
+	params    *TransactionManagerMockReadCommittedParams
+	paramPtrs *TransactionManagerMockReadCommittedParamPtrs
+	results   *TransactionManagerMockReadCommittedResults
+	Counter   uint64
+}
+
+// TransactionManagerMockReadCommittedParams contains parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParams struct {
+	ctx context.Context
+	f1  func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedParamPtrs contains pointers to parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParamPtrs struct {
+	ctx *context.Context
+	f1  *func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedResults contains results of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedResults struct {
+	err error
+}
+
+// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
+// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
+// Optional() makes method check to work in '0 or more' mode.
+// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
+// catch the problems when the expected method call is totally skipped during test run.
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Optional() *mTransactionManagerMockReadCommitted {
+	mmReadCommitted.optional = true
+	return mmReadCommitted
+}
+
+// Expect sets up expected params for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Expect(ctx context.Context, f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by ExpectParams functions")
+	}
+
+	mmReadCommitted.defaultExpectation.params = &TransactionManagerMockReadCommittedParams{ctx, f1}
+	for _, e := range mmReadCommitted.expectations {
+		if minimock.Equal(e.params, mmReadCommitted.defaultExpectation.params) {
+			mmReadCommitted.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmReadCommitted.defaultExpectation.params)
+		}
+	}
+
+	return mmReadCommitted
+}
+
+// ExpectCtxParam1 sets up expected param ctx for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectCtxParam1(ctx context.Context) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.ctx = &ctx
+
+	return mmReadCommitted
+}
+
+// ExpectF1Param2 sets up expected param f1 for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectF1Param2(f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.f1 = &f1
+
+	return mmReadCommitted
+}
+
+// Inspect accepts an inspector function that has same arguments as the TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Inspect(f func(ctx context.Context, f1 func(ctx context.Context) error)) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.inspectFuncReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("Inspect function is already set for TransactionManagerMock.ReadCommitted")
+	}
+
+	mmReadCommitted.mock.inspectFuncReadCommitted = f
+
+	return mmReadCommitted
+}
+
+// Return sets up results that will be returned by TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Return(err error) *TransactionManagerMock {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{mock: mmReadCommitted.mock}
+	}
+	mmReadCommitted.defaultExpectation.results = &TransactionManagerMockReadCommittedResults{err}
+	return mmReadCommitted.mock
+}
+
+// Set uses given function f to mock the TransactionManager.ReadCommitted method
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Set(f func(ctx context.Context, f1 func(ctx context.Context) error) (err error)) *TransactionManagerMock {
+	if mmReadCommitted.defaultExpectation != nil {
+		mmReadCommitted.mock.t.Fatalf("Default expectation is already set for the TransactionManager.ReadCommitted method")
+	}
+
+	if len(mmReadCommitted.expectations) > 0 {
+		mmReadCommitted.mock.t.Fatalf("Some expectations are already set for the TransactionManager.ReadCommitted method")
+	}
+
+	mmReadCommitted.mock.funcReadCommitted = f
+	return mmReadCommitted.mock
+}
+
+// When sets expectation for the TransactionManager.ReadCommitted which will trigger the result defined by the following
+// Then helper
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) When(ctx context.Context, f1 func(ctx context.Context) error) *TransactionManagerMockReadCommittedExpectation {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	expectation := &TransactionManagerMockReadCommittedExpectation{
+		mock:   mmReadCommitted.mock,
+		params: &TransactionManagerMockReadCommittedParams{ctx, f1},
+	}
+	mmReadCommitted.expectations = append(mmReadCommitted.expectations, expectation)
+	return expectation
+}
+
+// Then sets up TransactionManager.ReadCommitted return parameters for the expectation previously defined by the When method
+func (e *TransactionManagerMockReadCommittedExpectation) Then(err error) *TransactionManagerMock {
+	e.results = &TransactionManagerMockReadCommittedResults{err}
+	return e.mock
+}
+
+// Times sets number of times TransactionManager.ReadCommitted should be invoked
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Times(n uint64) *mTransactionManagerMockReadCommitted {
+	if n == 0 {
+		mmReadCommitted.mock.t.Fatalf("Times of TransactionManagerMock.ReadCommitted mock can not be zero")
+	}
+	mm_atomic.StoreUint64(&mmReadCommitted.expectedInvocations, n)
+	return mmReadCommitted
+}
+
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) invocationsDone() bool {
+	if len(mmReadCommitted.expectations) == 0 && mmReadCommitted.defaultExpectation == nil && mmReadCommitted.mock.funcReadCommitted == nil {
+		return true
+	}
+
+	totalInvocations := mm_atomic.LoadUint64(&mmReadCommitted.mock.afterReadCommittedCounter)
+	expectedInvocations := mm_atomic.LoadUint64(&mmReadCommitted.expectedInvocations)
+
+	return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
+}
+
+// ReadCommitted implements tag.TransactionManager
+func (mmReadCommitted *TransactionManagerMock) ReadCommitted(ctx context.Context, f1 func(ctx context.Context) error) (err error) {
+	mm_atomic.AddUint64(&mmReadCommitted.beforeReadCommittedCounter, 1)
+	defer mm_atomic.AddUint64(&mmReadCommitted.afterReadCommittedCounter, 1)
+
+	if mmReadCommitted.inspectFuncReadCommitted != nil {
+		mmReadCommitted.inspectFuncReadCommitted(ctx, f1)
+	}
+
+	mm_params := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+	// Record call args
+	mmReadCommitted.ReadCommittedMock.mutex.Lock()
+	mmReadCommitted.ReadCommittedMock.callArgs = append(mmReadCommitted.ReadCommittedMock.callArgs, &mm_params)
+	mmReadCommitted.ReadCommittedMock.mutex.Unlock()
+
+	for _, e := range mmReadCommitted.ReadCommittedMock.expectations {
+		if minimock.Equal(*e.params, mm_params) {
+			mm_atomic.AddUint64(&e.Counter, 1)
+			return e.results.err
+		}
+	}
+
+	if mmReadCommitted.ReadCommittedMock.defaultExpectation != nil {
+		mm_atomic.AddUint64(&mmReadCommitted.ReadCommittedMock.defaultExpectation.Counter, 1)
+		mm_want := mmReadCommitted.ReadCommittedMock.defaultExpectation.params
+		mm_want_ptrs := mmReadCommitted.ReadCommittedMock.defaultExpectation.paramPtrs
+
+		mm_got := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+		if mm_want_ptrs != nil {
+
+			if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
+			}
+
+			if mm_want_ptrs.f1 != nil && !minimock.Equal(*mm_want_ptrs.f1, mm_got.f1) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter f1, want: %#v, got: %#v%s\n", *mm_want_ptrs.f1, mm_got.f1, minimock.Diff(*mm_want_ptrs.f1, mm_got.f1))
+			}
+
+		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
+			mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
+		}
+
+		mm_results := mmReadCommitted.ReadCommittedMock.defaultExpectation.results
+		if mm_results == nil {
+			mmReadCommitted.t.Fatal("No results are set for the TransactionManagerMock.ReadCommitted")
+		}
+		return (*mm_results).err
+	}
+	if mmReadCommitted.funcReadCommitted != nil {
+		return mmReadCommitted.funcReadCommitted(ctx, f1)
+	}
+	mmReadCommitted.t.Fatalf("Unexpected call to TransactionManagerMock.ReadCommitted. %v %v", ctx, f1)
+	return
+}
+
+// ReadCommittedAfterCounter returns a count of finished TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedAfterCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.afterReadCommittedCounter)
+}
+
+// ReadCommittedBeforeCounter returns a count of TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedBeforeCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.beforeReadCommittedCounter)
+}
+
+// Calls returns a list of arguments used in each call to TransactionManagerMock.ReadCommitted.
+// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Calls() []*TransactionManagerMockReadCommittedParams {
+	mmReadCommitted.mutex.RLock()
+
+	argCopy := make([]*TransactionManagerMockReadCommittedParams, len(mmReadCommitted.callArgs))
+	copy(argCopy, mmReadCommitted.callArgs)
+
+	mmReadCommitted.mutex.RUnlock()
+
+	return argCopy
+}
+
+// MinimockReadCommittedDone returns true if the count of the ReadCommitted invocations corresponds
+// the number of defined expectations
+func (m *TransactionManagerMock) MinimockReadCommittedDone() bool {
+	if m.ReadCommittedMock.optional {
+		// Optional methods provide '0 or more' call count restriction.
+		return true
+	}
+
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			return false
+		}
+	}
+
+	return m.ReadCommittedMock.invocationsDone()
+}
+
+// MinimockReadCommittedInspect logs each unmet expectation
+func (m *TransactionManagerMock) MinimockReadCommittedInspect() {
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *e.params)
+		}
+	}
+
+	afterReadCommittedCounter := mm_atomic.LoadUint64(&m.afterReadCommittedCounter)
+	// if default expectation was set then invocations count should be greater than zero
+	if m.ReadCommittedMock.defaultExpectation != nil && afterReadCommittedCounter < 1 {
+		if m.ReadCommittedMock.defaultExpectation.params == nil {
+			m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+		} else {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *m.ReadCommittedMock.defaultExpectation.params)
+		}
+	}
+	// if func was set then invocations count should be greater than zero
+	if m.funcReadCommitted != nil && afterReadCommittedCounter < 1 {
+		m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+	}
+
+	if !m.ReadCommittedMock.invocationsDone() && afterReadCommittedCounter > 0 {
+		m.t.Errorf("Expected %d calls to TransactionManagerMock.ReadCommitted but found %d calls",
+			mm_atomic.LoadUint64(&m.ReadCommittedMock.expectedInvocations), afterReadCommittedCounter)
+	}
+}
+
+// MinimockFinish checks that all mocked methods have been called the expected number of times
+func (m *TransactionManagerMock) MinimockFinish() {
+	m.finishOnce.Do(func() {
+		if !m.minimockDone() {
+			m.MinimockReadCommittedInspect()
+		}
+	})
+}
+
+// MinimockWait waits for all mocked methods to be called the expected number of times
+func (m *TransactionManagerMock) MinimockWait(timeout mm_time.Duration) {
+	timeoutCh := mm_time.After(timeout)
+	for {
+		if m.minimockDone() {
+			return
+		}
+		select {
+		case <-timeoutCh:
+			m.MinimockFinish()
+			return
+		case <-mm_time.After(10 * mm_time.Millisecond):
+		}
+	}
+}
+
+func (m *TransactionManagerMock) minimockDone() bool {
+	done := true
+	return done &&
+		m.MinimockReadCommittedDone()
+}

+ 11 - 4
internal/api/v1/tag/update_tag.go

@@ -1,12 +1,14 @@
 package tag
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -24,32 +26,37 @@ import (
 func UpdateTagHandler(tagRepository TagRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("tagId")
+		id, err := request.ConvertToUint64(fctx, "tagId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		req := dto.UpdateTagRequest{}
 		if err = fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err = validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		err = tagRepository.Update(ctx, mappers.ToUpdateTagRequest(id, req), nil)
+		err = tagRepository.Update(ctx, mappers.ToUpdateTagRequest(id, req))
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := tagRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToTagResponse(*res))
 	}

+ 15 - 18
internal/api/v1/tag/update_tag_test.go

@@ -2,8 +2,6 @@ package tag
 
 import (
 	"context"
-	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/tag/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -31,15 +28,15 @@ func TestUpdateTagHandler(t *testing.T) {
 	}
 
 	var (
-		tagID     = gofakeit.Number(1, 1000)
+		tagID     = uint64(gofakeit.Number(1, 1000))
 		title     = gofakeit.Phrase()
 		style     = gofakeit.Phrase()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodPut,
-			route:  "/v1/tags/" + strconv.Itoa(tagID),
+			route:  "/v1/tags/" + strconv.FormatUint(tagID, 10),
 			body: &dto.UpdateTagRequest{
 				Title: title,
 				Style: style,
@@ -79,13 +76,13 @@ func TestUpdateTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest) {
 					assert.Equal(mc, tagID, req.ID)
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(&repoRes, nil)
 
@@ -107,7 +104,7 @@ func TestUpdateTagHandler(t *testing.T) {
 			name: "negative case - body parse error",
 			req: req{
 				method: fiber.MethodPut,
-				route:  "/v1/tags/" + strconv.Itoa(tagID),
+				route:  "/v1/tags/" + strconv.FormatUint(tagID, 10),
 			},
 			resCode: fiber.StatusBadRequest,
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
@@ -118,7 +115,7 @@ func TestUpdateTagHandler(t *testing.T) {
 			name: "negative case - request without title",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/tags/" + strconv.Itoa(tagID),
+				route:       "/v1/tags/" + strconv.FormatUint(tagID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 				body: &dto.UpdateTagRequest{
 					Style: style,
@@ -139,7 +136,7 @@ func TestUpdateTagHandler(t *testing.T) {
 			name: "negative case - request without style",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/tags/" + strconv.Itoa(tagID),
+				route:       "/v1/tags/" + strconv.FormatUint(tagID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 				body: &dto.UpdateTagRequest{
 					Title: title,
@@ -163,7 +160,7 @@ func TestUpdateTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest) {
 					assert.Equal(mc, tagID, req.ID)
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
@@ -179,13 +176,13 @@ func TestUpdateTagHandler(t *testing.T) {
 			tagRepoMock: func(mc *minimock.Controller) TagRepository {
 				mock := mocks.NewTagRepositoryMock(mc)
 
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateTagRequest) {
 					assert.Equal(mc, tagID, req.ID)
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, style, req.Style)
 				}).Return(nil)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, tagID, id)
 				}).Return(nil, testError)
 
@@ -202,13 +199,13 @@ func TestUpdateTagHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Put("/v1/tags/:tagId", UpdateTagHandler(tt.tagRepoMock(mc)))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 44 - 35
internal/api/v1/thing/add_thing.go

@@ -2,16 +2,16 @@ package thing
 
 //go:generate mkdir -p mocks
 //go:generate rm -rf ./mocks/*_minimock.go
-//go:generate minimock -i ThingRepository,PlaceThingRepository,ThingTagRepository,ThingImageRepository,ThingNotificationRepository,FileRepository -o ./mocks/ -s "_minimock.go"
+//go:generate minimock -i ThingRepository,PlaceThingRepository,ThingTagRepository,ThingImageRepository,ThingNotificationRepository,FileRepository,TransactionManager -o ./mocks/ -s "_minimock.go"
 
 import (
 	"context"
-	"database/sql"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
+
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 
@@ -20,37 +20,39 @@ import (
 )
 
 type (
+	TransactionManager interface {
+		ReadCommitted(context.Context, func(ctx context.Context) error) error
+	}
+
 	ThingRepository interface {
-		Get(ctx context.Context, thingID int) (*models.Thing, error)
+		Get(ctx context.Context, id uint64) (*models.Thing, error)
 		Search(ctx context.Context, search string) ([]models.Thing, error)
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.Thing, error)
-		GetAllByPlaceID(ctx context.Context, placeID int) ([]models.Thing, error)
-		Add(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) (int, error)
-		Update(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) error
-		Delete(ctx context.Context, thingID int, tx *sql.Tx) error
-		BeginTx(ctx context.Context, level sql.IsolationLevel) (*sql.Tx, error)
-		CommitTx(tx *sql.Tx) error
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.Thing, error)
+		GetAllByPlaceID(ctx context.Context, id uint64) ([]models.Thing, error)
+		Add(ctx context.Context, req models.AddThingRequest) (uint64, error)
+		Update(ctx context.Context, req models.UpdateThingRequest) error
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	PlaceThingRepository interface {
-		Add(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) error
-		GetByThingID(ctx context.Context, thingID int) (*models.PlaceThing, error)
-		UpdatePlace(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) error
-		DeleteThing(ctx context.Context, thingID int, tx *sql.Tx) error
+		Add(ctx context.Context, req models.AddPlaceThingRequest) error
+		GetByThingID(ctx context.Context, id uint64) (*models.PlaceThing, error)
+		UpdatePlace(ctx context.Context, req models.UpdatePlaceThingRequest) error
+		DeleteThing(ctx context.Context, id uint64) error
 	}
 
 	ThingTagRepository interface {
-		GetByPlaceID(ctx context.Context, placeID int) ([]models.ThingTag, error)
-		DeleteByThingID(ctx context.Context, thingID int, tx *sql.Tx) error
+		GetByPlaceID(ctx context.Context, id uint64) ([]models.ThingTag, error)
+		DeleteByThingID(ctx context.Context, id uint64) error
 	}
 
 	ThingImageRepository interface {
-		GetByThingID(ctx context.Context, thingID int) ([]models.Image, error)
-		Delete(ctx context.Context, imageID int, tx *sql.Tx) error
+		GetByThingID(ctx context.Context, id uint64) ([]models.Image, error)
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	ThingNotificationRepository interface {
-		Delete(ctx context.Context, thingID int, tx *sql.Tx) error
+		Delete(ctx context.Context, id uint64) error
 	}
 
 	FileRepository interface {
@@ -69,6 +71,7 @@ type (
 // @Accept      json
 // @Produce     json
 func AddThingHandler(
+	tm TransactionManager,
 	thingRepository ThingRepository,
 	placeThingRepository PlaceThingRepository,
 ) fiber.Handler {
@@ -76,39 +79,45 @@ func AddThingHandler(
 		ctx := fctx.Context()
 		req := dto.AddThingRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		tx, err := thingRepository.BeginTx(ctx, API.DefaultTxLevel)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+		var id uint64
 
-		id, err := thingRepository.Add(ctx, mappers.ToAddThingRequest(req), tx)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+		err := tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			var txErr error
+			id, txErr = thingRepository.Add(ctx, mappers.ToAddThingRequest(req))
+			if txErr != nil {
+				return txErr
+			}
 
-		err = placeThingRepository.Add(ctx, mappers.ToAddPlaceThingRequest(id, req.PlaceID), tx)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			txErr = placeThingRepository.Add(ctx, mappers.ToAddPlaceThingRequest(id, req.PlaceID))
+			if txErr != nil {
+				return txErr
+			}
+
+			return nil
+		})
 
-		if err = thingRepository.CommitTx(tx); err != nil {
+		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := thingRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingResponse(*res))
 	}

+ 53 - 71
internal/api/v1/thing/add_thing_test.go

@@ -3,7 +3,6 @@ package thing
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"testing"
 
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -30,13 +28,17 @@ func TestAddThingHandler(t *testing.T) {
 	}
 
 	var (
-		placeID     = gofakeit.Number(1, 1000)
-		thingID     = gofakeit.Number(1, 1000)
+		placeID     = uint64(gofakeit.Number(1, 1000))
+		thingID     = uint64(gofakeit.Number(1, 1000))
 		title       = gofakeit.Phrase()
 		description = gofakeit.Phrase()
-		testError   = errors.New(gofakeit.Phrase())
+		testError   = gofakeit.Error()
 		layout      = "2006-01-02 15:04:05"
 
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
+
 		correctReq = req{
 			method: fiber.MethodPost,
 			route:  "/v1/things",
@@ -72,6 +74,7 @@ func TestAddThingHandler(t *testing.T) {
 		req                req
 		resCode            int
 		resBody            interface{}
+		tmMock             func(mc *minimock.Controller) TransactionManager
 		thingRepoMock      func(mc *minimock.Controller) ThingRepository
 		placeThingRepoMock func(mc *minimock.Controller) PlaceThingRepository
 	}{
@@ -80,19 +83,20 @@ func TestAddThingHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: expectedRes,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(thingID, nil)
 
-				mock.CommitTxMock.Return(nil)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoRes, nil)
 
@@ -101,7 +105,7 @@ func TestAddThingHandler(t *testing.T) {
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, placeID, req.PlaceID)
 				}).Return(nil)
@@ -116,6 +120,9 @@ func TestAddThingHandler(t *testing.T) {
 				route:  "/v1/things",
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -141,6 +148,9 @@ func TestAddThingHandler(t *testing.T) {
 					Tag:   "required",
 				},
 			},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -166,6 +176,9 @@ func TestAddThingHandler(t *testing.T) {
 					Tag:   "required",
 				},
 			},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -174,28 +187,18 @@ func TestAddThingHandler(t *testing.T) {
 			},
 		},
 		{
-			name:    "negative case - repository error (begin tx)",
+			name:    "negative case - repository error (add thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-				mock.BeginTxMock.Return(nil, testError)
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				return mocks.NewPlaceThingRepositoryMock(mc)
-			},
-		},
-		{
-			name:    "negative case - repository error (add thing)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(0, testError)
@@ -210,54 +213,28 @@ func TestAddThingHandler(t *testing.T) {
 			name:    "negative case - repository error (add place thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) {
-					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, description, req.Description)
-				}).Return(thingID, nil)
-
-				return mock
-			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				mock := mocks.NewPlaceThingRepositoryMock(mc)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) {
-					assert.Equal(mc, thingID, req.ThingID)
-					assert.Equal(mc, placeID, req.PlaceID)
-				}).Return(testError)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-		},
-		{
-			name:    "negative case - repository error (commit tx)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(thingID, nil)
 
-				mock.CommitTxMock.Return(testError)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, placeID, req.PlaceID)
-				}).Return(nil)
+				}).Return(testError)
 
 				return mock
 			},
@@ -266,19 +243,20 @@ func TestAddThingHandler(t *testing.T) {
 			name:    "negative case - repository error (get thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(thingID, nil)
 
-				mock.CommitTxMock.Return(nil)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -287,7 +265,7 @@ func TestAddThingHandler(t *testing.T) {
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) {
+				mock.AddMock.Inspect(func(ctx context.Context, req models.AddPlaceThingRequest) {
 					assert.Equal(mc, thingID, req.ThingID)
 					assert.Equal(mc, placeID, req.PlaceID)
 				}).Return(nil)
@@ -303,15 +281,19 @@ func TestAddThingHandler(t *testing.T) {
 
 			mc := minimock.NewController(t)
 			fiberApp := fiber.New()
-			fiberApp.Post("/v1/things", AddThingHandler(tt.thingRepoMock(mc), tt.placeThingRepoMock(mc)))
+			fiberApp.Post("/v1/things", AddThingHandler(
+				tt.tmMock(mc),
+				tt.thingRepoMock(mc),
+				tt.placeThingRepoMock(mc),
+			))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 43 - 36
internal/api/v1/thing/delete_thing.go

@@ -1,13 +1,15 @@
 package thing
 
 import (
+	"context"
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 )
 
 // @Router 		/api/v1/things/{thingId} [delete]
@@ -21,6 +23,7 @@ import (
 // @Accept      json
 // @Produce     json
 func DeleteThingHandler(
+	tm TransactionManager,
 	thingRepository ThingRepository,
 	thingTagRepository ThingTagRepository,
 	placeThingRepository PlaceThingRepository,
@@ -30,63 +33,67 @@ func DeleteThingHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		if _, err = thingRepository.Get(ctx, id); err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusBadRequest, "")
 			}
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
 
-		tx, err := thingRepository.BeginTx(ctx, API.DefaultTxLevel)
-		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		if err = placeThingRepository.DeleteThing(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			if txErr := placeThingRepository.DeleteThing(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		images, err := thingImageRepository.GetByThingID(ctx, id)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			images, txErr := thingImageRepository.GetByThingID(ctx, id)
+			if txErr != nil {
+				return txErr
+			}
 
-		imageURLs := make([]string, 0, len(images))
-		for i := range images {
-			imageURLs = append(imageURLs, images[i].Image)
+			imageURLs := make([]string, 0, len(images))
+			for i := range images {
+				imageURLs = append(imageURLs, images[i].Image)
 
-			if err = thingImageRepository.Delete(ctx, images[i].ID, tx); err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+				if txErr = thingImageRepository.Delete(ctx, images[i].ID); txErr != nil {
+					return txErr
+				}
 			}
-		}
-
-		if err = thingTagRepository.DeleteByThingID(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
 
-		if err = thingNotificationRepository.Delete(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = thingTagRepository.DeleteByThingID(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = thingRepository.Delete(ctx, id, tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = thingNotificationRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if err = thingRepository.CommitTx(tx); err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			if txErr = thingRepository.Delete(ctx, id); txErr != nil {
+				return txErr
+			}
 
-		if len(imageURLs) > 0 {
-			for i := range imageURLs {
-				if err = fileRepository.Delete(imageURLs[i]); err != nil {
-					return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			if len(imageURLs) > 0 {
+				for i := range imageURLs {
+					if txErr = fileRepository.Delete(imageURLs[i]); txErr != nil {
+						return txErr
+					}
 				}
 			}
+
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
+			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		return fctx.JSON(factory.CreateEmptyResponse())

+ 106 - 166
internal/api/v1/thing/delete_thing_test.go

@@ -3,7 +3,6 @@ package thing
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,14 +27,18 @@ func TestDeleteThingHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		imageID   = gofakeit.Number(1, 1000)
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		imageID   = uint64(gofakeit.Number(1, 1000))
 		imageURL  = gofakeit.URL()
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
+
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
 
 		correctReq = req{
 			method: fiber.MethodDelete,
-			route:  "/v1/things/" + strconv.Itoa(thingID),
+			route:  "/v1/things/" + strconv.FormatUint(thingID, 10),
 		}
 
 		repoImagesRes = []models.Image{
@@ -52,6 +54,7 @@ func TestDeleteThingHandler(t *testing.T) {
 		req                       req
 		resCode                   int
 		resBody                   interface{}
+		tmMock                    func(mc *minimock.Controller) TransactionManager
 		thingRepoMock             func(mc *minimock.Controller) ThingRepository
 		placeThingRepoMock        func(mc *minimock.Controller) PlaceThingRepository
 		thingImageRepoMock        func(mc *minimock.Controller) ThingImageRepository
@@ -66,6 +69,9 @@ func TestDeleteThingHandler(t *testing.T) {
 				route:  "/v1/things/" + gofakeit.Word(),
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -89,10 +95,13 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - bad request (thing not found)",
 			req:     correctReq,
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -118,10 +127,13 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (get thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -144,55 +156,27 @@ func TestDeleteThingHandler(t *testing.T) {
 			},
 		},
 		{
-			name:    "negative case - repository error (begin tx)",
+			name:    "negative case - repository error (delete place thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil, nil)
-
-				mock.BeginTxMock.Return(nil, testError)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				return mocks.NewPlaceThingRepositoryMock(mc)
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				return mocks.NewThingImageRepositoryMock(mc)
-			},
-			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
-				return mocks.NewThingTagRepositoryMock(mc)
-			},
-			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
-				return mocks.NewThingNotificationRepositoryMock(mc)
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				return mocks.NewFileRepositoryMock(mc)
-			},
-		},
-		{
-			name:    "negative case - repository error (delete place thing)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(testError)
 
@@ -215,21 +199,24 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (get images)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -238,7 +225,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -258,21 +245,24 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (delete images)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -281,11 +271,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(testError)
 
@@ -305,21 +295,24 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (delete thing tags)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -328,11 +321,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -341,7 +334,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(testError)
 
@@ -358,21 +351,24 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (delete notification)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -381,11 +377,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -394,7 +390,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -403,7 +399,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(testError)
 
@@ -417,90 +413,28 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - repository error (delete thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil, nil)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, thingID, id)
-				}).Return(testError)
-
-				return mock
-			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				mock := mocks.NewPlaceThingRepositoryMock(mc)
-
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil)
-
-				return mock
-			},
-			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
-				mock := mocks.NewThingImageRepositoryMock(mc)
-
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(repoImagesRes, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, imageID, id)
-				}).Return(nil)
-
-				return mock
-			},
-			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
-				mock := mocks.NewThingTagRepositoryMock(mc)
-
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
-				mock := mocks.NewThingNotificationRepositoryMock(mc)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil)
-
-				return mock
-			},
-			fileRepoMock: func(mc *minimock.Controller) FileRepository {
-				return mocks.NewFileRepositoryMock(mc)
-			},
-		},
-		{
-			name:    "negative case - repository error (commit tx)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
-				}).Return(nil)
-
-				mock.CommitTxMock.Return(testError)
+				}).Return(testError)
 
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -509,11 +443,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -522,7 +456,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -531,7 +465,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -545,27 +479,28 @@ func TestDeleteThingHandler(t *testing.T) {
 			name:    "negative case - file delete error",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -574,11 +509,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -587,7 +522,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -596,7 +531,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -613,27 +548,28 @@ func TestDeleteThingHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: dto.EmptyResponse{},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteThingMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -642,11 +578,11 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
 				mock := mocks.NewThingImageRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(repoImagesRes, nil)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, imageID, id)
 				}).Return(nil)
 
@@ -655,7 +591,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -664,7 +600,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
 				mock := mocks.NewThingNotificationRepositoryMock(mc)
 
-				mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
+				mock.DeleteMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil)
 
@@ -686,6 +622,7 @@ func TestDeleteThingHandler(t *testing.T) {
 			fiberApp := fiber.New()
 
 			fiberApp.Delete("/v1/things/:thingId", DeleteThingHandler(
+				tt.tmMock(mc),
 				tt.thingRepoMock(mc),
 				tt.thingTagRepoMock(mc),
 				tt.placeThingRepoMock(mc),
@@ -694,10 +631,13 @@ func TestDeleteThingHandler(t *testing.T) {
 				tt.fileRepoMock(mc),
 			))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 9 - 4
internal/api/v1/thing/get_place_things.go

@@ -1,9 +1,11 @@
 package thing
 
 import (
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -23,23 +25,26 @@ func GetPlaceThingsHandler(
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("placeId")
+		id, err := request.ConvertToUint64(fctx, "placeId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		things, err := thingRepository.GetAllByPlaceID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		tags, err := thingTagRepository.GetByPlaceID(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		things = helpers.ApplyLocation(fctx, things)
-		tags = helpers.ApplyLocation(fctx, tags)
+		things = location.ApplyLocation(fctx, things)
+		tags = location.ApplyLocation(fctx, tags)
 
 		return fctx.JSON(mappers.ToThingsExtResponse(things, tags))
 	}

+ 19 - 18
internal/api/v1/thing/get_place_things_test.go

@@ -2,7 +2,6 @@ package thing
 
 import (
 	"context"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -28,18 +26,18 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 	}
 
 	var (
-		placeID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/things/place/" + strconv.Itoa(placeID),
+			route:  "/v1/things/place/" + strconv.FormatUint(placeID, 10),
 		}
 
 		thingRepoRes = []models.Thing{
 			{
-				ID:          gofakeit.Number(1, 1000),
+				ID:          uint64(gofakeit.Number(1, 1000)),
 				PlaceID:     placeID,
 				Title:       gofakeit.Phrase(),
 				Description: gofakeit.Phrase(),
@@ -47,7 +45,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 				UpdatedAt:   gofakeit.Date(),
 			},
 			{
-				ID:          gofakeit.Number(1, 1000),
+				ID:          uint64(gofakeit.Number(1, 1000)),
 				PlaceID:     placeID,
 				Title:       gofakeit.Phrase(),
 				Description: gofakeit.Phrase(),
@@ -60,7 +58,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			{
 				ThingID: thingRepoRes[0].ID,
 				Tag: models.Tag{
-					ID:        gofakeit.Number(1, 1000),
+					ID:        uint64(gofakeit.Number(1, 1000)),
 					Title:     gofakeit.Phrase(),
 					Style:     gofakeit.Phrase(),
 					CreatedAt: gofakeit.Date(),
@@ -70,7 +68,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			{
 				ThingID: thingRepoRes[1].ID,
 				Tag: models.Tag{
-					ID:        gofakeit.Number(1, 1000),
+					ID:        uint64(gofakeit.Number(1, 1000)),
 					Title:     gofakeit.Phrase(),
 					Style:     gofakeit.Phrase(),
 					CreatedAt: gofakeit.Date(),
@@ -139,7 +137,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(thingRepoRes, nil)
 
@@ -148,7 +146,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(thingTagRepoRes, nil)
 
@@ -162,7 +160,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -179,7 +177,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetAllByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(thingRepoRes, nil)
 
@@ -188,7 +186,7 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 			thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
 				mock := mocks.NewThingTagRepositoryMock(mc)
 
-				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, placeID, id)
 				}).Return(nil, testError)
 
@@ -218,12 +216,15 @@ func TestGetPlaceThingsHandler(t *testing.T) {
 
 			mc := minimock.NewController(t)
 			fiberApp := fiber.New()
-			fiberApp.Get("/v1/things/place/:placeId", GetPlaceThingsHandler(tt.thingRepoMock(mc), tt.thingTagRepoMock(mc)))
+			fiberApp.Get("/v1/things/place/:placeId", GetPlaceThingsHandler(
+				tt.thingRepoMock(mc),
+				tt.thingTagRepoMock(mc),
+			))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), test.TestTimeout)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 8 - 3
internal/api/v1/thing/get_thing.go

@@ -4,9 +4,11 @@ import (
 	"database/sql"
 	"errors"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -24,21 +26,24 @@ import (
 func GetThingHandler(thingRepository ThingRepository) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		res, err := thingRepository.Get(ctx, id)
 		if err != nil {
 			if errors.Is(err, sql.ErrNoRows) {
+				logger.Info(ctx, err.Error())
 				return fiber.NewError(fiber.StatusNotFound, "")
 			}
 
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingResponse(*res))
 	}

+ 13 - 12
internal/api/v1/thing/get_thing_test.go

@@ -3,7 +3,6 @@ package thing
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,14 +27,14 @@ func TestGetThingHandler(t *testing.T) {
 	}
 
 	var (
-		thingID   = gofakeit.Number(1, 1000)
-		placeID   = gofakeit.Number(1, 1000)
-		testError = errors.New(gofakeit.Phrase())
+		thingID   = uint64(gofakeit.Number(1, 1000))
+		placeID   = uint64(gofakeit.Number(1, 1000))
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
 			method: fiber.MethodGet,
-			route:  "/v1/things/" + strconv.Itoa(thingID),
+			route:  "/v1/things/" + strconv.FormatUint(thingID, 10),
 		}
 
 		thingRepoRes = models.Thing{
@@ -73,7 +71,7 @@ func TestGetThingHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&thingRepoRes, nil)
 
@@ -87,7 +85,7 @@ func TestGetThingHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -101,7 +99,7 @@ func TestGetThingHandler(t *testing.T) {
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, testError)
 
@@ -130,10 +128,13 @@ func TestGetThingHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/things/:thingId", GetThingHandler(tt.thingRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 1 - 1
internal/api/v1/thing/mocks/file_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 

+ 75 - 160
internal/api/v1/thing/mocks/place_thing_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,26 +19,26 @@ type PlaceThingRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcAdd          func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) (err error)
-	inspectFuncAdd   func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx)
+	funcAdd          func(ctx context.Context, req models.AddPlaceThingRequest) (err error)
+	inspectFuncAdd   func(ctx context.Context, req models.AddPlaceThingRequest)
 	afterAddCounter  uint64
 	beforeAddCounter uint64
 	AddMock          mPlaceThingRepositoryMockAdd
 
-	funcDeleteThing          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDeleteThing   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDeleteThing          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDeleteThing   func(ctx context.Context, id uint64)
 	afterDeleteThingCounter  uint64
 	beforeDeleteThingCounter uint64
 	DeleteThingMock          mPlaceThingRepositoryMockDeleteThing
 
-	funcGetByThingID          func(ctx context.Context, thingID int) (pp1 *models.PlaceThing, err error)
-	inspectFuncGetByThingID   func(ctx context.Context, thingID int)
+	funcGetByThingID          func(ctx context.Context, id uint64) (pp1 *models.PlaceThing, err error)
+	inspectFuncGetByThingID   func(ctx context.Context, id uint64)
 	afterGetByThingIDCounter  uint64
 	beforeGetByThingIDCounter uint64
 	GetByThingIDMock          mPlaceThingRepositoryMockGetByThingID
 
-	funcUpdatePlace          func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) (err error)
-	inspectFuncUpdatePlace   func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx)
+	funcUpdatePlace          func(ctx context.Context, req models.UpdatePlaceThingRequest) (err error)
+	inspectFuncUpdatePlace   func(ctx context.Context, req models.UpdatePlaceThingRequest)
 	afterUpdatePlaceCounter  uint64
 	beforeUpdatePlaceCounter uint64
 	UpdatePlaceMock          mPlaceThingRepositoryMockUpdatePlace
@@ -95,14 +94,12 @@ type PlaceThingRepositoryMockAddExpectation struct {
 type PlaceThingRepositoryMockAddParams struct {
 	ctx context.Context
 	req models.AddPlaceThingRequest
-	tx  *sql.Tx
 }
 
 // PlaceThingRepositoryMockAddParamPtrs contains pointers to parameters of the PlaceThingRepository.Add
 type PlaceThingRepositoryMockAddParamPtrs struct {
 	ctx *context.Context
 	req *models.AddPlaceThingRequest
-	tx  **sql.Tx
 }
 
 // PlaceThingRepositoryMockAddResults contains results of the PlaceThingRepository.Add
@@ -121,7 +118,7 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) Optional() *mPlaceThingRepositoryMock
 }
 
 // Expect sets up expected params for PlaceThingRepository.Add
-func (mmAdd *mPlaceThingRepositoryMockAdd) Expect(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) *mPlaceThingRepositoryMockAdd {
+func (mmAdd *mPlaceThingRepositoryMockAdd) Expect(ctx context.Context, req models.AddPlaceThingRequest) *mPlaceThingRepositoryMockAdd {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("PlaceThingRepositoryMock.Add mock is already set by Set")
 	}
@@ -134,7 +131,7 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) Expect(ctx context.Context, req model
 		mmAdd.mock.t.Fatalf("PlaceThingRepositoryMock.Add mock is already set by ExpectParams functions")
 	}
 
-	mmAdd.defaultExpectation.params = &PlaceThingRepositoryMockAddParams{ctx, req, tx}
+	mmAdd.defaultExpectation.params = &PlaceThingRepositoryMockAddParams{ctx, req}
 	for _, e := range mmAdd.expectations {
 		if minimock.Equal(e.params, mmAdd.defaultExpectation.params) {
 			mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params)
@@ -188,30 +185,8 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) ExpectReqParam2(req models.AddPlaceTh
 	return mmAdd
 }
 
-// ExpectTxParam3 sets up expected param tx for PlaceThingRepository.Add
-func (mmAdd *mPlaceThingRepositoryMockAdd) ExpectTxParam3(tx *sql.Tx) *mPlaceThingRepositoryMockAdd {
-	if mmAdd.mock.funcAdd != nil {
-		mmAdd.mock.t.Fatalf("PlaceThingRepositoryMock.Add mock is already set by Set")
-	}
-
-	if mmAdd.defaultExpectation == nil {
-		mmAdd.defaultExpectation = &PlaceThingRepositoryMockAddExpectation{}
-	}
-
-	if mmAdd.defaultExpectation.params != nil {
-		mmAdd.mock.t.Fatalf("PlaceThingRepositoryMock.Add mock is already set by Expect")
-	}
-
-	if mmAdd.defaultExpectation.paramPtrs == nil {
-		mmAdd.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockAddParamPtrs{}
-	}
-	mmAdd.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmAdd
-}
-
 // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.Add
-func (mmAdd *mPlaceThingRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx)) *mPlaceThingRepositoryMockAdd {
+func (mmAdd *mPlaceThingRepositoryMockAdd) Inspect(f func(ctx context.Context, req models.AddPlaceThingRequest)) *mPlaceThingRepositoryMockAdd {
 	if mmAdd.mock.inspectFuncAdd != nil {
 		mmAdd.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.Add")
 	}
@@ -235,7 +210,7 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) Return(err error) *PlaceThingReposito
 }
 
 // Set uses given function f to mock the PlaceThingRepository.Add method
-func (mmAdd *mPlaceThingRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) (err error)) *PlaceThingRepositoryMock {
+func (mmAdd *mPlaceThingRepositoryMockAdd) Set(f func(ctx context.Context, req models.AddPlaceThingRequest) (err error)) *PlaceThingRepositoryMock {
 	if mmAdd.defaultExpectation != nil {
 		mmAdd.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.Add method")
 	}
@@ -250,14 +225,14 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) Set(f func(ctx context.Context, req m
 
 // When sets expectation for the PlaceThingRepository.Add which will trigger the result defined by the following
 // Then helper
-func (mmAdd *mPlaceThingRepositoryMockAdd) When(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) *PlaceThingRepositoryMockAddExpectation {
+func (mmAdd *mPlaceThingRepositoryMockAdd) When(ctx context.Context, req models.AddPlaceThingRequest) *PlaceThingRepositoryMockAddExpectation {
 	if mmAdd.mock.funcAdd != nil {
 		mmAdd.mock.t.Fatalf("PlaceThingRepositoryMock.Add mock is already set by Set")
 	}
 
 	expectation := &PlaceThingRepositoryMockAddExpectation{
 		mock:   mmAdd.mock,
-		params: &PlaceThingRepositoryMockAddParams{ctx, req, tx},
+		params: &PlaceThingRepositoryMockAddParams{ctx, req},
 	}
 	mmAdd.expectations = append(mmAdd.expectations, expectation)
 	return expectation
@@ -290,15 +265,15 @@ func (mmAdd *mPlaceThingRepositoryMockAdd) invocationsDone() bool {
 }
 
 // Add implements thing.PlaceThingRepository
-func (mmAdd *PlaceThingRepositoryMock) Add(ctx context.Context, req models.AddPlaceThingRequest, tx *sql.Tx) (err error) {
+func (mmAdd *PlaceThingRepositoryMock) Add(ctx context.Context, req models.AddPlaceThingRequest) (err error) {
 	mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1)
 	defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1)
 
 	if mmAdd.inspectFuncAdd != nil {
-		mmAdd.inspectFuncAdd(ctx, req, tx)
+		mmAdd.inspectFuncAdd(ctx, req)
 	}
 
-	mm_params := PlaceThingRepositoryMockAddParams{ctx, req, tx}
+	mm_params := PlaceThingRepositoryMockAddParams{ctx, req}
 
 	// Record call args
 	mmAdd.AddMock.mutex.Lock()
@@ -317,7 +292,7 @@ func (mmAdd *PlaceThingRepositoryMock) Add(ctx context.Context, req models.AddPl
 		mm_want := mmAdd.AddMock.defaultExpectation.params
 		mm_want_ptrs := mmAdd.AddMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceThingRepositoryMockAddParams{ctx, req, tx}
+		mm_got := PlaceThingRepositoryMockAddParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -329,10 +304,6 @@ func (mmAdd *PlaceThingRepositoryMock) Add(ctx context.Context, req models.AddPl
 				mmAdd.t.Errorf("PlaceThingRepositoryMock.Add got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmAdd.t.Errorf("PlaceThingRepositoryMock.Add got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmAdd.t.Errorf("PlaceThingRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -344,9 +315,9 @@ func (mmAdd *PlaceThingRepositoryMock) Add(ctx context.Context, req models.AddPl
 		return (*mm_results).err
 	}
 	if mmAdd.funcAdd != nil {
-		return mmAdd.funcAdd(ctx, req, tx)
+		return mmAdd.funcAdd(ctx, req)
 	}
-	mmAdd.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.Add. %v %v %v", ctx, req, tx)
+	mmAdd.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.Add. %v %v", ctx, req)
 	return
 }
 
@@ -441,16 +412,14 @@ type PlaceThingRepositoryMockDeleteThingExpectation struct {
 
 // PlaceThingRepositoryMockDeleteThingParams contains parameters of the PlaceThingRepository.DeleteThing
 type PlaceThingRepositoryMockDeleteThingParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // PlaceThingRepositoryMockDeleteThingParamPtrs contains pointers to parameters of the PlaceThingRepository.DeleteThing
 type PlaceThingRepositoryMockDeleteThingParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // PlaceThingRepositoryMockDeleteThingResults contains results of the PlaceThingRepository.DeleteThing
@@ -469,7 +438,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Optional() *mPlaceThi
 }
 
 // Expect sets up expected params for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mPlaceThingRepositoryMockDeleteThing {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Context, id uint64) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
@@ -482,7 +451,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Expect(ctx context.Co
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by ExpectParams functions")
 	}
 
-	mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+	mmDeleteThing.defaultExpectation.params = &PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 	for _, e := range mmDeleteThing.expectations {
 		if minimock.Equal(e.params, mmDeleteThing.defaultExpectation.params) {
 			mmDeleteThing.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteThing.defaultExpectation.params)
@@ -514,8 +483,8 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectCtxParam1(ctx c
 	return mmDeleteThing
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectThingIDParam2(thingID int) *mPlaceThingRepositoryMockDeleteThing {
+// ExpectIdParam2 sets up expected param id for PlaceThingRepository.DeleteThing
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectIdParam2(id uint64) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
@@ -531,35 +500,13 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectThingIDParam2(t
 	if mmDeleteThing.defaultExpectation.paramPtrs == nil {
 		mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
 	}
-	mmDeleteThing.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDeleteThing
-}
-
-// ExpectTxParam3 sets up expected param tx for PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) ExpectTxParam3(tx *sql.Tx) *mPlaceThingRepositoryMockDeleteThing {
-	if mmDeleteThing.mock.funcDeleteThing != nil {
-		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
-	}
-
-	if mmDeleteThing.defaultExpectation == nil {
-		mmDeleteThing.defaultExpectation = &PlaceThingRepositoryMockDeleteThingExpectation{}
-	}
-
-	if mmDeleteThing.defaultExpectation.params != nil {
-		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Expect")
-	}
-
-	if mmDeleteThing.defaultExpectation.paramPtrs == nil {
-		mmDeleteThing.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockDeleteThingParamPtrs{}
-	}
-	mmDeleteThing.defaultExpectation.paramPtrs.tx = &tx
+	mmDeleteThing.defaultExpectation.paramPtrs.id = &id
 
 	return mmDeleteThing
 }
 
 // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.DeleteThing
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mPlaceThingRepositoryMockDeleteThing {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Inspect(f func(ctx context.Context, id uint64)) *mPlaceThingRepositoryMockDeleteThing {
 	if mmDeleteThing.mock.inspectFuncDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.DeleteThing")
 	}
@@ -583,7 +530,7 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Return(err error) *Pl
 }
 
 // Set uses given function f to mock the PlaceThingRepository.DeleteThing method
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *PlaceThingRepositoryMock {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx context.Context, id uint64) (err error)) *PlaceThingRepositoryMock {
 	if mmDeleteThing.defaultExpectation != nil {
 		mmDeleteThing.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.DeleteThing method")
 	}
@@ -598,14 +545,14 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) Set(f func(ctx contex
 
 // When sets expectation for the PlaceThingRepository.DeleteThing which will trigger the result defined by the following
 // Then helper
-func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, thingID int, tx *sql.Tx) *PlaceThingRepositoryMockDeleteThingExpectation {
+func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) When(ctx context.Context, id uint64) *PlaceThingRepositoryMockDeleteThingExpectation {
 	if mmDeleteThing.mock.funcDeleteThing != nil {
 		mmDeleteThing.mock.t.Fatalf("PlaceThingRepositoryMock.DeleteThing mock is already set by Set")
 	}
 
 	expectation := &PlaceThingRepositoryMockDeleteThingExpectation{
 		mock:   mmDeleteThing.mock,
-		params: &PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx},
+		params: &PlaceThingRepositoryMockDeleteThingParams{ctx, id},
 	}
 	mmDeleteThing.expectations = append(mmDeleteThing.expectations, expectation)
 	return expectation
@@ -638,15 +585,15 @@ func (mmDeleteThing *mPlaceThingRepositoryMockDeleteThing) invocationsDone() boo
 }
 
 // DeleteThing implements thing.PlaceThingRepository
-func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDeleteThing.beforeDeleteThingCounter, 1)
 	defer mm_atomic.AddUint64(&mmDeleteThing.afterDeleteThingCounter, 1)
 
 	if mmDeleteThing.inspectFuncDeleteThing != nil {
-		mmDeleteThing.inspectFuncDeleteThing(ctx, thingID, tx)
+		mmDeleteThing.inspectFuncDeleteThing(ctx, id)
 	}
 
-	mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+	mm_params := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 
 	// Record call args
 	mmDeleteThing.DeleteThingMock.mutex.Lock()
@@ -665,7 +612,7 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 		mm_want := mmDeleteThing.DeleteThingMock.defaultExpectation.params
 		mm_want_ptrs := mmDeleteThing.DeleteThingMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, thingID, tx}
+		mm_got := PlaceThingRepositoryMockDeleteThingParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -673,12 +620,8 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDeleteThing.t.Errorf("PlaceThingRepositoryMock.DeleteThing got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -692,9 +635,9 @@ func (mmDeleteThing *PlaceThingRepositoryMock) DeleteThing(ctx context.Context,
 		return (*mm_results).err
 	}
 	if mmDeleteThing.funcDeleteThing != nil {
-		return mmDeleteThing.funcDeleteThing(ctx, thingID, tx)
+		return mmDeleteThing.funcDeleteThing(ctx, id)
 	}
-	mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v %v", ctx, thingID, tx)
+	mmDeleteThing.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.DeleteThing. %v %v", ctx, id)
 	return
 }
 
@@ -789,14 +732,14 @@ type PlaceThingRepositoryMockGetByThingIDExpectation struct {
 
 // PlaceThingRepositoryMockGetByThingIDParams contains parameters of the PlaceThingRepository.GetByThingID
 type PlaceThingRepositoryMockGetByThingIDParams struct {
-	ctx     context.Context
-	thingID int
+	ctx context.Context
+	id  uint64
 }
 
 // PlaceThingRepositoryMockGetByThingIDParamPtrs contains pointers to parameters of the PlaceThingRepository.GetByThingID
 type PlaceThingRepositoryMockGetByThingIDParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // PlaceThingRepositoryMockGetByThingIDResults contains results of the PlaceThingRepository.GetByThingID
@@ -816,7 +759,7 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Optional() *mPlaceT
 }
 
 // Expect sets up expected params for PlaceThingRepository.GetByThingID
-func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Expect(ctx context.Context, thingID int) *mPlaceThingRepositoryMockGetByThingID {
+func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Expect(ctx context.Context, id uint64) *mPlaceThingRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("PlaceThingRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -829,7 +772,7 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Expect(ctx context.
 		mmGetByThingID.mock.t.Fatalf("PlaceThingRepositoryMock.GetByThingID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByThingID.defaultExpectation.params = &PlaceThingRepositoryMockGetByThingIDParams{ctx, thingID}
+	mmGetByThingID.defaultExpectation.params = &PlaceThingRepositoryMockGetByThingIDParams{ctx, id}
 	for _, e := range mmGetByThingID.expectations {
 		if minimock.Equal(e.params, mmGetByThingID.defaultExpectation.params) {
 			mmGetByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByThingID.defaultExpectation.params)
@@ -861,8 +804,8 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) ExpectCtxParam1(ctx
 	return mmGetByThingID
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for PlaceThingRepository.GetByThingID
-func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) ExpectThingIDParam2(thingID int) *mPlaceThingRepositoryMockGetByThingID {
+// ExpectIdParam2 sets up expected param id for PlaceThingRepository.GetByThingID
+func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) ExpectIdParam2(id uint64) *mPlaceThingRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("PlaceThingRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -878,13 +821,13 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) ExpectThingIDParam2
 	if mmGetByThingID.defaultExpectation.paramPtrs == nil {
 		mmGetByThingID.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockGetByThingIDParamPtrs{}
 	}
-	mmGetByThingID.defaultExpectation.paramPtrs.thingID = &thingID
+	mmGetByThingID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByThingID
 }
 
 // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.GetByThingID
-func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, thingID int)) *mPlaceThingRepositoryMockGetByThingID {
+func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, id uint64)) *mPlaceThingRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.inspectFuncGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.GetByThingID")
 	}
@@ -908,7 +851,7 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Return(pp1 *models.
 }
 
 // Set uses given function f to mock the PlaceThingRepository.GetByThingID method
-func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Set(f func(ctx context.Context, thingID int) (pp1 *models.PlaceThing, err error)) *PlaceThingRepositoryMock {
+func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Set(f func(ctx context.Context, id uint64) (pp1 *models.PlaceThing, err error)) *PlaceThingRepositoryMock {
 	if mmGetByThingID.defaultExpectation != nil {
 		mmGetByThingID.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.GetByThingID method")
 	}
@@ -923,14 +866,14 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) Set(f func(ctx cont
 
 // When sets expectation for the PlaceThingRepository.GetByThingID which will trigger the result defined by the following
 // Then helper
-func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) When(ctx context.Context, thingID int) *PlaceThingRepositoryMockGetByThingIDExpectation {
+func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) When(ctx context.Context, id uint64) *PlaceThingRepositoryMockGetByThingIDExpectation {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("PlaceThingRepositoryMock.GetByThingID mock is already set by Set")
 	}
 
 	expectation := &PlaceThingRepositoryMockGetByThingIDExpectation{
 		mock:   mmGetByThingID.mock,
-		params: &PlaceThingRepositoryMockGetByThingIDParams{ctx, thingID},
+		params: &PlaceThingRepositoryMockGetByThingIDParams{ctx, id},
 	}
 	mmGetByThingID.expectations = append(mmGetByThingID.expectations, expectation)
 	return expectation
@@ -963,15 +906,15 @@ func (mmGetByThingID *mPlaceThingRepositoryMockGetByThingID) invocationsDone() b
 }
 
 // GetByThingID implements thing.PlaceThingRepository
-func (mmGetByThingID *PlaceThingRepositoryMock) GetByThingID(ctx context.Context, thingID int) (pp1 *models.PlaceThing, err error) {
+func (mmGetByThingID *PlaceThingRepositoryMock) GetByThingID(ctx context.Context, id uint64) (pp1 *models.PlaceThing, err error) {
 	mm_atomic.AddUint64(&mmGetByThingID.beforeGetByThingIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByThingID.afterGetByThingIDCounter, 1)
 
 	if mmGetByThingID.inspectFuncGetByThingID != nil {
-		mmGetByThingID.inspectFuncGetByThingID(ctx, thingID)
+		mmGetByThingID.inspectFuncGetByThingID(ctx, id)
 	}
 
-	mm_params := PlaceThingRepositoryMockGetByThingIDParams{ctx, thingID}
+	mm_params := PlaceThingRepositoryMockGetByThingIDParams{ctx, id}
 
 	// Record call args
 	mmGetByThingID.GetByThingIDMock.mutex.Lock()
@@ -990,7 +933,7 @@ func (mmGetByThingID *PlaceThingRepositoryMock) GetByThingID(ctx context.Context
 		mm_want := mmGetByThingID.GetByThingIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByThingID.GetByThingIDMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceThingRepositoryMockGetByThingIDParams{ctx, thingID}
+		mm_got := PlaceThingRepositoryMockGetByThingIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -998,8 +941,8 @@ func (mmGetByThingID *PlaceThingRepositoryMock) GetByThingID(ctx context.Context
 				mmGetByThingID.t.Errorf("PlaceThingRepositoryMock.GetByThingID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmGetByThingID.t.Errorf("PlaceThingRepositoryMock.GetByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByThingID.t.Errorf("PlaceThingRepositoryMock.GetByThingID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -1013,9 +956,9 @@ func (mmGetByThingID *PlaceThingRepositoryMock) GetByThingID(ctx context.Context
 		return (*mm_results).pp1, (*mm_results).err
 	}
 	if mmGetByThingID.funcGetByThingID != nil {
-		return mmGetByThingID.funcGetByThingID(ctx, thingID)
+		return mmGetByThingID.funcGetByThingID(ctx, id)
 	}
-	mmGetByThingID.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.GetByThingID. %v %v", ctx, thingID)
+	mmGetByThingID.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.GetByThingID. %v %v", ctx, id)
 	return
 }
 
@@ -1112,14 +1055,12 @@ type PlaceThingRepositoryMockUpdatePlaceExpectation struct {
 type PlaceThingRepositoryMockUpdatePlaceParams struct {
 	ctx context.Context
 	req models.UpdatePlaceThingRequest
-	tx  *sql.Tx
 }
 
 // PlaceThingRepositoryMockUpdatePlaceParamPtrs contains pointers to parameters of the PlaceThingRepository.UpdatePlace
 type PlaceThingRepositoryMockUpdatePlaceParamPtrs struct {
 	ctx *context.Context
 	req *models.UpdatePlaceThingRequest
-	tx  **sql.Tx
 }
 
 // PlaceThingRepositoryMockUpdatePlaceResults contains results of the PlaceThingRepository.UpdatePlace
@@ -1138,7 +1079,7 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Optional() *mPlaceThi
 }
 
 // Expect sets up expected params for PlaceThingRepository.UpdatePlace
-func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Expect(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) *mPlaceThingRepositoryMockUpdatePlace {
+func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Expect(ctx context.Context, req models.UpdatePlaceThingRequest) *mPlaceThingRepositoryMockUpdatePlace {
 	if mmUpdatePlace.mock.funcUpdatePlace != nil {
 		mmUpdatePlace.mock.t.Fatalf("PlaceThingRepositoryMock.UpdatePlace mock is already set by Set")
 	}
@@ -1151,7 +1092,7 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Expect(ctx context.Co
 		mmUpdatePlace.mock.t.Fatalf("PlaceThingRepositoryMock.UpdatePlace mock is already set by ExpectParams functions")
 	}
 
-	mmUpdatePlace.defaultExpectation.params = &PlaceThingRepositoryMockUpdatePlaceParams{ctx, req, tx}
+	mmUpdatePlace.defaultExpectation.params = &PlaceThingRepositoryMockUpdatePlaceParams{ctx, req}
 	for _, e := range mmUpdatePlace.expectations {
 		if minimock.Equal(e.params, mmUpdatePlace.defaultExpectation.params) {
 			mmUpdatePlace.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdatePlace.defaultExpectation.params)
@@ -1205,30 +1146,8 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) ExpectReqParam2(req m
 	return mmUpdatePlace
 }
 
-// ExpectTxParam3 sets up expected param tx for PlaceThingRepository.UpdatePlace
-func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) ExpectTxParam3(tx *sql.Tx) *mPlaceThingRepositoryMockUpdatePlace {
-	if mmUpdatePlace.mock.funcUpdatePlace != nil {
-		mmUpdatePlace.mock.t.Fatalf("PlaceThingRepositoryMock.UpdatePlace mock is already set by Set")
-	}
-
-	if mmUpdatePlace.defaultExpectation == nil {
-		mmUpdatePlace.defaultExpectation = &PlaceThingRepositoryMockUpdatePlaceExpectation{}
-	}
-
-	if mmUpdatePlace.defaultExpectation.params != nil {
-		mmUpdatePlace.mock.t.Fatalf("PlaceThingRepositoryMock.UpdatePlace mock is already set by Expect")
-	}
-
-	if mmUpdatePlace.defaultExpectation.paramPtrs == nil {
-		mmUpdatePlace.defaultExpectation.paramPtrs = &PlaceThingRepositoryMockUpdatePlaceParamPtrs{}
-	}
-	mmUpdatePlace.defaultExpectation.paramPtrs.tx = &tx
-
-	return mmUpdatePlace
-}
-
 // Inspect accepts an inspector function that has same arguments as the PlaceThingRepository.UpdatePlace
-func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Inspect(f func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx)) *mPlaceThingRepositoryMockUpdatePlace {
+func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Inspect(f func(ctx context.Context, req models.UpdatePlaceThingRequest)) *mPlaceThingRepositoryMockUpdatePlace {
 	if mmUpdatePlace.mock.inspectFuncUpdatePlace != nil {
 		mmUpdatePlace.mock.t.Fatalf("Inspect function is already set for PlaceThingRepositoryMock.UpdatePlace")
 	}
@@ -1252,7 +1171,7 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Return(err error) *Pl
 }
 
 // Set uses given function f to mock the PlaceThingRepository.UpdatePlace method
-func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Set(f func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) (err error)) *PlaceThingRepositoryMock {
+func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Set(f func(ctx context.Context, req models.UpdatePlaceThingRequest) (err error)) *PlaceThingRepositoryMock {
 	if mmUpdatePlace.defaultExpectation != nil {
 		mmUpdatePlace.mock.t.Fatalf("Default expectation is already set for the PlaceThingRepository.UpdatePlace method")
 	}
@@ -1267,14 +1186,14 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) Set(f func(ctx contex
 
 // When sets expectation for the PlaceThingRepository.UpdatePlace which will trigger the result defined by the following
 // Then helper
-func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) When(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) *PlaceThingRepositoryMockUpdatePlaceExpectation {
+func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) When(ctx context.Context, req models.UpdatePlaceThingRequest) *PlaceThingRepositoryMockUpdatePlaceExpectation {
 	if mmUpdatePlace.mock.funcUpdatePlace != nil {
 		mmUpdatePlace.mock.t.Fatalf("PlaceThingRepositoryMock.UpdatePlace mock is already set by Set")
 	}
 
 	expectation := &PlaceThingRepositoryMockUpdatePlaceExpectation{
 		mock:   mmUpdatePlace.mock,
-		params: &PlaceThingRepositoryMockUpdatePlaceParams{ctx, req, tx},
+		params: &PlaceThingRepositoryMockUpdatePlaceParams{ctx, req},
 	}
 	mmUpdatePlace.expectations = append(mmUpdatePlace.expectations, expectation)
 	return expectation
@@ -1307,15 +1226,15 @@ func (mmUpdatePlace *mPlaceThingRepositoryMockUpdatePlace) invocationsDone() boo
 }
 
 // UpdatePlace implements thing.PlaceThingRepository
-func (mmUpdatePlace *PlaceThingRepositoryMock) UpdatePlace(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) (err error) {
+func (mmUpdatePlace *PlaceThingRepositoryMock) UpdatePlace(ctx context.Context, req models.UpdatePlaceThingRequest) (err error) {
 	mm_atomic.AddUint64(&mmUpdatePlace.beforeUpdatePlaceCounter, 1)
 	defer mm_atomic.AddUint64(&mmUpdatePlace.afterUpdatePlaceCounter, 1)
 
 	if mmUpdatePlace.inspectFuncUpdatePlace != nil {
-		mmUpdatePlace.inspectFuncUpdatePlace(ctx, req, tx)
+		mmUpdatePlace.inspectFuncUpdatePlace(ctx, req)
 	}
 
-	mm_params := PlaceThingRepositoryMockUpdatePlaceParams{ctx, req, tx}
+	mm_params := PlaceThingRepositoryMockUpdatePlaceParams{ctx, req}
 
 	// Record call args
 	mmUpdatePlace.UpdatePlaceMock.mutex.Lock()
@@ -1334,7 +1253,7 @@ func (mmUpdatePlace *PlaceThingRepositoryMock) UpdatePlace(ctx context.Context,
 		mm_want := mmUpdatePlace.UpdatePlaceMock.defaultExpectation.params
 		mm_want_ptrs := mmUpdatePlace.UpdatePlaceMock.defaultExpectation.paramPtrs
 
-		mm_got := PlaceThingRepositoryMockUpdatePlaceParams{ctx, req, tx}
+		mm_got := PlaceThingRepositoryMockUpdatePlaceParams{ctx, req}
 
 		if mm_want_ptrs != nil {
 
@@ -1346,10 +1265,6 @@ func (mmUpdatePlace *PlaceThingRepositoryMock) UpdatePlace(ctx context.Context,
 				mmUpdatePlace.t.Errorf("PlaceThingRepositoryMock.UpdatePlace got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req))
 			}
 
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmUpdatePlace.t.Errorf("PlaceThingRepositoryMock.UpdatePlace got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
-			}
-
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
 			mmUpdatePlace.t.Errorf("PlaceThingRepositoryMock.UpdatePlace got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
 		}
@@ -1361,9 +1276,9 @@ func (mmUpdatePlace *PlaceThingRepositoryMock) UpdatePlace(ctx context.Context,
 		return (*mm_results).err
 	}
 	if mmUpdatePlace.funcUpdatePlace != nil {
-		return mmUpdatePlace.funcUpdatePlace(ctx, req, tx)
+		return mmUpdatePlace.funcUpdatePlace(ctx, req)
 	}
-	mmUpdatePlace.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.UpdatePlace. %v %v %v", ctx, req, tx)
+	mmUpdatePlace.t.Fatalf("Unexpected call to PlaceThingRepositoryMock.UpdatePlace. %v %v", ctx, req)
 	return
 }
 

+ 47 - 76
internal/api/v1/thing/mocks/thing_image_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,14 +19,14 @@ type ThingImageRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, imageID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, imageID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingImageRepositoryMockDelete
 
-	funcGetByThingID          func(ctx context.Context, thingID int) (ia1 []models.Image, err error)
-	inspectFuncGetByThingID   func(ctx context.Context, thingID int)
+	funcGetByThingID          func(ctx context.Context, id uint64) (ia1 []models.Image, err error)
+	inspectFuncGetByThingID   func(ctx context.Context, id uint64)
 	afterGetByThingIDCounter  uint64
 	beforeGetByThingIDCounter uint64
 	GetByThingIDMock          mThingImageRepositoryMockGetByThingID
@@ -75,16 +74,14 @@ type ThingImageRepositoryMockDeleteExpectation struct {
 
 // ThingImageRepositoryMockDeleteParams contains parameters of the ThingImageRepository.Delete
 type ThingImageRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	imageID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingImageRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingImageRepository.Delete
 type ThingImageRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	imageID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingImageRepositoryMockDeleteResults contains results of the ThingImageRepository.Delete
@@ -103,7 +100,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Optional() *mThingImageReposito
 }
 
 // Expect sets up expected params for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, imageID int, tx *sql.Tx) *mThingImageRepositoryMockDelete {
+func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -116,7 +113,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Expect(ctx context.Context, ima
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mmDelete.defaultExpectation.params = &ThingImageRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -148,8 +145,8 @@ func (mmDelete *mThingImageRepositoryMockDelete) ExpectCtxParam1(ctx context.Con
 	return mmDelete
 }
 
-// ExpectImageIDParam2 sets up expected param imageID for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) ExpectImageIDParam2(imageID int) *mThingImageRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingImageRepository.Delete
+func (mmDelete *mThingImageRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
@@ -165,35 +162,13 @@ func (mmDelete *mThingImageRepositoryMockDelete) ExpectImageIDParam2(imageID int
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.imageID = &imageID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingImageRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingImageRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingImageRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.Delete
-func (mmDelete *mThingImageRepositoryMockDelete) Inspect(f func(ctx context.Context, imageID int, tx *sql.Tx)) *mThingImageRepositoryMockDelete {
+func (mmDelete *mThingImageRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingImageRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.Delete")
 	}
@@ -217,7 +192,7 @@ func (mmDelete *mThingImageRepositoryMockDelete) Return(err error) *ThingImageRe
 }
 
 // Set uses given function f to mock the ThingImageRepository.Delete method
-func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context, imageID int, tx *sql.Tx) (err error)) *ThingImageRepositoryMock {
+func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingImageRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.Delete method")
 	}
@@ -232,14 +207,14 @@ func (mmDelete *mThingImageRepositoryMockDelete) Set(f func(ctx context.Context,
 
 // When sets expectation for the ThingImageRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingImageRepositoryMockDelete) When(ctx context.Context, imageID int, tx *sql.Tx) *ThingImageRepositoryMockDeleteExpectation {
+func (mmDelete *mThingImageRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingImageRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingImageRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingImageRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingImageRepositoryMockDeleteParams{ctx, imageID, tx},
+		params: &ThingImageRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -272,15 +247,15 @@ func (mmDelete *mThingImageRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements thing.ThingImageRepository
-func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, imageID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+	mm_params := ThingImageRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -299,7 +274,7 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingImageRepositoryMockDeleteParams{ctx, imageID, tx}
+		mm_got := ThingImageRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -307,12 +282,8 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.imageID != nil && !minimock.Equal(*mm_want_ptrs.imageID, mm_got.imageID) {
-				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter imageID, want: %#v, got: %#v%s\n", *mm_want_ptrs.imageID, mm_got.imageID, minimock.Diff(*mm_want_ptrs.imageID, mm_got.imageID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingImageRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -326,9 +297,9 @@ func (mmDelete *ThingImageRepositoryMock) Delete(ctx context.Context, imageID in
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, imageID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingImageRepositoryMock.Delete. %v %v %v", ctx, imageID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingImageRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 
@@ -423,14 +394,14 @@ type ThingImageRepositoryMockGetByThingIDExpectation struct {
 
 // ThingImageRepositoryMockGetByThingIDParams contains parameters of the ThingImageRepository.GetByThingID
 type ThingImageRepositoryMockGetByThingIDParams struct {
-	ctx     context.Context
-	thingID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingImageRepositoryMockGetByThingIDParamPtrs contains pointers to parameters of the ThingImageRepository.GetByThingID
 type ThingImageRepositoryMockGetByThingIDParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingImageRepositoryMockGetByThingIDResults contains results of the ThingImageRepository.GetByThingID
@@ -450,7 +421,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Optional() *mThingI
 }
 
 // Expect sets up expected params for ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.Context, thingID int) *mThingImageRepositoryMockGetByThingID {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.Context, id uint64) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -463,7 +434,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Expect(ctx context.
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByThingID.defaultExpectation.params = &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+	mmGetByThingID.defaultExpectation.params = &ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 	for _, e := range mmGetByThingID.expectations {
 		if minimock.Equal(e.params, mmGetByThingID.defaultExpectation.params) {
 			mmGetByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByThingID.defaultExpectation.params)
@@ -495,8 +466,8 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectCtxParam1(ctx
 	return mmGetByThingID
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectThingIDParam2(thingID int) *mThingImageRepositoryMockGetByThingID {
+// ExpectIdParam2 sets up expected param id for ThingImageRepository.GetByThingID
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectIdParam2(id uint64) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
@@ -512,13 +483,13 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) ExpectThingIDParam2
 	if mmGetByThingID.defaultExpectation.paramPtrs == nil {
 		mmGetByThingID.defaultExpectation.paramPtrs = &ThingImageRepositoryMockGetByThingIDParamPtrs{}
 	}
-	mmGetByThingID.defaultExpectation.paramPtrs.thingID = &thingID
+	mmGetByThingID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByThingID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingImageRepository.GetByThingID
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, thingID int)) *mThingImageRepositoryMockGetByThingID {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Inspect(f func(ctx context.Context, id uint64)) *mThingImageRepositoryMockGetByThingID {
 	if mmGetByThingID.mock.inspectFuncGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("Inspect function is already set for ThingImageRepositoryMock.GetByThingID")
 	}
@@ -542,7 +513,7 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Return(ia1 []models
 }
 
 // Set uses given function f to mock the ThingImageRepository.GetByThingID method
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx context.Context, thingID int) (ia1 []models.Image, err error)) *ThingImageRepositoryMock {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx context.Context, id uint64) (ia1 []models.Image, err error)) *ThingImageRepositoryMock {
 	if mmGetByThingID.defaultExpectation != nil {
 		mmGetByThingID.mock.t.Fatalf("Default expectation is already set for the ThingImageRepository.GetByThingID method")
 	}
@@ -557,14 +528,14 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) Set(f func(ctx cont
 
 // When sets expectation for the ThingImageRepository.GetByThingID which will trigger the result defined by the following
 // Then helper
-func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) When(ctx context.Context, thingID int) *ThingImageRepositoryMockGetByThingIDExpectation {
+func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) When(ctx context.Context, id uint64) *ThingImageRepositoryMockGetByThingIDExpectation {
 	if mmGetByThingID.mock.funcGetByThingID != nil {
 		mmGetByThingID.mock.t.Fatalf("ThingImageRepositoryMock.GetByThingID mock is already set by Set")
 	}
 
 	expectation := &ThingImageRepositoryMockGetByThingIDExpectation{
 		mock:   mmGetByThingID.mock,
-		params: &ThingImageRepositoryMockGetByThingIDParams{ctx, thingID},
+		params: &ThingImageRepositoryMockGetByThingIDParams{ctx, id},
 	}
 	mmGetByThingID.expectations = append(mmGetByThingID.expectations, expectation)
 	return expectation
@@ -597,15 +568,15 @@ func (mmGetByThingID *mThingImageRepositoryMockGetByThingID) invocationsDone() b
 }
 
 // GetByThingID implements thing.ThingImageRepository
-func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context, thingID int) (ia1 []models.Image, err error) {
+func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context, id uint64) (ia1 []models.Image, err error) {
 	mm_atomic.AddUint64(&mmGetByThingID.beforeGetByThingIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByThingID.afterGetByThingIDCounter, 1)
 
 	if mmGetByThingID.inspectFuncGetByThingID != nil {
-		mmGetByThingID.inspectFuncGetByThingID(ctx, thingID)
+		mmGetByThingID.inspectFuncGetByThingID(ctx, id)
 	}
 
-	mm_params := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+	mm_params := ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 
 	// Record call args
 	mmGetByThingID.GetByThingIDMock.mutex.Lock()
@@ -624,7 +595,7 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 		mm_want := mmGetByThingID.GetByThingIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByThingID.GetByThingIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingImageRepositoryMockGetByThingIDParams{ctx, thingID}
+		mm_got := ThingImageRepositoryMockGetByThingIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -632,8 +603,8 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByThingID.t.Errorf("ThingImageRepositoryMock.GetByThingID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -647,9 +618,9 @@ func (mmGetByThingID *ThingImageRepositoryMock) GetByThingID(ctx context.Context
 		return (*mm_results).ia1, (*mm_results).err
 	}
 	if mmGetByThingID.funcGetByThingID != nil {
-		return mmGetByThingID.funcGetByThingID(ctx, thingID)
+		return mmGetByThingID.funcGetByThingID(ctx, id)
 	}
-	mmGetByThingID.t.Fatalf("Unexpected call to ThingImageRepositoryMock.GetByThingID. %v %v", ctx, thingID)
+	mmGetByThingID.t.Fatalf("Unexpected call to ThingImageRepositoryMock.GetByThingID. %v %v", ctx, id)
 	return
 }
 

+ 24 - 53
internal/api/v1/thing/mocks/thing_notification_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -19,8 +18,8 @@ type ThingNotificationRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDelete          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDelete   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDelete          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDelete   func(ctx context.Context, id uint64)
 	afterDeleteCounter  uint64
 	beforeDeleteCounter uint64
 	DeleteMock          mThingNotificationRepositoryMockDelete
@@ -65,16 +64,14 @@ type ThingNotificationRepositoryMockDeleteExpectation struct {
 
 // ThingNotificationRepositoryMockDeleteParams contains parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingNotificationRepositoryMockDeleteParamPtrs contains pointers to parameters of the ThingNotificationRepository.Delete
 type ThingNotificationRepositoryMockDeleteParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingNotificationRepositoryMockDeleteResults contains results of the ThingNotificationRepository.Delete
@@ -93,7 +90,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Optional() *mThingNotifi
 }
 
 // Expect sets up expected params for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Context, id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -106,7 +103,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Expect(ctx context.Conte
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by ExpectParams functions")
 	}
 
-	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mmDelete.defaultExpectation.params = &ThingNotificationRepositoryMockDeleteParams{ctx, id}
 	for _, e := range mmDelete.expectations {
 		if minimock.Equal(e.params, mmDelete.defaultExpectation.params) {
 			mmDelete.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDelete.defaultExpectation.params)
@@ -138,8 +135,8 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectCtxParam1(ctx cont
 	return mmDelete
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thingID int) *mThingNotificationRepositoryMockDelete {
+// ExpectIdParam2 sets up expected param id for ThingNotificationRepository.Delete
+func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectIdParam2(id uint64) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
@@ -155,35 +152,13 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectThingIDParam2(thin
 	if mmDelete.defaultExpectation.paramPtrs == nil {
 		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
 	}
-	mmDelete.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDelete
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) ExpectTxParam3(tx *sql.Tx) *mThingNotificationRepositoryMockDelete {
-	if mmDelete.mock.funcDelete != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
-	}
-
-	if mmDelete.defaultExpectation == nil {
-		mmDelete.defaultExpectation = &ThingNotificationRepositoryMockDeleteExpectation{}
-	}
-
-	if mmDelete.defaultExpectation.params != nil {
-		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Expect")
-	}
-
-	if mmDelete.defaultExpectation.paramPtrs == nil {
-		mmDelete.defaultExpectation.paramPtrs = &ThingNotificationRepositoryMockDeleteParamPtrs{}
-	}
-	mmDelete.defaultExpectation.paramPtrs.tx = &tx
+	mmDelete.defaultExpectation.paramPtrs.id = &id
 
 	return mmDelete
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingNotificationRepository.Delete
-func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingNotificationRepositoryMockDelete {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Inspect(f func(ctx context.Context, id uint64)) *mThingNotificationRepositoryMockDelete {
 	if mmDelete.mock.inspectFuncDelete != nil {
 		mmDelete.mock.t.Fatalf("Inspect function is already set for ThingNotificationRepositoryMock.Delete")
 	}
@@ -207,7 +182,7 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Return(err error) *Thing
 }
 
 // Set uses given function f to mock the ThingNotificationRepository.Delete method
-func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingNotificationRepositoryMock {
+func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.Context, id uint64) (err error)) *ThingNotificationRepositoryMock {
 	if mmDelete.defaultExpectation != nil {
 		mmDelete.mock.t.Fatalf("Default expectation is already set for the ThingNotificationRepository.Delete method")
 	}
@@ -222,14 +197,14 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) Set(f func(ctx context.C
 
 // When sets expectation for the ThingNotificationRepository.Delete which will trigger the result defined by the following
 // Then helper
-func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingNotificationRepositoryMockDeleteExpectation {
+func (mmDelete *mThingNotificationRepositoryMockDelete) When(ctx context.Context, id uint64) *ThingNotificationRepositoryMockDeleteExpectation {
 	if mmDelete.mock.funcDelete != nil {
 		mmDelete.mock.t.Fatalf("ThingNotificationRepositoryMock.Delete mock is already set by Set")
 	}
 
 	expectation := &ThingNotificationRepositoryMockDeleteExpectation{
 		mock:   mmDelete.mock,
-		params: &ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx},
+		params: &ThingNotificationRepositoryMockDeleteParams{ctx, id},
 	}
 	mmDelete.expectations = append(mmDelete.expectations, expectation)
 	return expectation
@@ -262,15 +237,15 @@ func (mmDelete *mThingNotificationRepositoryMockDelete) invocationsDone() bool {
 }
 
 // Delete implements thing.ThingNotificationRepository
-func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDelete.beforeDeleteCounter, 1)
 	defer mm_atomic.AddUint64(&mmDelete.afterDeleteCounter, 1)
 
 	if mmDelete.inspectFuncDelete != nil {
-		mmDelete.inspectFuncDelete(ctx, thingID, tx)
+		mmDelete.inspectFuncDelete(ctx, id)
 	}
 
-	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+	mm_params := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 	// Record call args
 	mmDelete.DeleteMock.mutex.Lock()
@@ -289,7 +264,7 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		mm_want := mmDelete.DeleteMock.defaultExpectation.params
 		mm_want_ptrs := mmDelete.DeleteMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, thingID, tx}
+		mm_got := ThingNotificationRepositoryMockDeleteParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -297,12 +272,8 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDelete.t.Errorf("ThingNotificationRepositoryMock.Delete got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -316,9 +287,9 @@ func (mmDelete *ThingNotificationRepositoryMock) Delete(ctx context.Context, thi
 		return (*mm_results).err
 	}
 	if mmDelete.funcDelete != nil {
-		return mmDelete.funcDelete(ctx, thingID, tx)
+		return mmDelete.funcDelete(ctx, id)
 	}
-	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v %v", ctx, thingID, tx)
+	mmDelete.t.Fatalf("Unexpected call to ThingNotificationRepositoryMock.Delete. %v %v", ctx, id)
 	return
 }
 

Різницю між файлами не показано, бо вона завелика
+ 45 - 729
internal/api/v1/thing/mocks/thing_repository_minimock.go


+ 47 - 76
internal/api/v1/thing/mocks/thing_tag_repository_minimock.go

@@ -1,4 +1,4 @@
-// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT.
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
 
 package mocks
 
@@ -6,7 +6,6 @@ package mocks
 
 import (
 	"context"
-	"database/sql"
 	"sync"
 	mm_atomic "sync/atomic"
 	mm_time "time"
@@ -20,14 +19,14 @@ type ThingTagRepositoryMock struct {
 	t          minimock.Tester
 	finishOnce sync.Once
 
-	funcDeleteByThingID          func(ctx context.Context, thingID int, tx *sql.Tx) (err error)
-	inspectFuncDeleteByThingID   func(ctx context.Context, thingID int, tx *sql.Tx)
+	funcDeleteByThingID          func(ctx context.Context, id uint64) (err error)
+	inspectFuncDeleteByThingID   func(ctx context.Context, id uint64)
 	afterDeleteByThingIDCounter  uint64
 	beforeDeleteByThingIDCounter uint64
 	DeleteByThingIDMock          mThingTagRepositoryMockDeleteByThingID
 
-	funcGetByPlaceID          func(ctx context.Context, placeID int) (ta1 []models.ThingTag, err error)
-	inspectFuncGetByPlaceID   func(ctx context.Context, placeID int)
+	funcGetByPlaceID          func(ctx context.Context, id uint64) (ta1 []models.ThingTag, err error)
+	inspectFuncGetByPlaceID   func(ctx context.Context, id uint64)
 	afterGetByPlaceIDCounter  uint64
 	beforeGetByPlaceIDCounter uint64
 	GetByPlaceIDMock          mThingTagRepositoryMockGetByPlaceID
@@ -75,16 +74,14 @@ type ThingTagRepositoryMockDeleteByThingIDExpectation struct {
 
 // ThingTagRepositoryMockDeleteByThingIDParams contains parameters of the ThingTagRepository.DeleteByThingID
 type ThingTagRepositoryMockDeleteByThingIDParams struct {
-	ctx     context.Context
-	thingID int
-	tx      *sql.Tx
+	ctx context.Context
+	id  uint64
 }
 
 // ThingTagRepositoryMockDeleteByThingIDParamPtrs contains pointers to parameters of the ThingTagRepository.DeleteByThingID
 type ThingTagRepositoryMockDeleteByThingIDParamPtrs struct {
-	ctx     *context.Context
-	thingID *int
-	tx      **sql.Tx
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingTagRepositoryMockDeleteByThingIDResults contains results of the ThingTagRepository.DeleteByThingID
@@ -103,7 +100,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Optional() *mTh
 }
 
 // Expect sets up expected params for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx context.Context, thingID int, tx *sql.Tx) *mThingTagRepositoryMockDeleteByThingID {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx context.Context, id uint64) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
@@ -116,7 +113,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Expect(ctx cont
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by ExpectParams functions")
 	}
 
-	mmDeleteByThingID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+	mmDeleteByThingID.defaultExpectation.params = &ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 	for _, e := range mmDeleteByThingID.expectations {
 		if minimock.Equal(e.params, mmDeleteByThingID.defaultExpectation.params) {
 			mmDeleteByThingID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteByThingID.defaultExpectation.params)
@@ -148,8 +145,8 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectCtxParam1
 	return mmDeleteByThingID
 }
 
-// ExpectThingIDParam2 sets up expected param thingID for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectThingIDParam2(thingID int) *mThingTagRepositoryMockDeleteByThingID {
+// ExpectIdParam2 sets up expected param id for ThingTagRepository.DeleteByThingID
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectIdParam2(id uint64) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
@@ -165,35 +162,13 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectThingIDPa
 	if mmDeleteByThingID.defaultExpectation.paramPtrs == nil {
 		mmDeleteByThingID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByThingIDParamPtrs{}
 	}
-	mmDeleteByThingID.defaultExpectation.paramPtrs.thingID = &thingID
-
-	return mmDeleteByThingID
-}
-
-// ExpectTxParam3 sets up expected param tx for ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) ExpectTxParam3(tx *sql.Tx) *mThingTagRepositoryMockDeleteByThingID {
-	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
-		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
-	}
-
-	if mmDeleteByThingID.defaultExpectation == nil {
-		mmDeleteByThingID.defaultExpectation = &ThingTagRepositoryMockDeleteByThingIDExpectation{}
-	}
-
-	if mmDeleteByThingID.defaultExpectation.params != nil {
-		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Expect")
-	}
-
-	if mmDeleteByThingID.defaultExpectation.paramPtrs == nil {
-		mmDeleteByThingID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockDeleteByThingIDParamPtrs{}
-	}
-	mmDeleteByThingID.defaultExpectation.paramPtrs.tx = &tx
+	mmDeleteByThingID.defaultExpectation.paramPtrs.id = &id
 
 	return mmDeleteByThingID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.DeleteByThingID
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Inspect(f func(ctx context.Context, thingID int, tx *sql.Tx)) *mThingTagRepositoryMockDeleteByThingID {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Inspect(f func(ctx context.Context, id uint64)) *mThingTagRepositoryMockDeleteByThingID {
 	if mmDeleteByThingID.mock.inspectFuncDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.DeleteByThingID")
 	}
@@ -217,7 +192,7 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Return(err erro
 }
 
 // Set uses given function f to mock the ThingTagRepository.DeleteByThingID method
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx context.Context, thingID int, tx *sql.Tx) (err error)) *ThingTagRepositoryMock {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx context.Context, id uint64) (err error)) *ThingTagRepositoryMock {
 	if mmDeleteByThingID.defaultExpectation != nil {
 		mmDeleteByThingID.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.DeleteByThingID method")
 	}
@@ -232,14 +207,14 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) Set(f func(ctx
 
 // When sets expectation for the ThingTagRepository.DeleteByThingID which will trigger the result defined by the following
 // Then helper
-func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) When(ctx context.Context, thingID int, tx *sql.Tx) *ThingTagRepositoryMockDeleteByThingIDExpectation {
+func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) When(ctx context.Context, id uint64) *ThingTagRepositoryMockDeleteByThingIDExpectation {
 	if mmDeleteByThingID.mock.funcDeleteByThingID != nil {
 		mmDeleteByThingID.mock.t.Fatalf("ThingTagRepositoryMock.DeleteByThingID mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockDeleteByThingIDExpectation{
 		mock:   mmDeleteByThingID.mock,
-		params: &ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx},
+		params: &ThingTagRepositoryMockDeleteByThingIDParams{ctx, id},
 	}
 	mmDeleteByThingID.expectations = append(mmDeleteByThingID.expectations, expectation)
 	return expectation
@@ -272,15 +247,15 @@ func (mmDeleteByThingID *mThingTagRepositoryMockDeleteByThingID) invocationsDone
 }
 
 // DeleteByThingID implements thing.ThingTagRepository
-func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Context, thingID int, tx *sql.Tx) (err error) {
+func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Context, id uint64) (err error) {
 	mm_atomic.AddUint64(&mmDeleteByThingID.beforeDeleteByThingIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmDeleteByThingID.afterDeleteByThingIDCounter, 1)
 
 	if mmDeleteByThingID.inspectFuncDeleteByThingID != nil {
-		mmDeleteByThingID.inspectFuncDeleteByThingID(ctx, thingID, tx)
+		mmDeleteByThingID.inspectFuncDeleteByThingID(ctx, id)
 	}
 
-	mm_params := ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+	mm_params := ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 
 	// Record call args
 	mmDeleteByThingID.DeleteByThingIDMock.mutex.Lock()
@@ -299,7 +274,7 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 		mm_want := mmDeleteByThingID.DeleteByThingIDMock.defaultExpectation.params
 		mm_want_ptrs := mmDeleteByThingID.DeleteByThingIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockDeleteByThingIDParams{ctx, thingID, tx}
+		mm_got := ThingTagRepositoryMockDeleteByThingIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -307,12 +282,8 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.thingID != nil && !minimock.Equal(*mm_want_ptrs.thingID, mm_got.thingID) {
-				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter thingID, want: %#v, got: %#v%s\n", *mm_want_ptrs.thingID, mm_got.thingID, minimock.Diff(*mm_want_ptrs.thingID, mm_got.thingID))
-			}
-
-			if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
-				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmDeleteByThingID.t.Errorf("ThingTagRepositoryMock.DeleteByThingID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -326,9 +297,9 @@ func (mmDeleteByThingID *ThingTagRepositoryMock) DeleteByThingID(ctx context.Con
 		return (*mm_results).err
 	}
 	if mmDeleteByThingID.funcDeleteByThingID != nil {
-		return mmDeleteByThingID.funcDeleteByThingID(ctx, thingID, tx)
+		return mmDeleteByThingID.funcDeleteByThingID(ctx, id)
 	}
-	mmDeleteByThingID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByThingID. %v %v %v", ctx, thingID, tx)
+	mmDeleteByThingID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.DeleteByThingID. %v %v", ctx, id)
 	return
 }
 
@@ -423,14 +394,14 @@ type ThingTagRepositoryMockGetByPlaceIDExpectation struct {
 
 // ThingTagRepositoryMockGetByPlaceIDParams contains parameters of the ThingTagRepository.GetByPlaceID
 type ThingTagRepositoryMockGetByPlaceIDParams struct {
-	ctx     context.Context
-	placeID int
+	ctx context.Context
+	id  uint64
 }
 
 // ThingTagRepositoryMockGetByPlaceIDParamPtrs contains pointers to parameters of the ThingTagRepository.GetByPlaceID
 type ThingTagRepositoryMockGetByPlaceIDParamPtrs struct {
-	ctx     *context.Context
-	placeID *int
+	ctx *context.Context
+	id  *uint64
 }
 
 // ThingTagRepositoryMockGetByPlaceIDResults contains results of the ThingTagRepository.GetByPlaceID
@@ -450,7 +421,7 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Optional() *mThingTag
 }
 
 // Expect sets up expected params for ThingTagRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Expect(ctx context.Context, placeID int) *mThingTagRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Expect(ctx context.Context, id uint64) *mThingTagRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingTagRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -463,7 +434,7 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Expect(ctx context.Co
 		mmGetByPlaceID.mock.t.Fatalf("ThingTagRepositoryMock.GetByPlaceID mock is already set by ExpectParams functions")
 	}
 
-	mmGetByPlaceID.defaultExpectation.params = &ThingTagRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mmGetByPlaceID.defaultExpectation.params = &ThingTagRepositoryMockGetByPlaceIDParams{ctx, id}
 	for _, e := range mmGetByPlaceID.expectations {
 		if minimock.Equal(e.params, mmGetByPlaceID.defaultExpectation.params) {
 			mmGetByPlaceID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetByPlaceID.defaultExpectation.params)
@@ -495,8 +466,8 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) ExpectCtxParam1(ctx c
 	return mmGetByPlaceID
 }
 
-// ExpectPlaceIDParam2 sets up expected param placeID for ThingTagRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) ExpectPlaceIDParam2(placeID int) *mThingTagRepositoryMockGetByPlaceID {
+// ExpectIdParam2 sets up expected param id for ThingTagRepository.GetByPlaceID
+func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) ExpectIdParam2(id uint64) *mThingTagRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingTagRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
@@ -512,13 +483,13 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) ExpectPlaceIDParam2(p
 	if mmGetByPlaceID.defaultExpectation.paramPtrs == nil {
 		mmGetByPlaceID.defaultExpectation.paramPtrs = &ThingTagRepositoryMockGetByPlaceIDParamPtrs{}
 	}
-	mmGetByPlaceID.defaultExpectation.paramPtrs.placeID = &placeID
+	mmGetByPlaceID.defaultExpectation.paramPtrs.id = &id
 
 	return mmGetByPlaceID
 }
 
 // Inspect accepts an inspector function that has same arguments as the ThingTagRepository.GetByPlaceID
-func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, placeID int)) *mThingTagRepositoryMockGetByPlaceID {
+func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Inspect(f func(ctx context.Context, id uint64)) *mThingTagRepositoryMockGetByPlaceID {
 	if mmGetByPlaceID.mock.inspectFuncGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Inspect function is already set for ThingTagRepositoryMock.GetByPlaceID")
 	}
@@ -542,7 +513,7 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Return(ta1 []models.T
 }
 
 // Set uses given function f to mock the ThingTagRepository.GetByPlaceID method
-func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, placeID int) (ta1 []models.ThingTag, err error)) *ThingTagRepositoryMock {
+func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Set(f func(ctx context.Context, id uint64) (ta1 []models.ThingTag, err error)) *ThingTagRepositoryMock {
 	if mmGetByPlaceID.defaultExpectation != nil {
 		mmGetByPlaceID.mock.t.Fatalf("Default expectation is already set for the ThingTagRepository.GetByPlaceID method")
 	}
@@ -557,14 +528,14 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) Set(f func(ctx contex
 
 // When sets expectation for the ThingTagRepository.GetByPlaceID which will trigger the result defined by the following
 // Then helper
-func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) When(ctx context.Context, placeID int) *ThingTagRepositoryMockGetByPlaceIDExpectation {
+func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) When(ctx context.Context, id uint64) *ThingTagRepositoryMockGetByPlaceIDExpectation {
 	if mmGetByPlaceID.mock.funcGetByPlaceID != nil {
 		mmGetByPlaceID.mock.t.Fatalf("ThingTagRepositoryMock.GetByPlaceID mock is already set by Set")
 	}
 
 	expectation := &ThingTagRepositoryMockGetByPlaceIDExpectation{
 		mock:   mmGetByPlaceID.mock,
-		params: &ThingTagRepositoryMockGetByPlaceIDParams{ctx, placeID},
+		params: &ThingTagRepositoryMockGetByPlaceIDParams{ctx, id},
 	}
 	mmGetByPlaceID.expectations = append(mmGetByPlaceID.expectations, expectation)
 	return expectation
@@ -597,15 +568,15 @@ func (mmGetByPlaceID *mThingTagRepositoryMockGetByPlaceID) invocationsDone() boo
 }
 
 // GetByPlaceID implements thing.ThingTagRepository
-func (mmGetByPlaceID *ThingTagRepositoryMock) GetByPlaceID(ctx context.Context, placeID int) (ta1 []models.ThingTag, err error) {
+func (mmGetByPlaceID *ThingTagRepositoryMock) GetByPlaceID(ctx context.Context, id uint64) (ta1 []models.ThingTag, err error) {
 	mm_atomic.AddUint64(&mmGetByPlaceID.beforeGetByPlaceIDCounter, 1)
 	defer mm_atomic.AddUint64(&mmGetByPlaceID.afterGetByPlaceIDCounter, 1)
 
 	if mmGetByPlaceID.inspectFuncGetByPlaceID != nil {
-		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, placeID)
+		mmGetByPlaceID.inspectFuncGetByPlaceID(ctx, id)
 	}
 
-	mm_params := ThingTagRepositoryMockGetByPlaceIDParams{ctx, placeID}
+	mm_params := ThingTagRepositoryMockGetByPlaceIDParams{ctx, id}
 
 	// Record call args
 	mmGetByPlaceID.GetByPlaceIDMock.mutex.Lock()
@@ -624,7 +595,7 @@ func (mmGetByPlaceID *ThingTagRepositoryMock) GetByPlaceID(ctx context.Context,
 		mm_want := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.params
 		mm_want_ptrs := mmGetByPlaceID.GetByPlaceIDMock.defaultExpectation.paramPtrs
 
-		mm_got := ThingTagRepositoryMockGetByPlaceIDParams{ctx, placeID}
+		mm_got := ThingTagRepositoryMockGetByPlaceIDParams{ctx, id}
 
 		if mm_want_ptrs != nil {
 
@@ -632,8 +603,8 @@ func (mmGetByPlaceID *ThingTagRepositoryMock) GetByPlaceID(ctx context.Context,
 				mmGetByPlaceID.t.Errorf("ThingTagRepositoryMock.GetByPlaceID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
 			}
 
-			if mm_want_ptrs.placeID != nil && !minimock.Equal(*mm_want_ptrs.placeID, mm_got.placeID) {
-				mmGetByPlaceID.t.Errorf("ThingTagRepositoryMock.GetByPlaceID got unexpected parameter placeID, want: %#v, got: %#v%s\n", *mm_want_ptrs.placeID, mm_got.placeID, minimock.Diff(*mm_want_ptrs.placeID, mm_got.placeID))
+			if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
+				mmGetByPlaceID.t.Errorf("ThingTagRepositoryMock.GetByPlaceID got unexpected parameter id, want: %#v, got: %#v%s\n", *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
 			}
 
 		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
@@ -647,9 +618,9 @@ func (mmGetByPlaceID *ThingTagRepositoryMock) GetByPlaceID(ctx context.Context,
 		return (*mm_results).ta1, (*mm_results).err
 	}
 	if mmGetByPlaceID.funcGetByPlaceID != nil {
-		return mmGetByPlaceID.funcGetByPlaceID(ctx, placeID)
+		return mmGetByPlaceID.funcGetByPlaceID(ctx, id)
 	}
-	mmGetByPlaceID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.GetByPlaceID. %v %v", ctx, placeID)
+	mmGetByPlaceID.t.Fatalf("Unexpected call to ThingTagRepositoryMock.GetByPlaceID. %v %v", ctx, id)
 	return
 }
 

+ 393 - 0
internal/api/v1/thing/mocks/transaction_manager_minimock.go

@@ -0,0 +1,393 @@
+// Code generated by http://github.com/gojuno/minimock (v3.3.14). DO NOT EDIT.
+
+package mocks
+
+//go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing.TransactionManager -o transaction_manager_minimock.go -n TransactionManagerMock -p mocks
+
+import (
+	"context"
+	"sync"
+	mm_atomic "sync/atomic"
+	mm_time "time"
+
+	"github.com/gojuno/minimock/v3"
+)
+
+// TransactionManagerMock implements thing.TransactionManager
+type TransactionManagerMock struct {
+	t          minimock.Tester
+	finishOnce sync.Once
+
+	funcReadCommitted          func(ctx context.Context, f1 func(ctx context.Context) error) (err error)
+	inspectFuncReadCommitted   func(ctx context.Context, f1 func(ctx context.Context) error)
+	afterReadCommittedCounter  uint64
+	beforeReadCommittedCounter uint64
+	ReadCommittedMock          mTransactionManagerMockReadCommitted
+}
+
+// NewTransactionManagerMock returns a mock for thing.TransactionManager
+func NewTransactionManagerMock(t minimock.Tester) *TransactionManagerMock {
+	m := &TransactionManagerMock{t: t}
+
+	if controller, ok := t.(minimock.MockController); ok {
+		controller.RegisterMocker(m)
+	}
+
+	m.ReadCommittedMock = mTransactionManagerMockReadCommitted{mock: m}
+	m.ReadCommittedMock.callArgs = []*TransactionManagerMockReadCommittedParams{}
+
+	t.Cleanup(m.MinimockFinish)
+
+	return m
+}
+
+type mTransactionManagerMockReadCommitted struct {
+	optional           bool
+	mock               *TransactionManagerMock
+	defaultExpectation *TransactionManagerMockReadCommittedExpectation
+	expectations       []*TransactionManagerMockReadCommittedExpectation
+
+	callArgs []*TransactionManagerMockReadCommittedParams
+	mutex    sync.RWMutex
+
+	expectedInvocations uint64
+}
+
+// TransactionManagerMockReadCommittedExpectation specifies expectation struct of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedExpectation struct {
+	mock      *TransactionManagerMock
+	params    *TransactionManagerMockReadCommittedParams
+	paramPtrs *TransactionManagerMockReadCommittedParamPtrs
+	results   *TransactionManagerMockReadCommittedResults
+	Counter   uint64
+}
+
+// TransactionManagerMockReadCommittedParams contains parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParams struct {
+	ctx context.Context
+	f1  func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedParamPtrs contains pointers to parameters of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedParamPtrs struct {
+	ctx *context.Context
+	f1  *func(ctx context.Context) error
+}
+
+// TransactionManagerMockReadCommittedResults contains results of the TransactionManager.ReadCommitted
+type TransactionManagerMockReadCommittedResults struct {
+	err error
+}
+
+// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
+// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
+// Optional() makes method check to work in '0 or more' mode.
+// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
+// catch the problems when the expected method call is totally skipped during test run.
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Optional() *mTransactionManagerMockReadCommitted {
+	mmReadCommitted.optional = true
+	return mmReadCommitted
+}
+
+// Expect sets up expected params for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Expect(ctx context.Context, f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by ExpectParams functions")
+	}
+
+	mmReadCommitted.defaultExpectation.params = &TransactionManagerMockReadCommittedParams{ctx, f1}
+	for _, e := range mmReadCommitted.expectations {
+		if minimock.Equal(e.params, mmReadCommitted.defaultExpectation.params) {
+			mmReadCommitted.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmReadCommitted.defaultExpectation.params)
+		}
+	}
+
+	return mmReadCommitted
+}
+
+// ExpectCtxParam1 sets up expected param ctx for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectCtxParam1(ctx context.Context) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.ctx = &ctx
+
+	return mmReadCommitted
+}
+
+// ExpectF1Param2 sets up expected param f1 for TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) ExpectF1Param2(f1 func(ctx context.Context) error) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{}
+	}
+
+	if mmReadCommitted.defaultExpectation.params != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Expect")
+	}
+
+	if mmReadCommitted.defaultExpectation.paramPtrs == nil {
+		mmReadCommitted.defaultExpectation.paramPtrs = &TransactionManagerMockReadCommittedParamPtrs{}
+	}
+	mmReadCommitted.defaultExpectation.paramPtrs.f1 = &f1
+
+	return mmReadCommitted
+}
+
+// Inspect accepts an inspector function that has same arguments as the TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Inspect(f func(ctx context.Context, f1 func(ctx context.Context) error)) *mTransactionManagerMockReadCommitted {
+	if mmReadCommitted.mock.inspectFuncReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("Inspect function is already set for TransactionManagerMock.ReadCommitted")
+	}
+
+	mmReadCommitted.mock.inspectFuncReadCommitted = f
+
+	return mmReadCommitted
+}
+
+// Return sets up results that will be returned by TransactionManager.ReadCommitted
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Return(err error) *TransactionManagerMock {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	if mmReadCommitted.defaultExpectation == nil {
+		mmReadCommitted.defaultExpectation = &TransactionManagerMockReadCommittedExpectation{mock: mmReadCommitted.mock}
+	}
+	mmReadCommitted.defaultExpectation.results = &TransactionManagerMockReadCommittedResults{err}
+	return mmReadCommitted.mock
+}
+
+// Set uses given function f to mock the TransactionManager.ReadCommitted method
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Set(f func(ctx context.Context, f1 func(ctx context.Context) error) (err error)) *TransactionManagerMock {
+	if mmReadCommitted.defaultExpectation != nil {
+		mmReadCommitted.mock.t.Fatalf("Default expectation is already set for the TransactionManager.ReadCommitted method")
+	}
+
+	if len(mmReadCommitted.expectations) > 0 {
+		mmReadCommitted.mock.t.Fatalf("Some expectations are already set for the TransactionManager.ReadCommitted method")
+	}
+
+	mmReadCommitted.mock.funcReadCommitted = f
+	return mmReadCommitted.mock
+}
+
+// When sets expectation for the TransactionManager.ReadCommitted which will trigger the result defined by the following
+// Then helper
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) When(ctx context.Context, f1 func(ctx context.Context) error) *TransactionManagerMockReadCommittedExpectation {
+	if mmReadCommitted.mock.funcReadCommitted != nil {
+		mmReadCommitted.mock.t.Fatalf("TransactionManagerMock.ReadCommitted mock is already set by Set")
+	}
+
+	expectation := &TransactionManagerMockReadCommittedExpectation{
+		mock:   mmReadCommitted.mock,
+		params: &TransactionManagerMockReadCommittedParams{ctx, f1},
+	}
+	mmReadCommitted.expectations = append(mmReadCommitted.expectations, expectation)
+	return expectation
+}
+
+// Then sets up TransactionManager.ReadCommitted return parameters for the expectation previously defined by the When method
+func (e *TransactionManagerMockReadCommittedExpectation) Then(err error) *TransactionManagerMock {
+	e.results = &TransactionManagerMockReadCommittedResults{err}
+	return e.mock
+}
+
+// Times sets number of times TransactionManager.ReadCommitted should be invoked
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Times(n uint64) *mTransactionManagerMockReadCommitted {
+	if n == 0 {
+		mmReadCommitted.mock.t.Fatalf("Times of TransactionManagerMock.ReadCommitted mock can not be zero")
+	}
+	mm_atomic.StoreUint64(&mmReadCommitted.expectedInvocations, n)
+	return mmReadCommitted
+}
+
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) invocationsDone() bool {
+	if len(mmReadCommitted.expectations) == 0 && mmReadCommitted.defaultExpectation == nil && mmReadCommitted.mock.funcReadCommitted == nil {
+		return true
+	}
+
+	totalInvocations := mm_atomic.LoadUint64(&mmReadCommitted.mock.afterReadCommittedCounter)
+	expectedInvocations := mm_atomic.LoadUint64(&mmReadCommitted.expectedInvocations)
+
+	return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
+}
+
+// ReadCommitted implements thing.TransactionManager
+func (mmReadCommitted *TransactionManagerMock) ReadCommitted(ctx context.Context, f1 func(ctx context.Context) error) (err error) {
+	mm_atomic.AddUint64(&mmReadCommitted.beforeReadCommittedCounter, 1)
+	defer mm_atomic.AddUint64(&mmReadCommitted.afterReadCommittedCounter, 1)
+
+	if mmReadCommitted.inspectFuncReadCommitted != nil {
+		mmReadCommitted.inspectFuncReadCommitted(ctx, f1)
+	}
+
+	mm_params := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+	// Record call args
+	mmReadCommitted.ReadCommittedMock.mutex.Lock()
+	mmReadCommitted.ReadCommittedMock.callArgs = append(mmReadCommitted.ReadCommittedMock.callArgs, &mm_params)
+	mmReadCommitted.ReadCommittedMock.mutex.Unlock()
+
+	for _, e := range mmReadCommitted.ReadCommittedMock.expectations {
+		if minimock.Equal(*e.params, mm_params) {
+			mm_atomic.AddUint64(&e.Counter, 1)
+			return e.results.err
+		}
+	}
+
+	if mmReadCommitted.ReadCommittedMock.defaultExpectation != nil {
+		mm_atomic.AddUint64(&mmReadCommitted.ReadCommittedMock.defaultExpectation.Counter, 1)
+		mm_want := mmReadCommitted.ReadCommittedMock.defaultExpectation.params
+		mm_want_ptrs := mmReadCommitted.ReadCommittedMock.defaultExpectation.paramPtrs
+
+		mm_got := TransactionManagerMockReadCommittedParams{ctx, f1}
+
+		if mm_want_ptrs != nil {
+
+			if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
+			}
+
+			if mm_want_ptrs.f1 != nil && !minimock.Equal(*mm_want_ptrs.f1, mm_got.f1) {
+				mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameter f1, want: %#v, got: %#v%s\n", *mm_want_ptrs.f1, mm_got.f1, minimock.Diff(*mm_want_ptrs.f1, mm_got.f1))
+			}
+
+		} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
+			mmReadCommitted.t.Errorf("TransactionManagerMock.ReadCommitted got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
+		}
+
+		mm_results := mmReadCommitted.ReadCommittedMock.defaultExpectation.results
+		if mm_results == nil {
+			mmReadCommitted.t.Fatal("No results are set for the TransactionManagerMock.ReadCommitted")
+		}
+		return (*mm_results).err
+	}
+	if mmReadCommitted.funcReadCommitted != nil {
+		return mmReadCommitted.funcReadCommitted(ctx, f1)
+	}
+	mmReadCommitted.t.Fatalf("Unexpected call to TransactionManagerMock.ReadCommitted. %v %v", ctx, f1)
+	return
+}
+
+// ReadCommittedAfterCounter returns a count of finished TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedAfterCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.afterReadCommittedCounter)
+}
+
+// ReadCommittedBeforeCounter returns a count of TransactionManagerMock.ReadCommitted invocations
+func (mmReadCommitted *TransactionManagerMock) ReadCommittedBeforeCounter() uint64 {
+	return mm_atomic.LoadUint64(&mmReadCommitted.beforeReadCommittedCounter)
+}
+
+// Calls returns a list of arguments used in each call to TransactionManagerMock.ReadCommitted.
+// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
+func (mmReadCommitted *mTransactionManagerMockReadCommitted) Calls() []*TransactionManagerMockReadCommittedParams {
+	mmReadCommitted.mutex.RLock()
+
+	argCopy := make([]*TransactionManagerMockReadCommittedParams, len(mmReadCommitted.callArgs))
+	copy(argCopy, mmReadCommitted.callArgs)
+
+	mmReadCommitted.mutex.RUnlock()
+
+	return argCopy
+}
+
+// MinimockReadCommittedDone returns true if the count of the ReadCommitted invocations corresponds
+// the number of defined expectations
+func (m *TransactionManagerMock) MinimockReadCommittedDone() bool {
+	if m.ReadCommittedMock.optional {
+		// Optional methods provide '0 or more' call count restriction.
+		return true
+	}
+
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			return false
+		}
+	}
+
+	return m.ReadCommittedMock.invocationsDone()
+}
+
+// MinimockReadCommittedInspect logs each unmet expectation
+func (m *TransactionManagerMock) MinimockReadCommittedInspect() {
+	for _, e := range m.ReadCommittedMock.expectations {
+		if mm_atomic.LoadUint64(&e.Counter) < 1 {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *e.params)
+		}
+	}
+
+	afterReadCommittedCounter := mm_atomic.LoadUint64(&m.afterReadCommittedCounter)
+	// if default expectation was set then invocations count should be greater than zero
+	if m.ReadCommittedMock.defaultExpectation != nil && afterReadCommittedCounter < 1 {
+		if m.ReadCommittedMock.defaultExpectation.params == nil {
+			m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+		} else {
+			m.t.Errorf("Expected call to TransactionManagerMock.ReadCommitted with params: %#v", *m.ReadCommittedMock.defaultExpectation.params)
+		}
+	}
+	// if func was set then invocations count should be greater than zero
+	if m.funcReadCommitted != nil && afterReadCommittedCounter < 1 {
+		m.t.Error("Expected call to TransactionManagerMock.ReadCommitted")
+	}
+
+	if !m.ReadCommittedMock.invocationsDone() && afterReadCommittedCounter > 0 {
+		m.t.Errorf("Expected %d calls to TransactionManagerMock.ReadCommitted but found %d calls",
+			mm_atomic.LoadUint64(&m.ReadCommittedMock.expectedInvocations), afterReadCommittedCounter)
+	}
+}
+
+// MinimockFinish checks that all mocked methods have been called the expected number of times
+func (m *TransactionManagerMock) MinimockFinish() {
+	m.finishOnce.Do(func() {
+		if !m.minimockDone() {
+			m.MinimockReadCommittedInspect()
+		}
+	})
+}
+
+// MinimockWait waits for all mocked methods to be called the expected number of times
+func (m *TransactionManagerMock) MinimockWait(timeout mm_time.Duration) {
+	timeoutCh := mm_time.After(timeout)
+	for {
+		if m.minimockDone() {
+			return
+		}
+		select {
+		case <-timeoutCh:
+			m.MinimockFinish()
+			return
+		case <-mm_time.After(10 * mm_time.Millisecond):
+		}
+	}
+}
+
+func (m *TransactionManagerMock) minimockDone() bool {
+	done := true
+	return done &&
+		m.MinimockReadCommittedDone()
+}

+ 4 - 2
internal/api/v1/thing/search_thing.go

@@ -5,9 +5,10 @@ import (
 	"regexp"
 	"strings"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/gofiber/fiber/v2"
 
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -36,10 +37,11 @@ func SearchThingHandler(thingRepository ThingRepository) fiber.Handler {
 
 		res, err := thingRepository.Search(ctx, search)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingsResponse(res))
 	}

+ 11 - 10
internal/api/v1/thing/search_thing_test.go

@@ -2,7 +2,6 @@ package thing
 
 import (
 	"context"
-	"errors"
 	"net/http/httptest"
 	"net/url"
 	"testing"
@@ -12,10 +11,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -29,7 +27,7 @@ func TestSearchThingHandler(t *testing.T) {
 
 	var (
 		search    = gofakeit.LetterN(10)
-		testError = errors.New(gofakeit.Phrase())
+		testError = gofakeit.Error()
 		layout    = "2006-01-02 15:04:05"
 
 		correctReq = req{
@@ -39,16 +37,16 @@ func TestSearchThingHandler(t *testing.T) {
 
 		thingRepoRes = []models.Thing{
 			{
-				ID:          gofakeit.Number(1, 1000),
-				PlaceID:     gofakeit.Number(1, 1000),
+				ID:          uint64(gofakeit.Number(1, 1000)),
+				PlaceID:     uint64(gofakeit.Number(1, 1000)),
 				Title:       gofakeit.Phrase(),
 				Description: gofakeit.Phrase(),
 				CreatedAt:   gofakeit.Date(),
 				UpdatedAt:   gofakeit.Date(),
 			},
 			{
-				ID:          gofakeit.Number(1, 1000),
-				PlaceID:     gofakeit.Number(1, 1000),
+				ID:          uint64(gofakeit.Number(1, 1000)),
+				PlaceID:     uint64(gofakeit.Number(1, 1000)),
 				Title:       gofakeit.Phrase(),
 				Description: gofakeit.Phrase(),
 				CreatedAt:   gofakeit.Date(),
@@ -146,10 +144,13 @@ func TestSearchThingHandler(t *testing.T) {
 			fiberApp := fiber.New()
 			fiberApp.Get("/v1/things/search/:search", SearchThingHandler(tt.thingRepoMock(mc)))
 
-			fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(
+				httptest.NewRequest(tt.req.method, tt.req.route, nil),
+				test.TestTimeout,
+			)
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 36 - 28
internal/api/v1/thing/update_thing.go

@@ -1,13 +1,16 @@
 package thing
 
 import (
+	"context"
+
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/factory"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/location"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/request"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
 )
 
@@ -23,65 +26,70 @@ import (
 // @Accept      json
 // @Produce     json
 func UpdateThingHandler(
+	tm TransactionManager,
 	thingRepository ThingRepository,
 	placeThingRepository PlaceThingRepository,
 ) fiber.Handler {
 	return func(fctx *fiber.Ctx) error {
 		ctx := fctx.Context()
-		id, err := fctx.ParamsInt("thingId")
+		id, err := request.ConvertToUint64(fctx, "thingId")
 		if err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		req := dto.UpdateThingRequest{}
 		if err = fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err = validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
-		thing, err := thingRepository.Get(ctx, id)
-		if err != nil {
-			return fiber.NewError(fiber.StatusBadRequest, err.Error())
-		}
-
-		placeThing, err := placeThingRepository.GetByThingID(ctx, id)
-		if err != nil {
-			return fiber.NewError(fiber.StatusBadRequest, err.Error())
-		}
+		err = tm.ReadCommitted(ctx, func(ctx context.Context) error {
+			thing, txErr := thingRepository.Get(ctx, id)
+			if txErr != nil {
+				return txErr
+			}
 
-		tx, err := thingRepository.BeginTx(ctx, API.DefaultTxLevel)
-		if err != nil {
-			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
-		}
+			placeThing, txErr := placeThingRepository.GetByThingID(ctx, id)
+			if txErr != nil {
+				return txErr
+			}
 
-		if req.Title != thing.Title || req.Description != thing.Description {
-			err = thingRepository.Update(ctx, mappers.ToUpdateThingRequest(id, req), tx)
-			if err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			if req.Title != thing.Title || req.Description != thing.Description {
+				txErr = thingRepository.Update(ctx, mappers.ToUpdateThingRequest(id, req))
+				if txErr != nil {
+					return txErr
+				}
 			}
-		}
 
-		if placeThing.PlaceID != req.PlaceID {
-			err = placeThingRepository.UpdatePlace(ctx, mappers.ToUpdatePlaceThingRequest(id, req.PlaceID), tx)
-			if err != nil {
-				return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+			if placeThing.PlaceID != req.PlaceID {
+				txErr = placeThingRepository.UpdatePlace(ctx, mappers.ToUpdatePlaceThingRequest(id, req.PlaceID))
+				if txErr != nil {
+					return txErr
+				}
 			}
-		}
 
-		if err = thingRepository.CommitTx(tx); err != nil {
+			return nil
+		})
+
+		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		res, err := thingRepository.Get(ctx, id)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
-		res = helpers.ApplyLocation(fctx, res)
+		res = location.ApplyLocation(fctx, res)
 
 		return fctx.JSON(mappers.ToThingResponse(*res))
 	}

+ 82 - 107
internal/api/v1/thing/update_thing_test.go

@@ -3,7 +3,6 @@ package thing
 import (
 	"context"
 	"database/sql"
-	"errors"
 	"net/http/httptest"
 	"strconv"
 	"testing"
@@ -13,10 +12,9 @@ import (
 	"github.com/gojuno/minimock/v3"
 	"github.com/stretchr/testify/assert"
 
-	API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/dto"
-	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
+	"git.dmitriygnatenko.ru/dima/homethings/internal/helpers/test"
 	"git.dmitriygnatenko.ru/dima/homethings/internal/models"
 )
 
@@ -31,16 +29,20 @@ func TestUpdateThingHandler(t *testing.T) {
 	}
 
 	var (
-		placeID     = gofakeit.Number(1, 1000)
-		thingID     = gofakeit.Number(1, 1000)
+		placeID     = uint64(gofakeit.Number(1, 1000))
+		thingID     = uint64(gofakeit.Number(1, 1000))
 		title       = gofakeit.Phrase()
 		description = gofakeit.Phrase()
-		testError   = errors.New(gofakeit.Phrase())
+		testError   = gofakeit.Error()
 		layout      = "2006-01-02 15:04:05"
 
+		txMockFunc = func(ctx context.Context, f func(ctx context.Context) error) error {
+			return f(ctx)
+		}
+
 		correctReq = req{
 			method: fiber.MethodPut,
-			route:  "/v1/things/" + strconv.Itoa(thingID),
+			route:  "/v1/things/" + strconv.FormatUint(thingID, 10),
 			body: &dto.UpdateThingRequest{
 				PlaceID:     placeID,
 				Title:       title,
@@ -58,7 +60,7 @@ func TestUpdateThingHandler(t *testing.T) {
 		}
 
 		placeThingRepoResBeforeUpdate = models.PlaceThing{
-			PlaceID:   gofakeit.Number(1, 1000),
+			PlaceID:   uint64(gofakeit.Number(1, 1000)),
 			ThingID:   thingID,
 			CreatedAt: gofakeit.Date(),
 		}
@@ -85,6 +87,7 @@ func TestUpdateThingHandler(t *testing.T) {
 		req                req
 		resCode            int
 		resBody            interface{}
+		tmMock             func(mc *minimock.Controller) TransactionManager
 		thingRepoMock      func(mc *minimock.Controller) ThingRepository
 		placeThingRepoMock func(mc *minimock.Controller) PlaceThingRepository
 	}{
@@ -93,19 +96,20 @@ func TestUpdateThingHandler(t *testing.T) {
 			req:     correctReq,
 			resCode: fiber.StatusOK,
 			resBody: expectedRes,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
-				mock.GetMock.Set(func(ctx context.Context, id int) (*models.Thing, error) {
+				mock.GetMock.Set(func(ctx context.Context, id uint64) (*models.Thing, error) {
 					assert.Equal(mc, thingID, id)
 					if mock.GetAfterCounter() == 0 {
 						return &repoResBeforeUpdate, nil
@@ -118,11 +122,11 @@ func TestUpdateThingHandler(t *testing.T) {
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&placeThingRepoResBeforeUpdate, nil)
 
-				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) {
+				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest) {
 					assert.Equal(mc, placeID, req.PlaceID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(nil)
@@ -137,6 +141,9 @@ func TestUpdateThingHandler(t *testing.T) {
 				route:  "/v1/things/" + gofakeit.Word(),
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -148,9 +155,12 @@ func TestUpdateThingHandler(t *testing.T) {
 			name: "negative case - body parse error",
 			req: req{
 				method: fiber.MethodPut,
-				route:  "/v1/things/" + strconv.Itoa(thingID),
+				route:  "/v1/things/" + strconv.FormatUint(thingID, 10),
 			},
 			resCode: fiber.StatusBadRequest,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -162,7 +172,7 @@ func TestUpdateThingHandler(t *testing.T) {
 			name: "negative case - request without place_id",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/things/" + strconv.Itoa(thingID),
+				route:       "/v1/things/" + strconv.FormatUint(thingID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 				body: &dto.UpdateThingRequest{
 					Title: title,
@@ -175,6 +185,9 @@ func TestUpdateThingHandler(t *testing.T) {
 					Tag:   "required",
 				},
 			},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -186,7 +199,7 @@ func TestUpdateThingHandler(t *testing.T) {
 			name: "negative case - request without title",
 			req: req{
 				method:      fiber.MethodPut,
-				route:       "/v1/things/" + strconv.Itoa(thingID),
+				route:       "/v1/things/" + strconv.FormatUint(thingID, 10),
 				contentType: fiber.MIMEApplicationJSON,
 				body: &dto.UpdateThingRequest{
 					PlaceID: placeID,
@@ -199,6 +212,9 @@ func TestUpdateThingHandler(t *testing.T) {
 					Tag:   "required",
 				},
 			},
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				return mocks.NewTransactionManagerMock(mc)
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				return mocks.NewThingRepositoryMock(mc)
 			},
@@ -209,11 +225,16 @@ func TestUpdateThingHandler(t *testing.T) {
 		{
 			name:    "negative case - repository error (get thing)",
 			req:     correctReq,
-			resCode: fiber.StatusBadRequest,
+			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(nil, sql.ErrNoRows)
 
@@ -226,47 +247,27 @@ func TestUpdateThingHandler(t *testing.T) {
 		{
 			name:    "negative case - repository error (get place thing)",
 			req:     correctReq,
-			resCode: fiber.StatusBadRequest,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(&repoResBeforeUpdate, nil)
-
-				return mock
-			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				mock := mocks.NewPlaceThingRepositoryMock(mc)
-
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(nil, sql.ErrNoRows)
-
+			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-		},
-		{
-			name:    "negative case - repository error (begin tx)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoResBeforeUpdate, nil)
 
-				mock.BeginTxMock.Return(nil, testError)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
-				}).Return(&placeThingRepoResBeforeUpdate, nil)
+				}).Return(nil, sql.ErrNoRows)
 
 				return mock
 			},
@@ -275,16 +276,19 @@ func TestUpdateThingHandler(t *testing.T) {
 			name:    "negative case - repository error (update thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoResBeforeUpdate, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(testError)
@@ -294,7 +298,7 @@ func TestUpdateThingHandler(t *testing.T) {
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&placeThingRepoResBeforeUpdate, nil)
 
@@ -305,70 +309,36 @@ func TestUpdateThingHandler(t *testing.T) {
 			name:    "negative case - repository error (update place)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
-			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
-				mock := mocks.NewThingRepositoryMock(mc)
-
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(&repoResBeforeUpdate, nil)
-
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) {
-					assert.Equal(mc, title, req.Title)
-					assert.Equal(mc, description, req.Description)
-				}).Return(nil)
-
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
 				return mock
 			},
-			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
-				mock := mocks.NewPlaceThingRepositoryMock(mc)
-
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
-					assert.Equal(mc, thingID, id)
-				}).Return(&placeThingRepoResBeforeUpdate, nil)
-
-				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) {
-					assert.Equal(mc, placeID, req.PlaceID)
-					assert.Equal(mc, thingID, req.ThingID)
-				}).Return(testError)
-
-				return mock
-			},
-		},
-		{
-			name:    "negative case - repository error (commit tx)",
-			req:     correctReq,
-			resCode: fiber.StatusInternalServerError,
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&repoResBeforeUpdate, nil)
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(testError)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&placeThingRepoResBeforeUpdate, nil)
 
-				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) {
+				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest) {
 					assert.Equal(mc, placeID, req.PlaceID)
 					assert.Equal(mc, thingID, req.ThingID)
-				}).Return(nil)
+				}).Return(testError)
 
 				return mock
 			},
@@ -377,35 +347,36 @@ func TestUpdateThingHandler(t *testing.T) {
 			name:    "negative case - repository error (get thing)",
 			req:     correctReq,
 			resCode: fiber.StatusInternalServerError,
+			tmMock: func(mc *minimock.Controller) TransactionManager {
+				mock := mocks.NewTransactionManagerMock(mc)
+				mock.ReadCommittedMock.Set(txMockFunc)
+				return mock
+			},
 			thingRepoMock: func(mc *minimock.Controller) ThingRepository {
 				mock := mocks.NewThingRepositoryMock(mc)
 
-				mock.GetMock.Set(func(ctx context.Context, thingID int) (*models.Thing, error) {
+				mock.GetMock.Set(func(ctx context.Context, thingID uint64) (*models.Thing, error) {
 					if mock.GetAfterCounter() == 0 {
 						return &repoResBeforeUpdate, nil
 					}
 					return nil, sql.ErrNoRows
 				})
 
-				mock.BeginTxMock.Return(nil, nil)
-
-				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest, tx *sql.Tx) {
+				mock.UpdateMock.Inspect(func(ctx context.Context, req models.UpdateThingRequest) {
 					assert.Equal(mc, title, req.Title)
 					assert.Equal(mc, description, req.Description)
 				}).Return(nil)
 
-				mock.CommitTxMock.Return(nil)
-
 				return mock
 			},
 			placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
 				mock := mocks.NewPlaceThingRepositoryMock(mc)
 
-				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
+				mock.GetByThingIDMock.Inspect(func(ctx context.Context, id uint64) {
 					assert.Equal(mc, thingID, id)
 				}).Return(&placeThingRepoResBeforeUpdate, nil)
 
-				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest, tx *sql.Tx) {
+				mock.UpdatePlaceMock.Inspect(func(ctx context.Context, req models.UpdatePlaceThingRequest) {
 					assert.Equal(mc, placeID, req.PlaceID)
 					assert.Equal(mc, thingID, req.ThingID)
 				}).Return(nil)
@@ -421,15 +392,19 @@ func TestUpdateThingHandler(t *testing.T) {
 
 			mc := minimock.NewController(t)
 			fiberApp := fiber.New()
-			fiberApp.Put("/v1/things/:thingId", UpdateThingHandler(tt.thingRepoMock(mc), tt.placeThingRepoMock(mc)))
+			fiberApp.Put("/v1/things/:thingId", UpdateThingHandler(
+				tt.tmMock(mc),
+				tt.thingRepoMock(mc),
+				tt.placeThingRepoMock(mc),
+			))
 
-			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, helpers.ConvertDataToIOReader(tt.req.body))
+			fiberReq := httptest.NewRequest(tt.req.method, tt.req.route, test.ConvertDataToIOReader(tt.req.body))
 			fiberReq.Header.Add(fiber.HeaderContentType, tt.req.contentType)
-			fiberRes, _ := fiberApp.Test(fiberReq, API.DefaultTestTimeOut)
+			fiberRes, _ := fiberApp.Test(fiberReq, test.TestTimeout)
 
 			assert.Equal(t, tt.resCode, fiberRes.StatusCode)
 			if tt.resBody != nil {
-				assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
+				assert.Equal(t, test.MarshalResponse(tt.resBody), test.ConvertBodyToString(fiberRes.Body))
 			}
 		})
 	}

+ 6 - 1
internal/api/v1/user/add_user.go

@@ -8,6 +8,7 @@ import (
 	"context"
 	"strings"
 
+	"git.dmitriygnatenko.ru/dima/go-common/logger"
 	"github.com/go-playground/validator/v10"
 	"github.com/gofiber/fiber/v2"
 	"github.com/golang-jwt/jwt/v4"
@@ -25,7 +26,7 @@ type (
 
 	UserRepository interface {
 		Get(ctx context.Context, username string) (*models.User, error)
-		Add(ctx context.Context, username string, password string) (int, error)
+		Add(ctx context.Context, username string, password string) (uint64, error)
 		Update(ctx context.Context, req models.UpdateUserRequest) error
 	}
 )
@@ -48,21 +49,25 @@ func AddUserHandler(
 		ctx := fctx.Context()
 		req := dto.AddUserRequest{}
 		if err := fctx.BodyParser(&req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fiber.NewError(fiber.StatusBadRequest, err.Error())
 		}
 
 		var validate = validator.New()
 		if err := validate.Struct(req); err != nil {
+			logger.Info(ctx, err.Error())
 			return fctx.Status(fiber.StatusBadRequest).JSON(factory.CreateValidateErrorResponse(err))
 		}
 
 		hash, err := authService.GeneratePasswordHash(strings.TrimSpace(req.Password))
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 
 		_, err = userRepository.Add(ctx, strings.TrimSpace(req.Username), hash)
 		if err != nil {
+			logger.Error(ctx, err.Error())
 			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 		}
 

Деякі файли не було показано, через те що забагато файлів було змінено