Merge remote-tracking branch 'origin/dev/guerby' into dev/cedric
This commit is contained in:
@@ -2,12 +2,22 @@ package blogs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
<<<<<<< HEAD
|
||||||
|
"fmt"
|
||||||
|
=======
|
||||||
|
>>>>>>> dev/cedric
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
core "fr.latosa-escrima/core"
|
core "fr.latosa-escrima/core"
|
||||||
"fr.latosa-escrima/core/models"
|
"fr.latosa-escrima/core/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var blog []models.Blog
|
||||||
|
count, err := core.DB.NewSelect().
|
||||||
|
Model(&blog).
|
||||||
|
=======
|
||||||
func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
@@ -17,6 +27,7 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
|||||||
_, err := core.DB.NewSelect().
|
_, err := core.DB.NewSelect().
|
||||||
Model(&blog).
|
Model(&blog).
|
||||||
Where("blog_id = ?", blog_uuid).
|
Where("blog_id = ?", blog_uuid).
|
||||||
|
>>>>>>> dev/cedric
|
||||||
Relation("Author").
|
Relation("Author").
|
||||||
ScanAndCount(context.Background())
|
ScanAndCount(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,8 +40,40 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
core.JSONSuccess{
|
core.JSONSuccess{
|
||||||
Status: core.Success,
|
Status: core.Success,
|
||||||
|
<<<<<<< HEAD
|
||||||
|
Message: fmt.Sprintf("%d blogs objects sent", count),
|
||||||
|
=======
|
||||||
Message: "Status OK",
|
Message: "Status OK",
|
||||||
|
>>>>>>> dev/cedric
|
||||||
Data: blog,
|
Data: blog,
|
||||||
}.Respond(w, http.StatusOK)
|
}.Respond(w, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
<<<<<<<< HEAD:backend/api/blogs/blog.go
|
||||||
|
|
||||||
|
func HandleBlogs(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
|
||||||
|
}
|
||||||
|
========
|
||||||
|
>>>>>>>> dev/cedric:backend/api/blogs/blogs.go
|
||||||
|
=======
|
||||||
|
>>>>>>> dev/cedric
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package blogs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
core "fr.latosa-escrima/core"
|
|
||||||
"fr.latosa-escrima/core/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var blog []models.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.Sprintf("%d blogs objects sent", count),
|
|
||||||
Data: blog,
|
|
||||||
}.Respond(w, http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1 +1,35 @@
|
|||||||
package blogs
|
package blogs
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fr.latosa-escrima/api/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
uuid := r.PathValue("blog_uuid")
|
||||||
|
var blog core.Blog
|
||||||
|
res, err := core.DB.NewDelete().
|
||||||
|
Model(&blog).
|
||||||
|
Where("blog_id = ?", uuid).
|
||||||
|
Returning("*").
|
||||||
|
Exec(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(res)
|
||||||
|
|
||||||
|
core.JSONSuccess{
|
||||||
|
Status: core.Success,
|
||||||
|
Message: "Blog deleted.",
|
||||||
|
}.Respond(w, http.StatusOK)
|
||||||
|
}
|
||||||
|
=======
|
||||||
|
>>>>>>> dev/cedric
|
||||||
|
|||||||
53
backend/api/blogs/update.go
Normal file
53
backend/api/blogs/update.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package blogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fr.latosa-escrima/api/core"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var blog core.Blog
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&blog)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
blog_uuid := r.PathValue("blog_uuid")
|
||||||
|
blog.BlogID, err = uuid.Parse(blog_uuid)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(blog)
|
||||||
|
_, err = core.DB.NewUpdate().
|
||||||
|
Model(&blog).
|
||||||
|
OmitZero().
|
||||||
|
WherePK().
|
||||||
|
Exec(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: "Blog not found.",
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
core.JSONSuccess{
|
||||||
|
Status: core.Success,
|
||||||
|
Message: "Blog updated",
|
||||||
|
Data: blog,
|
||||||
|
}.Respond(w, http.StatusOK)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user