/
includedSubRegionManager.go
118 lines (107 loc) · 3.04 KB
/
includedSubRegionManager.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
package managers
import (
"net/http"
sdbi "github.com/Ulbora/six910-database-interface"
)
/*
Six910 is a shopping cart and E-commerce system.
Copyright (C) 2020 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2020 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//AddIncludedSubRegion AddIncludedSubRegion
func (m *Six910Manager) AddIncludedSubRegion(e *sdbi.IncludedSubRegion, sid int64) *ResponseID {
var rtn ResponseID
r := m.Db.GetRegion(e.RegionID)
if r.StoreID == sid {
suc, id := m.Db.AddIncludedSubRegion(e)
if suc && id != 0 {
rtn.Success = suc
rtn.ID = id
rtn.Code = http.StatusOK
} else {
rtn.Code = http.StatusBadRequest
}
} else {
rtn.Code = http.StatusBadRequest
}
return &rtn
}
//UpdateIncludedSubRegion UpdateIncludedSubRegion
func (m *Six910Manager) UpdateIncludedSubRegion(e *sdbi.IncludedSubRegion, sid int64) *Response {
var rtn Response
r := m.Db.GetRegion(e.RegionID)
if r.StoreID == sid {
suc := m.Db.UpdateIncludedSubRegion(e)
if suc {
rtn.Success = suc
rtn.Code = http.StatusOK
} else {
rtn.Code = http.StatusBadRequest
}
} else {
rtn.Code = http.StatusBadRequest
}
return &rtn
}
//GetIncludedSubRegion GetIncludedSubRegion
func (m *Six910Manager) GetIncludedSubRegion(id int64, sid int64) *sdbi.IncludedSubRegion {
var rtn *sdbi.IncludedSubRegion
sr := m.Db.GetIncludedSubRegion(id)
r := m.Db.GetRegion(sr.RegionID)
if r.StoreID == sid {
rtn = sr
} else {
var ns sdbi.IncludedSubRegion
rtn = &ns
}
return rtn
}
//GetIncludedSubRegionList GetIncludedSubRegionList
func (m *Six910Manager) GetIncludedSubRegionList(regionID int64, sid int64) *[]sdbi.IncludedSubRegion {
var rtn *[]sdbi.IncludedSubRegion
r := m.Db.GetRegion(regionID)
if r.StoreID == sid {
rtn = m.Db.GetIncludedSubRegionList(regionID)
} else {
var nr = []sdbi.IncludedSubRegion{}
rtn = &nr
}
return rtn
}
//DeleteIncludedSubRegion DeleteIncludedSubRegion
func (m *Six910Manager) DeleteIncludedSubRegion(id int64, regionID int64, sid int64) *Response {
var rtn Response
var found bool
srl := m.Db.GetIncludedSubRegionList(regionID)
for _, rr := range *srl {
if rr.ID == id {
found = true
break
}
}
r := m.Db.GetRegion(regionID)
if found && r.StoreID == sid {
suc := m.Db.DeleteIncludedSubRegion(id)
if suc {
rtn.Success = suc
rtn.Code = http.StatusOK
} else {
rtn.Code = http.StatusBadRequest
}
} else {
rtn.Code = http.StatusBadRequest
}
return &rtn
}