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
Select Git revision

Target

Select target project
  • web-et-numerique/factory/llle_project/backoffice-server
1 result
Select Git revision
Show changes
Commits on Source (6)
...@@ -17,9 +17,10 @@ variables: ...@@ -17,9 +17,10 @@ variables:
GIT_DEPTH: 0 GIT_DEPTH: 0
stages: stages:
- quality
- build - build
build: build-dev-master:
image: docker:18.09 image: docker:18.09
services: services:
- docker:18.09-dind - docker:18.09-dind
...@@ -32,3 +33,62 @@ build: ...@@ -32,3 +33,62 @@ build:
- dev - dev
- master - 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 ...@@ -3,7 +3,6 @@ package models
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"log" "log"
"net/http" "net/http"
"time" "time"
...@@ -151,7 +150,7 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request) ...@@ -151,7 +150,7 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request)
return return
} }
// Update and save consent // Update and save consent in MySQL
consent.EndDate = time.Now() consent.EndDate = time.Now()
err = dh.sqlClient.Save(&consent).Error err = dh.sqlClient.Save(&consent).Error
if err != nil { if err != nil {
...@@ -162,6 +161,16 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request) ...@@ -162,6 +161,16 @@ func (dh *DataHandler) DeleteConsentById(w http.ResponseWriter, r *http.Request)
dh.sqlClient.Delete(&consent) 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) log.Printf("| deleted consent | id : %d | %v", id, r.RemoteAddr)
} }
...@@ -179,10 +188,17 @@ func (dh *DataHandler) SearchConsent(w http.ResponseWriter, r *http.Request) { ...@@ -179,10 +188,17 @@ func (dh *DataHandler) SearchConsent(w http.ResponseWriter, r *http.Request) {
hits, err := json.Marshal(resp.Hits) hits, err := json.Marshal(resp.Hits)
if err != nil { if err != nil {
fmt.Println("error:", err) http.Error(w, "error when marshal hits", http.StatusInternalServerError)
log.Println(err.Error())
return
} }
var consents []Consent var consents []Consent
err = json.Unmarshal(hits, &consents) 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") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(consents) json.NewEncoder(w).Encode(consents)
......
...@@ -5,15 +5,17 @@ import ( ...@@ -5,15 +5,17 @@ import (
"errors" "errors"
"log" "log"
"net/http" "net/http"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
type CustomPopup struct { type CustomPopup struct {
ID uint `gorm:"<-:create"` ID uint `gorm:"<-:create"`
PopupEnabled bool `json:"popupEnabled"` PopupEnabled bool `json:"popupEnabled"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
EndDate time.Time `json:"endDate"`
} }
// GetCustomPopup godoc // GetCustomPopup godoc
...@@ -74,6 +76,7 @@ func (dh *DataHandler) SaveCustomPopup(w http.ResponseWriter, r *http.Request) { ...@@ -74,6 +76,7 @@ func (dh *DataHandler) SaveCustomPopup(w http.ResponseWriter, r *http.Request) {
updatedCustomPopup.PopupEnabled = customPopup.PopupEnabled updatedCustomPopup.PopupEnabled = customPopup.PopupEnabled
updatedCustomPopup.Title = customPopup.Title updatedCustomPopup.Title = customPopup.Title
updatedCustomPopup.Description = customPopup.Description updatedCustomPopup.Description = customPopup.Description
updatedCustomPopup.EndDate = customPopup.EndDate
dh.sqlClient.Save(&updatedCustomPopup) dh.sqlClient.Save(&updatedCustomPopup)
......
package models package models
import ( import (
"errors"
"fmt" "fmt"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common" "forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common"
...@@ -30,13 +31,13 @@ func NewDataHandler() *DataHandler { ...@@ -30,13 +31,13 @@ func NewDataHandler() *DataHandler {
if dbUser == "" || dbPassword == "" || dbName == "" { if dbUser == "" || dbPassword == "" || dbName == "" {
sqlClient, err = gorm.Open(sqlite.Open("backoffice.db"), &gorm.Config{}) sqlClient, err = gorm.Open(sqlite.Open("backoffice.db"), &gorm.Config{})
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect sqlite database")
} }
} else { } else {
dsn := fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbHost, dbName) 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{}) sqlClient, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect MySQL database")
} }
} }
...@@ -50,21 +51,30 @@ func NewDataHandler() *DataHandler { ...@@ -50,21 +51,30 @@ func NewDataHandler() *DataHandler {
sqlClient.AutoMigrate(&Price{}) sqlClient.AutoMigrate(&Price{})
sqlClient.AutoMigrate(&Consent{}) sqlClient.AutoMigrate(&Consent{})
//TODO fix recreate on server init // Check if partners info already exists
// Create default partner status var partnersInfo PartnersInfo
sqlClient.Create(&PartnersInfo{ err = sqlClient.First(&partnersInfo).Error
GRDFFailure: false, if errors.Is(err, gorm.ErrRecordNotFound) {
EnedisFailure: false, // Create default partner status
EGLFailure: false, sqlClient.Create(&PartnersInfo{
NotificationActivated: false, GRDFFailure: false,
}) EnedisFailure: false,
EGLFailure: false,
NotificationActivated: false,
})
}
// Create default custom popup // Check if custom popup already exists
sqlClient.Create(&CustomPopup{ var customPopup CustomPopup
PopupEnabled: false, err = sqlClient.First(&customPopup).Error
Title: "", if errors.Is(err, gorm.ErrRecordNotFound) {
Description: "", // Create default custom popup
}) sqlClient.Create(&CustomPopup{
PopupEnabled: false,
Title: "",
Description: "",
})
}
// Meilisearch setup // Meilisearch setup
meiliClient := meilisearch.NewClient(meilisearch.ClientConfig{ meiliClient := meilisearch.NewClient(meilisearch.ClientConfig{
......