Started working on the blogs
This commit is contained in:
@@ -3,7 +3,6 @@ package blogs
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
core "fr.latosa-escrima/core"
|
||||
@@ -11,14 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func HandleNew(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
var blog models.Blog
|
||||
if err := json.NewDecoder(r.Body).Decode(&blog); err != nil {
|
||||
core.JSONError{
|
||||
|
||||
25
backend/cmd/migrate/migrations/20250221153208_update_blog.go
Normal file
25
backend/cmd/migrate/migrations/20250221153208_update_blog.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"fr.latosa-escrima/core/models"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
||||
fmt.Print(" [up migration] ")
|
||||
_, err := db.NewDropColumn().
|
||||
Model((*models.Blog)(nil)).
|
||||
Column("href").
|
||||
Exec(ctx)
|
||||
_, err = db.Exec(`ALTER TABLE blogs RENAME COLUMN label TO title;
|
||||
ALTER TABLE blogs ALTER COLUMN title SET NOT NULL;`)
|
||||
return err
|
||||
}, func(ctx context.Context, db *bun.DB) error {
|
||||
fmt.Print(" [down migration] ")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -13,12 +13,11 @@ type Blog struct {
|
||||
BlogID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()" json:"blogID"`
|
||||
Slug string `bun:"slug,unique,notnull" json:"slug"`
|
||||
Content string `bun:"content,notnull" json:"content"`
|
||||
Label string `bun:"label" json:"label"`
|
||||
Title string `bun:"title,notnull" json:"title"`
|
||||
AuthorID uuid.UUID `bun:"author_id,type:uuid,notnull" json:"authorID"`
|
||||
Published time.Time `bun:"published,default:current_timestamp" json:"published"`
|
||||
Summary string `bun:"summary" json:"summary"`
|
||||
Image string `bun:"image" json:"image"`
|
||||
Href string `bun:"href" json:"href"`
|
||||
|
||||
Author User `bun:"rel:belongs-to,join:author_id=user_id" json:"author"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user