Skip to content
Snippets Groups Projects

Resolve "deleted Date on consent"

Closed Rémi PAILHAREY requested to merge 5-deleted-date-on-consent into dev
1 file
+ 19
3
Compare changes
  • Side-by-side
  • Inline
+ 19
3
@@ -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)
Loading