Company now works
This commit is contained in:
52
db/basicProfile.go
Normal file
52
db/basicProfile.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package db
|
||||
|
||||
type BasicProfile struct {
|
||||
CompanyId int
|
||||
Employees string
|
||||
Revenue string
|
||||
Applications string
|
||||
Compliance string
|
||||
Industry string
|
||||
ITDependency string
|
||||
DataSensitivity string
|
||||
DataVolume string
|
||||
NetworkSegmentation string
|
||||
LegacySystems string
|
||||
IoTIntegration string
|
||||
RemoteWork string
|
||||
BYOD string
|
||||
VPN string
|
||||
API string
|
||||
VendorAccess string
|
||||
InternalDev string
|
||||
}
|
||||
|
||||
// InsertBasicProfile inserts a new record into the BasicProfile table
|
||||
func InsertBasicProfile(profile BasicProfile) (int, error) {
|
||||
query := `
|
||||
INSERT INTO BasicProfile (
|
||||
CompanyId, Employees, Revenue, Applications, Compliance, Industry, ITDependency, DataSensitivity, DataVolume,
|
||||
NetworkSegmentation, LegacySystems, IoTIntegration, RemoteWork, BYOD, VPN, API, VendorAccess, InternalDev
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
stmt, err := db.Prepare(query)
|
||||
if err != nil {
|
||||
return -2, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
id := 0
|
||||
err = stmt.QueryRow(
|
||||
profile.CompanyId, profile.Employees, profile.Revenue, profile.Applications, profile.Compliance, profile.Industry,
|
||||
profile.ITDependency, profile.DataSensitivity, profile.DataVolume, profile.NetworkSegmentation, profile.LegacySystems,
|
||||
profile.IoTIntegration, profile.RemoteWork, profile.BYOD, profile.VPN, profile.API, profile.VendorAccess, profile.InternalDev,
|
||||
).Scan(&id)
|
||||
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
36
db/company.go
Normal file
36
db/company.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package db
|
||||
|
||||
type Company struct {
|
||||
ID int
|
||||
UUID string
|
||||
Name string
|
||||
Email string
|
||||
TaxId string
|
||||
Password string
|
||||
}
|
||||
|
||||
// InsertCompany inserts a new record into the Company table
|
||||
func InsertCompany(company Company) (int, error) {
|
||||
query := `
|
||||
INSERT INTO Company (UUID, Name, Email, TaxId, Password)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
stmt, err := db.Prepare(query)
|
||||
if err != nil {
|
||||
return -2, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
id := 0
|
||||
err = stmt.QueryRow(
|
||||
company.UUID, company.Name, company.Email, company.TaxId, company.Password,
|
||||
).Scan(&id)
|
||||
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
16
db/utils.go
Normal file
16
db/utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
func GenerateRandomString() string {
|
||||
const n = 25
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
Reference in New Issue
Block a user