implemented get all shares
This commit is contained in:
parent
f31f1bbf02
commit
508e109734
@ -104,3 +104,7 @@ func (c *Client) GetObjectMetadata(ctx context.Context, key string) (*types.Meta
|
||||
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetAllShares(ctx context.Context) ([]*types.Share, error) {
|
||||
return c.db.GetAllShares(ctx)
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ type DB interface {
|
||||
GetShare(ctx context.Context, slug string) (*types.Share, error)
|
||||
CreateShare(ctx context.Context, share *types.Share) error
|
||||
DeleteShare(ctx context.Context, slug string) error
|
||||
GetAllShares(ctx context.Context) ([]*types.Share, error)
|
||||
Close() error
|
||||
}
|
||||
|
@ -78,6 +78,28 @@ func (db *sqlLiteDB) DeleteShare(ctx context.Context, slug string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *sqlLiteDB) GetAllShares(ctx context.Context) ([]*types.Share, error) {
|
||||
res, err := db.db.QueryContext(ctx, "SELECT slug, objKey FROM shares")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var shares []*types.Share
|
||||
|
||||
for res.Next() {
|
||||
var share types.Share
|
||||
|
||||
err = res.Scan(&share.Slug, &share.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shares = append(shares, &share)
|
||||
}
|
||||
|
||||
return shares, nil
|
||||
}
|
||||
|
||||
func (db *sqlLiteDB) Close() error {
|
||||
return db.db.Close()
|
||||
}
|
||||
|
@ -62,6 +62,16 @@ func StartWebserver(addr string, client client.Client, username, password string
|
||||
return
|
||||
}
|
||||
|
||||
shares, err := client.GetAllShares(r.Context())
|
||||
|
||||
if err != nil {
|
||||
logrus.Error(err.Error())
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(shares)
|
||||
}).Methods("GET")
|
||||
|
||||
r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
Loading…
Reference in New Issue
Block a user