|
|
|
@ -19,7 +19,7 @@ func GetTransactions(c echo.Context) error {
|
|
|
|
|
|
|
|
|
|
client, err := data.NewDataClientFromViper()
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant data.NewDataClientFromViper(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
@ -28,19 +28,19 @@ func GetTransactions(c echo.Context) error {
|
|
|
|
|
transactions, err := client.ListTransactions()
|
|
|
|
|
response.Data.Transactions = transactions
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during client.ListTransactions(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant client.ListTransactions(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(transactions) == 0 {
|
|
|
|
|
response.Message = "No transactions found"
|
|
|
|
|
response.Message = "Aucune transaction trouvée"
|
|
|
|
|
statusCode = http.StatusNotFound
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Message = "List successful"
|
|
|
|
|
response.Message = "Liste complétée"
|
|
|
|
|
statusCode = http.StatusOK
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
@ -55,21 +55,21 @@ func PostTransactions(c echo.Context) error {
|
|
|
|
|
|
|
|
|
|
if err := c.Bind(&transactions); err != nil {
|
|
|
|
|
statusCode = http.StatusBadRequest
|
|
|
|
|
response.Message = fmt.Sprintf("Error during c.Bind(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant c.Bind(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client, err := data.NewDataClientFromViper()
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant data.NewDataClientFromViper(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
defer client.DB.Close()
|
|
|
|
|
|
|
|
|
|
if len(transactions) == 0 {
|
|
|
|
|
response.Message = fmt.Sprintf("Nothing to do")
|
|
|
|
|
response.Message = fmt.Sprintf("Rien à faire")
|
|
|
|
|
statusCode = http.StatusOK
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
@ -91,20 +91,20 @@ func PostTransactions(c echo.Context) error {
|
|
|
|
|
// Check if membre_id exists according to bottin
|
|
|
|
|
for _, transaction := range transactions {
|
|
|
|
|
if transaction.MembreID == "" {
|
|
|
|
|
response.Message = fmt.Sprintf("Cannot insert transaction without a membre_id")
|
|
|
|
|
response.Message = fmt.Sprintf("Impossible d'insérer une transaction sans membre_id (numéro étudiant)")
|
|
|
|
|
statusCode = http.StatusBadRequest
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
membre, err := bottinApiClient.GetMembre(transaction.MembreID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during bottinApiClient.GetMembre(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant bottinApiClient.GetMembre(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if membre.ID == "" {
|
|
|
|
|
response.Message = fmt.Sprintf("Cannot insert transaction for non-existent membre %s", membre.ID)
|
|
|
|
|
response.Message = fmt.Sprintf("Aucun membre avec numéro étudiant '%s' dans le bottin de l'AGECEM", membre.ID)
|
|
|
|
|
statusCode = http.StatusNotFound
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
@ -118,17 +118,17 @@ func PostTransactions(c echo.Context) error {
|
|
|
|
|
transaction, err := client.GetTransaction(transaction.MembreID, transaction.IsPerpetual)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err.Error() != "sql: no rows in result set" {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during client.GetTransaction(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant client.GetTransaction(): %s", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if transaction.ID != "" {
|
|
|
|
|
agendaType := "non-perpetual"
|
|
|
|
|
agendaType := "non-perpétuel"
|
|
|
|
|
if transaction.IsPerpetual {
|
|
|
|
|
agendaType = "perpetual"
|
|
|
|
|
agendaType = "perpétuel"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Message = fmt.Sprintf("Membre %s already received %s", transaction.MembreID, agendaType)
|
|
|
|
|
response.Message = fmt.Sprintf("Membre %s a déjà son agenda %s", transaction.MembreID, agendaType)
|
|
|
|
|
|
|
|
|
|
statusCode = http.StatusBadRequest
|
|
|
|
|
|
|
|
|
@ -139,13 +139,13 @@ func PostTransactions(c echo.Context) error {
|
|
|
|
|
insertedTransactions, err := client.InsertTransactions(transactions)
|
|
|
|
|
response.Data.Transactions = insertedTransactions
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Message = fmt.Sprintf("Error during client.InsertTransactions(): %s", err)
|
|
|
|
|
response.Message = fmt.Sprintf("Erreur pendant client.InsertTransactions(): %s", err)
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusCode = http.StatusCreated
|
|
|
|
|
response.Message = "Insert successful"
|
|
|
|
|
response.Message = "Insertion complétée"
|
|
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
|
|
|
|
}
|
|
|
|
|