Skip to content
Snippets Groups Projects

feat/us847 consents city

Merged Bastien DUMONT requested to merge feat/US847-consents-city into dev
4 files
+ 113
24
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 19
3
@@ -3,7 +3,6 @@ package models
import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"time"
@@ -152,7 +151,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 {
@@ -163,6 +162,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)
}
@@ -180,10 +189,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