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

Merge branch '5-deleted-date-on-consent' into 'dev'

feat: update endDate and DeletedAt fields in Meilisearch on delete

Closes #5

See merge request web-et-numerique/llle_project/backoffice-server!47
parents 5f403c85 76833183
No related branches found
No related tags found
4 merge requests!73Deploy Openshift v2,!65MEP: removed Meilisearch,!52back-office SGE before canary release,!47feat: update endDate and DeletedAt fields in Meilisearch on delete
Pipeline #43331 passed
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment