Merge pull request 'Cleanup blocs de commentaires désuets' (#23) from cleanup/comments into main
Reviewed-on: #23
This commit is contained in:
commit
26c0af3ad7
3 changed files with 0 additions and 206 deletions
|
@ -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")
|
||||
}
|
||||
|
|
122
data/data.go
122
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
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
|
Reference in a new issue