mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Databases CRUD
This commit is contained in:
42
internal/repositories/databases.go
Normal file
42
internal/repositories/databases.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package repositories
|
||||
|
||||
var databases = []Database{
|
||||
{ID: "db1"},
|
||||
{ID: "db2"},
|
||||
}
|
||||
|
||||
func GetAllDatabases() ([]Database, RepositoryStatus) {
|
||||
return databases, StatusOk
|
||||
}
|
||||
|
||||
func GetDatabase(id string) (Database, RepositoryStatus) {
|
||||
for _, db := range databases {
|
||||
if db.ID == id {
|
||||
return db, StatusOk
|
||||
}
|
||||
}
|
||||
|
||||
return Database{}, StatusNotFound
|
||||
}
|
||||
|
||||
func DeleteDatabase(id string) RepositoryStatus {
|
||||
for index, db := range databases {
|
||||
if db.ID == id {
|
||||
databases = append(databases[:index], databases[index+1:]...)
|
||||
return StatusOk
|
||||
}
|
||||
}
|
||||
|
||||
return StatusNotFound
|
||||
}
|
||||
|
||||
func CreateDatabase(newDatabase Database) RepositoryStatus {
|
||||
for _, db := range databases {
|
||||
if db.ID == newDatabase.ID {
|
||||
return Conflict
|
||||
}
|
||||
}
|
||||
|
||||
databases = append(databases, newDatabase)
|
||||
return StatusOk
|
||||
}
|
||||
13
internal/repositories/models.go
Normal file
13
internal/repositories/models.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package repositories
|
||||
|
||||
type Database struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type RepositoryStatus int
|
||||
|
||||
const (
|
||||
StatusOk = 1
|
||||
StatusNotFound = 2
|
||||
Conflict = 3
|
||||
)
|
||||
Reference in New Issue
Block a user