diff --git a/backend/api/get_blog.go b/backend/api/blogs/blog.go similarity index 56% rename from backend/api/get_blog.go rename to backend/api/blogs/blog.go index 65a8dfe..0101c24 100644 --- a/backend/api/get_blog.go +++ b/backend/api/blogs/blog.go @@ -2,7 +2,6 @@ package blogs import ( "context" - "fmt" "net/http" core "fr.latosa-escrima/api/core" @@ -34,25 +33,3 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) { }.Respond(w, http.StatusOK) return } - -func HandleGetBlogs(w http.ResponseWriter, r *http.Request) { - var blog []core.Blog - count, err := core.DB.NewSelect(). - Model(&blog). - Relation("Author"). - ScanAndCount(context.Background()) - if err != nil { - core.JSONError{ - Status: core.Error, - Message: err.Error(), - }.Respond(w, http.StatusNotAcceptable) - return - } - - core.JSONSuccess{ - Status: core.Success, - Message: fmt.Sprint("%d blogs objects sent", count), - Data: blog, - }.Respond(w, http.StatusOK) - return -} diff --git a/backend/api/blogs/blogs.go b/backend/api/blogs/blogs.go index 65a8dfe..ab10e53 100644 --- a/backend/api/blogs/blogs.go +++ b/backend/api/blogs/blogs.go @@ -8,15 +8,10 @@ import ( core "fr.latosa-escrima/api/core" ) -func HandleBlog(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - - blog_uuid := r.PathValue("uuid") - - var blog core.Blog - _, err := core.DB.NewSelect(). +func HandleGetBlogs(w http.ResponseWriter, r *http.Request) { + var blog []core.Blog + count, err := core.DB.NewSelect(). Model(&blog). - Where("blog_id = ?", blog_uuid). Relation("Author"). ScanAndCount(context.Background()) if err != nil { @@ -29,30 +24,8 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) { core.JSONSuccess{ Status: core.Success, - Message: "Status OK", + Message: fmt.Sprintf("%d blogs objects sent", count), Data: blog, }.Respond(w, http.StatusOK) return } - -func HandleGetBlogs(w http.ResponseWriter, r *http.Request) { - var blog []core.Blog - count, err := core.DB.NewSelect(). - Model(&blog). - Relation("Author"). - ScanAndCount(context.Background()) - if err != nil { - core.JSONError{ - Status: core.Error, - Message: err.Error(), - }.Respond(w, http.StatusNotAcceptable) - return - } - - core.JSONSuccess{ - Status: core.Success, - Message: fmt.Sprint("%d blogs objects sent", count), - Data: blog, - }.Respond(w, http.StatusOK) - return -} diff --git a/backend/api/blogs/delete_blog.go b/backend/api/blogs/delete_blog.go index e69de29..729d969 100644 --- a/backend/api/blogs/delete_blog.go +++ b/backend/api/blogs/delete_blog.go @@ -0,0 +1 @@ +package blogs diff --git a/backend/api/blogs/new_blog.go b/backend/api/blogs/new.go similarity index 100% rename from backend/api/blogs/new_blog.go rename to backend/api/blogs/new.go