Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • web-et-numerique/factory/llle_project/backoffice-server
1 result
Show changes
Commits on Source (6)
......@@ -17,9 +17,10 @@ variables:
GIT_DEPTH: 0
stages:
- quality
- build
build:
build-dev-master:
image: docker:18.09
services:
- docker:18.09-dind
......@@ -32,3 +33,62 @@ build:
- dev
- master
build-mr:
image: docker:18.09
services:
- docker:18.09-dind
stage: build
script:
- docker build .
only:
- merge_requests
sonarqube:
stage: quality
only:
- dev
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/sonarsource/sonar-scanner-cli:4
variables:
SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar' # Defines the location of the analysis task cache
GIT_DEPTH: '0' # T
cache:
key: '${CI_JOB_NAME}'
paths:
- .sonar/cache
script:
- >
sonar-scanner
-Dsonar.projectName=ecolyo-agent-server
-Dsonar.projectVersion=1.0
-Dsonar.sourceEncoding=UTF-8
-Dsonar.projectBaseDir=.
-Dsonar.host.url=${SONAR_URL}
-Dsonar.projectKey=ecolyo-agent-server
-Dsonar.login=${SONAR_TOKEN}
-Dsonar.cpd.exclusions=internal/mocks/**,internal/**/*_test.go
-Dsonar.qualitygate.wait=true
sonarqube:
stage: quality
only:
- merge_requests
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/sonarsource/sonar-scanner-cli:4
variables:
SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar' # Defines the location of the analysis task cache
GIT_DEPTH: '0' # T
cache:
key: '${CI_JOB_NAME}'
paths:
- .sonar/cache
script:
- >
sonar-scanner
-Dsonar.projectName=ecolyo-agent-server-mr
-Dsonar.projectVersion=1.0
-Dsonar.sourceEncoding=UTF-8
-Dsonar.projectBaseDir=.
-Dsonar.host.url=${SONAR_URL}
-Dsonar.projectKey=ecolyo-agent-server-mr
-Dsonar.login=${SONAR_MR_TOKEN}
-Dsonar.cpd.exclusions=internal/mocks/**,internal/**/*_test.go
-Dsonar.qualitygate.wait=true
......@@ -3,7 +3,6 @@ package models
import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"time"
......@@ -151,7 +150,7 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request)
return
}
// Update and save consent
// Update and save consent in MySQL
consent.EndDate = time.Now()
err = dh.sqlClient.Save(&consent).Error
if err != nil {
......@@ -162,6 +161,16 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request)
dh.sqlClient.Delete(&consent)
// Update and save consent in Meilisearch
deletedConsent := []map[string]interface{}{
{
"ID": consent.ID,
"endDate": consent.EndDate,
"DeletedAt": consent.DeletedAt,
},
}
dh.meiliClient.Index("consents").UpdateDocuments(deletedConsent)
log.Printf("| deleted consent | id : %d | %v", id, r.RemoteAddr)
}
......@@ -179,10 +188,17 @@ func (dh *DataHandler) SearchConsent(w http.ResponseWriter, r *http.Request) {
hits, err := json.Marshal(resp.Hits)
if err != nil {
fmt.Println("error:", err)
http.Error(w, "error when marshal hits", http.StatusInternalServerError)
log.Println(err.Error())
return
}
var consents []Consent
err = json.Unmarshal(hits, &consents)
if err != nil {
http.Error(w, "error when unmarshal hits", http.StatusInternalServerError)
log.Println(err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(consents)
......
......@@ -5,15 +5,17 @@ import (
"errors"
"log"
"net/http"
"time"
"gorm.io/gorm"
)
type CustomPopup struct {
ID uint `gorm:"<-:create"`
PopupEnabled bool `json:"popupEnabled"`
Title string `json:"title"`
Description string `json:"description"`
ID uint `gorm:"<-:create"`
PopupEnabled bool `json:"popupEnabled"`
Title string `json:"title"`
Description string `json:"description"`
EndDate time.Time `json:"endDate"`
}
// GetCustomPopup godoc
......@@ -74,6 +76,7 @@ func (dh *DataHandler) SaveCustomPopup(w http.ResponseWriter, r *http.Request) {
updatedCustomPopup.PopupEnabled = customPopup.PopupEnabled
updatedCustomPopup.Title = customPopup.Title
updatedCustomPopup.Description = customPopup.Description
updatedCustomPopup.EndDate = customPopup.EndDate
dh.sqlClient.Save(&updatedCustomPopup)
......
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{
......