From 55f5ce96b87443da2c32f468521cdb16d7ddba8a Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 20:05:05 -0400 Subject: [PATCH] =?UTF-8?q?Cleanup=20blocs=20de=20commentaires=20d=C3=A9su?= =?UTF-8?q?ets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/apiclient.go | 16 ------ data/data.go | 122 ---------------------------------------------- handlers/read.go | 68 -------------------------- 3 files changed, 206 deletions(-) diff --git a/data/apiclient.go b/data/apiclient.go index 585dd33..2f1f1ae 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -45,11 +45,6 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo a.Protocol, a.Host, a.Port, route, ) - /* - //TODO - log.Println("endpoint: ", endpoint) - */ - // Create client client := &http.Client{} @@ -119,11 +114,6 @@ func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) { return getMembreResponse.Data.Membre, errors.New("Veuillez fournir un numéro étudiant à rechercher") } - //TODO - /* - log.Println("ApiClient.GetMembre received membreID: ", membreID) - */ - response, err := a.Call(http.MethodGet, fmt.Sprintf("/v5/membres/%s", membreID), nil, true) if err != nil { return getMembreResponse.Data.Membre, err @@ -140,12 +130,6 @@ func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) { return getMembreResponse.Data.Membre, err } - /* - if getMembreResponse.Message != "Read successful" { - return getMembreResponse.Data.Membre, errors.New(getMembreResponse.Message) - } - */ - if getMembreResponse.Data.Membre == *new(models.Membre) { return getMembreResponse.Data.Membre, fmt.Errorf("Ce numéro étudiant ne correspond à aucunE membre") } diff --git a/data/data.go b/data/data.go index 1e4d17a..9a16342 100644 --- a/data/data.go +++ b/data/data.go @@ -182,125 +182,3 @@ func (d *DataClient) UpdateMembreName(membreID, newName string) (int64, error) { return rows, nil } - -/* -func (d *DataClient) Insert(assets []models.Asset) (id int64, err error) { - // Check for minimal required info - for _, asset := range assets { - if asset.Description == "" { - err = errors.New("Cannot insert: At least one asset has no `description` set.") - return - } - } - - tx := d.DB.MustBegin() - - for _, asset := range assets { - _, err = tx.NamedExec("INSERT INTO assets (description, status, created_at) VALUES (:description, :status, current_timestamp)", asset) - if err != nil { - return - } - } - - err = tx.Commit() - - return -} - -func (d *DataClient) List() ([]models.Asset, error) { - // Query the database, storing results in a []Person (wrapped in []interface{}) - assets := []models.Asset{} - - err := d.DB.Select(&assets, "SELECT * FROM assets WHERE deleted_at IS NULL LIMIT 1000") - if err != nil { - return nil, err - } - - return assets, nil -} - -// RecordEvent allows inserting into events when an asset or a tag is modified -// or deleted. -func (d *DataClient) RecordEvent(assetID, tagID int64, content string) error { - event := models.Event{ - AssetID: assetID, - TagID: tagID, - Content: content, - } - _, err := d.DB.NamedExec("INSERT INTO events (asset_id, tag_id, at, content) VALUES (:asset_id, :tag_id, current_timestamp, :content);", event) - if err != nil { - return err - } - - return nil -} - -func (d *DataClient) Delete(assetIDs []int64) ([]int64, error) { - var rows []int64 - - tx := d.DB.MustBegin() - - for _, assetID := range assetIDs { - result, err := d.DB.Exec("UPDATE assets SET deleted_at = current_timestamp WHERE id = $1 AND deleted_at IS NULL;", assetID) - if err != nil { - return rows, err - } - - rowsAffected, err := result.RowsAffected() - if err != nil { - return rows, err - } - - if rowsAffected != 0 { - rows = append(rows, assetID) - } - } - - err := tx.Commit() - if err != nil { - return rows, err - } - - for _, assetID := range assetIDs { - d.RecordEvent(assetID, -1, fmt.Sprintf("Asset %d deleted.", assetID)) - } - - return rows, nil -} - -func (d *DataClient) UpdateAssetDescription(assetID int64, description string) (int64, error) { - result, err := d.DB.Exec("UPDATE assets SET description = $1 WHERE id = $2", description, assetID) - if err != nil { - return 0, err - } - - rowsAffected, err := result.RowsAffected() - if err != nil { - return 0, err - } - - if rowsAffected != 0 { - return 0, errors.New("Nothing to do") - } - - return rowsAffected, nil -} - -func (d *DataClient) UpdateAssetStatus(assetID int64, status string) (int64, error) { - result, err := d.DB.Exec("UPDATE assets SET status = $1 WHERE id = $2", status, assetID) - if err != nil { - return 0, err - } - - rowsAffected, err := result.RowsAffected() - if err != nil { - return 0, err - } - - if rowsAffected != 0 { - return 0, errors.New("Nothing to do") - } - - return rowsAffected, nil -} -*/ diff --git a/handlers/read.go b/handlers/read.go index c5a074d..13a8007 100644 --- a/handlers/read.go +++ b/handlers/read.go @@ -47,71 +47,3 @@ func ReadMembre(c echo.Context) error { }, }) } - -/* -func PostMembres(c echo.Context) error { - connection := data.PostgresConnection{ - User: viper.GetString("db.user"), - Password: viper.GetString("db.password"), - Host: viper.GetString("db.host"), - Database: viper.GetString("db.database"), - Port: viper.GetInt("db.port"), - } - - client, err := data.NewDataClient(connection) - if err != nil { - return c.JSON(http.StatusInternalServerError, map[string]string{ - "message": "Could not establish database connection", - "error": err.Error(), - }) - } - - programmes := []models.Programme{ - { - ID: "foo", - Titre: "Foo", - }, - { - ID: "bar", - Titre: "Bar", - }, - } - - newProgrammes, err := client.InsertProgrammes(programmes) - if err != nil { - return c.JSON(http.StatusInternalServerError, map[string]string{ - "message": "Could not insert programmes", - "error": err.Error(), - }) - } - - membres := []models.Membre{ - { - ID: "1327163", - PreferedName: "victor", - ProgrammeID: "foo", - }, - { - ID: "0000000", - PreferedName: "test user", - ProgrammeID: "bar", - }, - } - - newMembres, err := client.InsertMembres(membres) - if err != nil { - return c.JSON(http.StatusInternalServerError, map[string]string{ - "message": "Could not insert membres", - "error": err.Error(), - }) - } - - return c.JSON(http.StatusOK, map[string]interface{}{ - "message": "Insert successful", - "data": map[string]interface{}{ - "membres": newMembres, - "programmes": newProgrammes, - }, - }) -} -*/