lifedebugger commited on
Commit
7d9da17
·
verified ·
1 Parent(s): 8e48e05

Delete repositories

Browse files
repositories/AccountRepository.go DELETED
@@ -1,24 +0,0 @@
1
- package repositories
2
-
3
- import (
4
- "api.qobiltu.id/models"
5
- )
6
-
7
- func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
8
- repo := Construct[models.Account, models.Account](
9
- models.Account{Email: email},
10
- )
11
- repo.Transactions(
12
- WhereGivenConstructor[models.Account, models.Account],
13
- Find[models.Account, models.Account],
14
- )
15
- return *repo
16
- }
17
-
18
- func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
19
- repo := Construct[models.Account, models.Account](
20
- account,
21
- )
22
- Create(repo)
23
- return *repo
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
repositories/DatabaseScoope.go DELETED
@@ -1,5 +0,0 @@
1
- package repositories
2
-
3
- import "api.qobiltu.id/config"
4
-
5
- var db = config.DB
 
 
 
 
 
 
repositories/account_repository.go DELETED
@@ -1,24 +0,0 @@
1
- package repositories
2
-
3
- import (
4
- "api.qobiltu.id/models"
5
- )
6
-
7
- func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
8
- repo := Construct[models.Account, models.Account](
9
- models.Account{Email: email},
10
- )
11
- repo.Transactions(
12
- WhereGivenConstructor[models.Account, models.Account],
13
- Find[models.Account, models.Account],
14
- )
15
- return *repo
16
- }
17
-
18
- func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
19
- repo := Construct[models.Account, models.Account](
20
- account,
21
- )
22
- Create(repo)
23
- return *repo
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
repositories/repositories.go DELETED
@@ -1,113 +0,0 @@
1
- package repositories
2
-
3
- import (
4
- "api.qobiltu.id/config"
5
- "gorm.io/gorm"
6
- )
7
-
8
- type Repositories interface {
9
- FindAllPaginate()
10
- Where()
11
- Find()
12
- Create()
13
- Update()
14
- CustomQuery()
15
- Delete()
16
- }
17
- type PaginationConstructor struct {
18
- Limit int
19
- Offset int
20
- Filter string
21
- }
22
-
23
- type CustomQueryConstructor struct {
24
- SQL string
25
- Values interface{}
26
- }
27
-
28
- type Repository[TConstructor any, TResult any] struct {
29
- Constructor TConstructor
30
- Pagination PaginationConstructor
31
- CustomQuery CustomQueryConstructor
32
- Result TResult
33
- Transaction *gorm.DB
34
- RowsCount int
35
- NoRecord bool
36
- RowsError error
37
- }
38
-
39
- func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
40
- if len(constructor) == 1 {
41
- return &Repository[TConstructor, TResult]{
42
- Constructor: constructor[0],
43
- Transaction: config.DB,
44
- }
45
- }
46
- return &Repository[TConstructor, TResult]{
47
- Constructor: constructor[0],
48
- Transaction: config.DB.Begin(),
49
- }
50
- }
51
- func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
52
- for _, tx := range transactions {
53
- repo.Transaction = tx(repo)
54
- if repo.RowsError != nil {
55
- return
56
- }
57
- }
58
- }
59
- func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
60
- tx := repo.Transaction.Where(&repo.Constructor)
61
- repo.RowsCount = int(tx.RowsAffected)
62
- repo.NoRecord = repo.RowsCount == 0
63
- repo.RowsError = tx.Error
64
- return tx
65
- }
66
- func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
67
- tx := repo.Transaction.Find(&repo.Result)
68
- repo.RowsCount = int(tx.RowsAffected)
69
- repo.NoRecord = repo.RowsCount == 0
70
- repo.RowsError = tx.Error
71
- return tx
72
- }
73
-
74
- func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
75
- tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
76
- repo.RowsCount = int(tx.RowsAffected)
77
- repo.NoRecord = repo.RowsCount == 0
78
- repo.RowsError = tx.Error
79
- return tx
80
- }
81
-
82
- func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
83
- tx := repo.Transaction.Create(&repo.Constructor)
84
- repo.RowsCount = int(tx.RowsAffected)
85
- repo.NoRecord = repo.RowsCount == 0
86
- repo.RowsError = tx.Error
87
- repo.Result = repo.Constructor
88
- return tx
89
- }
90
-
91
- func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
92
- tx := repo.Transaction.Save(&repo.Constructor)
93
- repo.RowsCount = int(tx.RowsAffected)
94
- repo.NoRecord = repo.RowsCount == 0
95
- repo.RowsError = tx.Error
96
- return tx
97
- }
98
-
99
- func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
100
- tx := repo.Transaction.Delete(&repo.Constructor)
101
- repo.RowsCount = int(tx.RowsAffected)
102
- repo.NoRecord = repo.RowsCount == 0
103
- repo.RowsError = tx.Error
104
- return tx
105
- }
106
-
107
- func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
108
- tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
109
- repo.RowsCount = int(tx.RowsAffected)
110
- repo.NoRecord = repo.RowsCount == 0
111
- repo.RowsError = tx.Error
112
- return tx
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
repositories/repository.go DELETED
@@ -1,113 +0,0 @@
1
- package repositories
2
-
3
- import (
4
- "api.qobiltu.id/config"
5
- "gorm.io/gorm"
6
- )
7
-
8
- type Repositories interface {
9
- FindAllPaginate()
10
- Where()
11
- Find()
12
- Create()
13
- Update()
14
- CustomQuery()
15
- Delete()
16
- }
17
- type PaginationConstructor struct {
18
- Limit int
19
- Offset int
20
- Filter string
21
- }
22
-
23
- type CustomQueryConstructor struct {
24
- SQL string
25
- Values interface{}
26
- }
27
-
28
- type Repository[TConstructor any, TResult any] struct {
29
- Constructor TConstructor
30
- Pagination PaginationConstructor
31
- CustomQuery CustomQueryConstructor
32
- Result TResult
33
- Transaction *gorm.DB
34
- RowsCount int
35
- NoRecord bool
36
- RowsError error
37
- }
38
-
39
- func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
40
- if len(constructor) == 1 {
41
- return &Repository[TConstructor, TResult]{
42
- Constructor: constructor[0],
43
- Transaction: config.DB,
44
- }
45
- }
46
- return &Repository[TConstructor, TResult]{
47
- Constructor: constructor[0],
48
- Transaction: config.DB.Begin(),
49
- }
50
- }
51
- func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
52
- for _, tx := range transactions {
53
- repo.Transaction = tx(repo)
54
- if repo.RowsError != nil {
55
- return
56
- }
57
- }
58
- }
59
- func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
60
- tx := repo.Transaction.Where(&repo.Constructor)
61
- repo.RowsCount = int(tx.RowsAffected)
62
- repo.NoRecord = repo.RowsCount == 0
63
- repo.RowsError = tx.Error
64
- return tx
65
- }
66
- func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
67
- tx := repo.Transaction.Find(&repo.Result)
68
- repo.RowsCount = int(tx.RowsAffected)
69
- repo.NoRecord = repo.RowsCount == 0
70
- repo.RowsError = tx.Error
71
- return tx
72
- }
73
-
74
- func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
75
- tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
76
- repo.RowsCount = int(tx.RowsAffected)
77
- repo.NoRecord = repo.RowsCount == 0
78
- repo.RowsError = tx.Error
79
- return tx
80
- }
81
-
82
- func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
83
- tx := repo.Transaction.Create(&repo.Constructor)
84
- repo.RowsCount = int(tx.RowsAffected)
85
- repo.NoRecord = repo.RowsCount == 0
86
- repo.RowsError = tx.Error
87
- repo.Result = repo.Constructor
88
- return tx
89
- }
90
-
91
- func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
92
- tx := repo.Transaction.Save(&repo.Constructor)
93
- repo.RowsCount = int(tx.RowsAffected)
94
- repo.NoRecord = repo.RowsCount == 0
95
- repo.RowsError = tx.Error
96
- return tx
97
- }
98
-
99
- func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
100
- tx := repo.Transaction.Delete(&repo.Constructor)
101
- repo.RowsCount = int(tx.RowsAffected)
102
- repo.NoRecord = repo.RowsCount == 0
103
- repo.RowsError = tx.Error
104
- return tx
105
- }
106
-
107
- func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
108
- tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
109
- repo.RowsCount = int(tx.RowsAffected)
110
- repo.NoRecord = repo.RowsCount == 0
111
- repo.RowsError = tx.Error
112
- return tx
113
- }