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

Feat/us555 partners check

parent 271b578c
No related branches found
No related tags found
3 merge requests!14feat: addprices + subject managment,!11feat: Add partners issue info,!9Feat/us555 partners check
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#65f4ff",
"activityBar.activeBorder": "#ff40f1",
"activityBar.background": "#65f4ff",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#ff40f1",
"activityBarBadge.foreground": "#15202b",
"sash.hoverBorder": "#65f4ff",
"statusBar.background": "#32f0ff",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#00ebfe",
"statusBarItem.remoteBackground": "#32f0ff",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#32f0ff",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#32f0ff99",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#32f0ff"
}
\ No newline at end of file
......@@ -41,5 +41,16 @@ func NewDataHandler() *DataHandler {
db.AutoMigrate(&MonthlyInfo{})
db.AutoMigrate(&MonthlyNews{})
db.AutoMigrate(&Poll{})
db.AutoMigrate(&PartnersInfo{})
// Create default partner status
db.Create(&PartnersInfo{
Message: "",
GRDFFailure: false,
EnedisFailure: false,
EGLFailure: false,
NotificationActivated: false,
})
return &DataHandler{db: db}
}
package models
import (
"encoding/json"
"errors"
"log"
"net/http"
"gorm.io/gorm"
)
type PartnersInfo struct {
ID uint `gorm:"<-:create"`
Message string `json:"message"`
GRDFFailure bool `json:"grdf_failure"`
EnedisFailure bool `json:"enedis_failure"`
EGLFailure bool `json:"egl_failure"`
NotificationActivated bool `json:"notification_activated"`
}
// GetPartnersInfo godoc
// @Summary Give status of partners' services
// @Description Give status of partners' services
// @Tags partnersInfo
// @Produce json
// @Success 200 {object} PartnersInfo
// @Failure 404 {string} string "Not found"
// @Router /api/common/partnersInfo [get]
func (dh *DataHandler) GetPartnersInfo(w http.ResponseWriter, r *http.Request) {
var partnersInfo PartnersInfo
err := dh.db.First(&partnersInfo).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
http.Error(w, "partners status not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(partnersInfo)
log.Printf("| get partnersInfo | %v", r.RemoteAddr)
}
// SavePartnersInfo godoc
// @Summary Update partnersInfo' content
// @Description Update partnersInfo' content
// @Tags partnersInfo
// @Accept json
// @Produce json
// @Success 200 {object} PartnersInfo "Updated successfully"
// @Failure 400 {string} string "Bad Request"
// @Failure 500 {string} string "Internal server error"
// @Param partnersInfo body PartnersInfo true "PartnersInfo to create/update with new content"
// @Router /api/admin/partnersInfo [put]
func (dh *DataHandler) SavePartnersInfo(w http.ResponseWriter, r *http.Request) {
if r.Body == http.NoBody {
http.Error(w, "request body is empty", http.StatusBadRequest)
return
}
decoder := json.NewDecoder(r.Body)
var partnersInfo PartnersInfo
err := decoder.Decode(&partnersInfo)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
var updatedPartnersInfo PartnersInfo
err = dh.db.First(&updatedPartnersInfo).Error
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
updatedPartnersInfo.Message = partnersInfo.Message
updatedPartnersInfo.GRDFFailure = partnersInfo.GRDFFailure
updatedPartnersInfo.EnedisFailure = partnersInfo.EnedisFailure
updatedPartnersInfo.EGLFailure = partnersInfo.EGLFailure
updatedPartnersInfo.NotificationActivated = partnersInfo.NotificationActivated
dh.db.Save(&updatedPartnersInfo)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(partnersInfo)
log.Printf("| updated partnersInfo | %v", r.RemoteAddr)
}
......@@ -42,6 +42,7 @@ func CreateRootMux() RootMux {
r.HandleFunc("/api/common/monthlyReport", dh.GetMonthlyReport).Methods(http.MethodGet)
r.HandleFunc("/api/common/monthlyReport/{year}/{month}", dh.GetMonthlyReport).Methods(http.MethodGet)
r.HandleFunc("/api/common/partnersInfo", dh.GetPartnersInfo).Methods(http.MethodGet)
apiAdmin := r.PathPrefix("/api/admin").Subrouter()
apiAdmin.Use(auth.AdminAuthMiddleware)
......@@ -61,6 +62,8 @@ func CreateRootMux() RootMux {
apiAdmin.HandleFunc("/poll", dh.SavePoll).Methods(http.MethodPut)
apiAdmin.HandleFunc("/poll/{year}/{month}", dh.DeletePoll).Methods(http.MethodDelete)
apiAdmin.HandleFunc("/partnersInfo", dh.SavePartnersInfo).Methods(http.MethodPut)
apiAdmin.HandleFunc("/imageNames", file.GetEcogestureImages).Methods(http.MethodGet)
// Swagger
......
......@@ -17,14 +17,16 @@ import (
)
var (
oAuth2Server *httptest.Server
monthlyInfo = models.MonthlyInfo{Year: 2021, Month: 0, Info: "Informations du mois", Image: "imagebase64"}
monthlyInfoStr string
monthlyNews = models.MonthlyNews{Year: 2021, Month: 0, Title: "", Content: "Nouvelles fonctionnalités"}
monthlyNewsStr string
newPoll = models.Poll{Year: 2021, Month: 0, Question: "pollQuestion", Link: "pollLink"}
newPollStr string
noH map[string]string
oAuth2Server *httptest.Server
monthlyInfo = models.MonthlyInfo{Year: 2021, Month: 0, Info: "Informations du mois", Image: "imagebase64"}
monthlyInfoStr string
monthlyNews = models.MonthlyNews{Year: 2021, Month: 0, Title: "", Content: "Nouvelles fonctionnalités"}
monthlyNewsStr string
newPoll = models.Poll{Year: 2021, Month: 0, Question: "pollQuestion", Link: "pollLink"}
newPollStr string
partnersInfo = models.PartnersInfo{ID: 1, Message: "EGL est down", GRDFFailure: false, EnedisFailure: false, EGLFailure: true, NotificationActivated: true}
partnersInfoStr string
noH map[string]string
)
func TestMain(m *testing.M) {
......@@ -51,6 +53,8 @@ func TestMain(m *testing.M) {
monthlyNewsStr = string(monthlyNewsBytes)
monthlyInfoBytes, _ := json.Marshal(monthlyInfo)
monthlyInfoStr = string(monthlyInfoBytes)
partnersInfoBytes, _ := json.Marshal(partnersInfo)
partnersInfoStr = string(partnersInfoBytes)
newPollBytes, _ := json.Marshal(newPoll)
newPollStr = string(newPollBytes)
......@@ -98,6 +102,8 @@ func unloggedTests(t *testing.T) {
do("GET", "/api/common/monthlyReport", noH, "", http.StatusBadRequest, "")
// Try to get a monthlyReport (must fail because not found)
do("GET", "/api/common/monthlyReport?year=2021&month=12", noH, "", http.StatusNotFound, "")
// Try to get partnersInfo (must pass)
do("GET", "/api/common/partnersInfo", noH, "", http.StatusOK, `{"ID":1,"message":"","grdf_failure":false,"enedis_failure":false,"egl_failure":false,"notification_activated":false}`)
}
/**
......@@ -158,6 +164,11 @@ func adminTests(t *testing.T) {
// Try to get the monthlyReport (must pass)
do("GET", "/api/common/monthlyReport/2021/0", noH, "", http.StatusOK, `{"year":2021,"month":0,"info":"Informations du mois","image":"imagebase64","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"pollQuestion","link":"pollLink"`)
// Try to update the partnersInfo (must pass)
do("PUT", "/api/admin/partnersInfo", xsrfHeader, partnersInfoStr, http.StatusOK, partnersInfoStr)
// Try to get the monthlyInfo created (must pass)
do("GET", "/api/common/partnersInfo", xsrfHeader, "", http.StatusOK, partnersInfoStr)
// Try to delete the monthlyNews created (must pass)
do("DELETE", "/api/admin/monthlyNews/2021/0", xsrfHeader, "", http.StatusOK, "successful delete")
// Try to get a monthlyNews after it is deleted (must fail because not found)
......
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