Skip to content

Commit

Permalink
fix blog created by
Browse files Browse the repository at this point in the history
  • Loading branch information
Kervin Christianata committed Jun 15, 2022
1 parent 1b3b266 commit 67fc3ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/api/blogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (app *application) showBlogHandler(w http.ResponseWriter, r *http.Request)
func (app *application) createBlogHandler(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(data.DefaultMaxMemory)

user := app.contextGetUser(r)

file, handler, err := r.FormFile("thumbnail")
if err != nil {
app.fileNotFoundResponse(w, r, "thumbnail")
Expand All @@ -84,7 +86,7 @@ func (app *application) createBlogHandler(w http.ResponseWriter, r *http.Request
}

blog := &data.Blog{
BlogCategoryID: blogCategoryId,
BlogCategoryID: int64(blogCategoryId),
Thumbnail: url,
Title: r.FormValue("title"),
Description: r.FormValue("description"),
Expand All @@ -95,7 +97,7 @@ func (app *application) createBlogHandler(w http.ResponseWriter, r *http.Request
Feature: r.FormValue("feature") == "true",
Status: r.FormValue("status"),
Tags: r.FormValue("tags"),
CreatedBy: 1,
CreatedBy: user.ID,
CreatedByText: "Admin",
}

Expand Down Expand Up @@ -167,7 +169,7 @@ func (app *application) updateBlogHandler(w http.ResponseWriter, r *http.Request
}

blog.Thumbnail = url
blog.BlogCategoryID = blogCategoryId
blog.BlogCategoryID = int64(blogCategoryId)
blog.Title = r.FormValue("title")
blog.Description = r.FormValue("description")
blog.Content = r.FormValue("content")
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (app *application) routes() http.Handler {
// Blogs
router.HandlerFunc(http.MethodGet, "/cms/blogs", app.listBlogsHandler)
router.HandlerFunc(http.MethodGet, "/cms/blogs/:id", app.showBlogHandler)
router.HandlerFunc(http.MethodPost, "/cms/blogs", app.createBlogHandler)
router.HandlerFunc(http.MethodPost, "/cms/blogs", app.requireAuthenticatedAdmin(app.createBlogHandler))
router.HandlerFunc(http.MethodPut, "/cms/blogs/:id", app.updateBlogHandler)
router.HandlerFunc(http.MethodDelete, "/cms/blogs/:id", app.deleteBlogHandler)

Expand Down
4 changes: 2 additions & 2 deletions internal/data/blogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Blog struct {
ID int64 `json:"id"`
BlogCategory BlogCategory `json:"blog_category"`
BlogCategoryID int `json:"blog_category_id"`
BlogCategoryID int64 `json:"blog_category_id"`
Thumbnail string `json:"thumbnail"`
Title string `json:"title"`
Description string `json:"description"`
Expand All @@ -23,7 +23,7 @@ type Blog struct {
Feature bool `json:"feature"`
Status string `json:"status"`
Tags string `json:"tags"`
CreatedBy int `json:"created_by"`
CreatedBy int64 `json:"created_by"`
DeletedAt time.Time `json:"-"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Expand Down

0 comments on commit 67fc3ba

Please sign in to comment.