2024-02-10 16:52:41 +00:00
|
|
|
package repositories
|
|
|
|
|
|
|
|
var collections = []Collection{
|
|
|
|
{ID: "db1"},
|
|
|
|
{ID: "db2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAllCollections(databaseId string) ([]Collection, RepositoryStatus) {
|
2024-02-10 19:05:08 +00:00
|
|
|
dbCollections := make([]Collection, 0)
|
2024-02-10 16:52:41 +00:00
|
|
|
|
|
|
|
for _, coll := range collections {
|
|
|
|
if coll.internals.databaseId == databaseId {
|
|
|
|
dbCollections = append(dbCollections, coll)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbCollections, StatusOk
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCollection(databaseId string, id string) (Collection, RepositoryStatus) {
|
|
|
|
for _, coll := range collections {
|
|
|
|
if coll.internals.databaseId == databaseId && coll.ID == id {
|
|
|
|
return coll, StatusOk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collection{}, StatusNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteCollection(databaseId string, id string) RepositoryStatus {
|
|
|
|
for index, coll := range collections {
|
|
|
|
if coll.internals.databaseId == databaseId && coll.ID == id {
|
|
|
|
collections = append(collections[:index], collections[index+1:]...)
|
|
|
|
return StatusOk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return StatusNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateCollection(databaseId string, newCollection Collection) RepositoryStatus {
|
|
|
|
for _, coll := range collections {
|
|
|
|
if coll.internals.databaseId == databaseId && coll.ID == newCollection.ID {
|
|
|
|
return Conflict
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 18:17:33 +00:00
|
|
|
newCollection.internals = struct{ databaseId string }{
|
|
|
|
databaseId: databaseId,
|
|
|
|
}
|
2024-02-10 16:52:41 +00:00
|
|
|
collections = append(collections, newCollection)
|
|
|
|
return StatusOk
|
|
|
|
}
|