Update + Delete articles
This commit is contained in:
@@ -3,18 +3,25 @@ package blogs
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
core "fr.latosa-escrima/core"
|
||||
"fr.latosa-escrima/core/models"
|
||||
)
|
||||
|
||||
func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
||||
slug := r.PathValue("slug")
|
||||
identifier := r.PathValue("identifier")
|
||||
query := "slug = ?"
|
||||
if regexp.
|
||||
MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`).
|
||||
MatchString(identifier) {
|
||||
query = "blog_id = ?"
|
||||
}
|
||||
|
||||
var blog models.Blog
|
||||
_, err := core.DB.NewSelect().
|
||||
Model(&blog).
|
||||
Where("slug = ?", slug).
|
||||
Where(query, identifier).
|
||||
Relation("Author").
|
||||
ScanAndCount(context.Background())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user