Skip to content
Snippets Groups Projects
Commit d8338872 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix: partner status and custom popup init

parent 186a304c
Branches
No related tags found
4 merge requests!73Deploy Openshift v2,!65MEP: removed Meilisearch,!52back-office SGE before canary release,!40Resolve "Creates an entry each time the server is launched"
package models
import (
"errors"
"fmt"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common"
......@@ -30,13 +31,13 @@ func NewDataHandler() *DataHandler {
if dbUser == "" || dbPassword == "" || dbName == "" {
sqlClient, err = gorm.Open(sqlite.Open("backoffice.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
panic("failed to connect sqlite database")
}
} else {
dsn := fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbHost, dbName)
sqlClient, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("failed to connect database")
panic("failed to connect MySQL database")
}
}
......@@ -50,21 +51,30 @@ func NewDataHandler() *DataHandler {
sqlClient.AutoMigrate(&Price{})
sqlClient.AutoMigrate(&Consent{})
//TODO fix recreate on server init
// Create default partner status
sqlClient.Create(&PartnersInfo{
GRDFFailure: false,
EnedisFailure: false,
EGLFailure: false,
NotificationActivated: false,
})
// Check if partners info already exists
var partnersInfo PartnersInfo
err = sqlClient.First(&partnersInfo).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
// Create default partner status
sqlClient.Create(&PartnersInfo{
GRDFFailure: false,
EnedisFailure: false,
EGLFailure: false,
NotificationActivated: false,
})
}
// Create default custom popup
sqlClient.Create(&CustomPopup{
PopupEnabled: false,
Title: "",
Description: "",
})
// Check if custom popup already exists
var customPopup CustomPopup
err = sqlClient.First(&customPopup).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
// Create default custom popup
sqlClient.Create(&CustomPopup{
PopupEnabled: false,
Title: "",
Description: "",
})
}
// Meilisearch setup
meiliClient := meilisearch.NewClient(meilisearch.ClientConfig{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment