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
Branches
No related tags found
Loading
Pipeline #43331 passed
...@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment