mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-20 09:20:11 +00:00
DataStore is interface now. Liskov would be proud.
This commit is contained in:
@@ -5,15 +5,15 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
"github.com/pikami/cosmium/internal/datastore"
|
||||
)
|
||||
|
||||
func (h *Handlers) GetAllCollections(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
|
||||
collections, status := h.repository.GetAllCollections(databaseId)
|
||||
if status == repositorymodels.StatusOk {
|
||||
database, _ := h.repository.GetDatabase(databaseId)
|
||||
collections, status := h.dataStore.GetAllCollections(databaseId)
|
||||
if status == datastore.StatusOk {
|
||||
database, _ := h.dataStore.GetDatabase(databaseId)
|
||||
|
||||
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(collections)))
|
||||
c.IndentedJSON(http.StatusOK, gin.H{
|
||||
@@ -31,13 +31,13 @@ func (h *Handlers) GetCollection(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
id := c.Param("collId")
|
||||
|
||||
collection, status := h.repository.GetCollection(databaseId, id)
|
||||
if status == repositorymodels.StatusOk {
|
||||
collection, status := h.dataStore.GetCollection(databaseId, id)
|
||||
if status == datastore.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, collection)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
if status == datastore.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
@@ -49,13 +49,13 @@ func (h *Handlers) DeleteCollection(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
id := c.Param("collId")
|
||||
|
||||
status := h.repository.DeleteCollection(databaseId, id)
|
||||
if status == repositorymodels.StatusOk {
|
||||
status := h.dataStore.DeleteCollection(databaseId, id)
|
||||
if status == datastore.StatusOk {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
if status == datastore.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (h *Handlers) DeleteCollection(c *gin.Context) {
|
||||
|
||||
func (h *Handlers) CreateCollection(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
var newCollection repositorymodels.Collection
|
||||
var newCollection datastore.Collection
|
||||
|
||||
if err := c.BindJSON(&newCollection); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
||||
@@ -77,13 +77,13 @@ func (h *Handlers) CreateCollection(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
createdCollection, status := h.repository.CreateCollection(databaseId, newCollection)
|
||||
if status == repositorymodels.Conflict {
|
||||
createdCollection, status := h.dataStore.CreateCollection(databaseId, newCollection)
|
||||
if status == datastore.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
if status == datastore.StatusOk {
|
||||
c.IndentedJSON(http.StatusCreated, createdCollection)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user