-
Notifications
You must be signed in to change notification settings - Fork 469
/
AppStoreVersionValuesRepository.go
127 lines (114 loc) · 5.05 KB
/
AppStoreVersionValuesRepository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 2020 Devtron Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package appstore
import (
"github.com/devtron-labs/devtron/internal/sql/models"
"github.com/go-pg/pg"
"go.uber.org/zap"
)
type AppStoreVersionValuesRepository interface {
CreateAppStoreVersionValues(model *AppStoreVersionValues) (*AppStoreVersionValues, error)
UpdateAppStoreVersionValues(model *AppStoreVersionValues) (*AppStoreVersionValues, error)
DeleteAppStoreVersionValues(model *AppStoreVersionValues) (bool, error)
/* FindAll() ([]*AppStoreVersionValues, error)*/
FindById(id int) (*AppStoreVersionValues, error)
FindValuesByAppStoreId(appStoreVersionId int) ([]*AppStoreVersionValues, error)
FindValuesByAppStoreIdAndReferenceType(appStoreVersionId int, referenceType string) ([]*AppStoreVersionValues, error)
}
type AppStoreVersionValuesRepositoryImpl struct {
dbConnection *pg.DB
Logger *zap.SugaredLogger
}
func NewAppStoreVersionValuesRepositoryImpl(Logger *zap.SugaredLogger, dbConnection *pg.DB) *AppStoreVersionValuesRepositoryImpl {
return &AppStoreVersionValuesRepositoryImpl{dbConnection: dbConnection, Logger: Logger}
}
type AppStoreVersionValues struct {
TableName struct{} `sql:"app_store_version_values" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
ValuesYaml string `sql:"values_yaml"`
AppStoreApplicationVersionId int `sql:"app_store_application_version_id"`
ReferenceType string `sql:"reference_type"`
Deleted bool `sql:"deleted,notnull"`
models.AuditLog
AppStoreApplicationVersion *AppStoreApplicationVersion
}
func (impl AppStoreVersionValuesRepositoryImpl) CreateAppStoreVersionValues(model *AppStoreVersionValues) (*AppStoreVersionValues, error) {
err := impl.dbConnection.Insert(model)
if err != nil {
impl.Logger.Error(err)
return nil, err
}
return model, nil
}
func (impl AppStoreVersionValuesRepositoryImpl) UpdateAppStoreVersionValues(model *AppStoreVersionValues) (*AppStoreVersionValues, error) {
err := impl.dbConnection.Update(model)
if err != nil {
impl.Logger.Error(err)
return model, err
}
return model, nil
}
func (impl AppStoreVersionValuesRepositoryImpl) DeleteAppStoreVersionValues(model *AppStoreVersionValues) (bool, error) {
err := impl.dbConnection.Update(model)
if err != nil {
impl.Logger.Error(err)
return false, err
}
return true, nil
}
/*func (impl *AppStoreVersionValuesRepositoryImpl) FindAll() ([]*AppStoreVersionValues, error) {
var appStoreWithVersion []*AppStoreVersionValues
err := impl.dbConnection.
Model(appStoreWithVersion).
Column("app_store_version_values.*", "AppStoreApplicationVersion").
Select()
return appStoreWithVersion, err
}*/
func (impl AppStoreVersionValuesRepositoryImpl) FindById(id int) (*AppStoreVersionValues, error) {
appStoreWithVersion := &AppStoreVersionValues{}
err := impl.dbConnection.
Model(appStoreWithVersion).
Column("app_store_version_values.*", "AppStoreApplicationVersion").
Where("app_store_version_values.id = ?", id).
Where("app_store_version_values.deleted =?", false).
Limit(1).
Select()
return appStoreWithVersion, err
}
func (impl AppStoreVersionValuesRepositoryImpl) FindValuesByAppStoreId(appStoreId int) ([]*AppStoreVersionValues, error) {
var appStoreVersionValues []*AppStoreVersionValues
err := impl.dbConnection.
Model(&appStoreVersionValues).
Column("app_store_version_values.id", "app_store_version_values.name", "AppStoreApplicationVersion.version", "AppStoreApplicationVersion.id").
Join("inner join app_store_application_version apv on apv.id = app_store_version_values.app_store_application_version_id").
Where("apv.app_store_id = ?", appStoreId).
Where("app_store_version_values.deleted =?", false).
Select()
return appStoreVersionValues, err
}
func (impl AppStoreVersionValuesRepositoryImpl) FindValuesByAppStoreIdAndReferenceType(appStoreId int, referenceType string) ([]*AppStoreVersionValues, error) {
var appStoreVersionValues []*AppStoreVersionValues
err := impl.dbConnection.
Model(&appStoreVersionValues).
Column("app_store_version_values.id", "app_store_version_values.name", "AppStoreApplicationVersion.version").
Join("inner join app_store_application_version apv on apv.id = app_store_version_values.app_store_application_version_id").
Where("apv.app_store_id = ?", appStoreId).Where("app_store_version_values.reference_type = ?", referenceType).
Where("app_store_version_values.deleted =?", false).
Select()
return appStoreVersionValues, err
}