Ajouter upload par json
Fonctionne avec json dans request body ou en fichier formatté json Cleanup commentaires Ajouter vérification d'insertion vide
This commit is contained in:
parent
3ccebd8cfb
commit
cb51ada4b6
2 changed files with 17 additions and 34 deletions
|
@ -26,36 +26,20 @@ func PostMembres(c echo.Context) error {
|
|||
})
|
||||
}
|
||||
|
||||
programmes := []models.Programme{
|
||||
{
|
||||
ID: "foo",
|
||||
Titre: "Foo",
|
||||
},
|
||||
{
|
||||
ID: "bar",
|
||||
Titre: "Bar",
|
||||
},
|
||||
}
|
||||
var membres []models.Membre
|
||||
|
||||
newProgrammes, err := client.InsertProgrammes(programmes)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"message": "Could not insert programmes",
|
||||
if err := c.Bind(&membres); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{
|
||||
"message": "Could not bind membres",
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
membres := []models.Membre{
|
||||
{
|
||||
ID: "1327163",
|
||||
PreferedName: "victor",
|
||||
ProgrammeID: "foo",
|
||||
},
|
||||
{
|
||||
ID: "0000000",
|
||||
PreferedName: "test user",
|
||||
ProgrammeID: "bar",
|
||||
},
|
||||
if len(membres) == 0 {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{
|
||||
"message": "Nothing to do",
|
||||
"error": "No valid membres to insert were found",
|
||||
})
|
||||
}
|
||||
|
||||
newMembres, err := client.InsertMembres(membres)
|
||||
|
@ -69,8 +53,7 @@ func PostMembres(c echo.Context) error {
|
|||
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||
"message": "Insert successful",
|
||||
"data": map[string]interface{}{
|
||||
"membres": newMembres,
|
||||
"programmes": newProgrammes,
|
||||
"membres": newMembres,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Reference in a new issue