This repository has been archived on 2023-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
sudoscientist-go-backend/packages/blog/blog.go
2019-04-15 18:40:50 -04:00

64 lines
1.2 KiB
Go

package blog
import (
"database/sql"
_ "fmt"
"github.com/go-chi/chi"
"github.com/go-chi/jwtauth"
_ "github.com/go-chi/render"
"net/http"
"time"
)
var (
DB *sql.DB
TokenAuth *jwtauth.JWTAuth
)
type BlogPost struct {
Title string `json:"title",db:"title"`
Slug string `json:"slug",db:"slug"`
Author string `json:"author",db:"author"`
DatePublished time.Time `json:"date", db:"date"`
}
func Init() {
dbCreateStatement := `
CREATE TABLE IF NOT EXISTS blog
(id SERIAL PRIMARY KEY,
title text,
slug text,
author text REFERENCES users (username),
date timestamp)`
DB.Exec(dbCreateStatement)
}
func Routes() *chi.Mux {
r := chi.NewRouter()
r.Group(func(r chi.Router) {
r.Use(jwtauth.Verifier(TokenAuth))
r.Use(jwtauth.Authenticator)
r.Post("/", createBlogPost)
r.Patch("/{slug}", updateBlogPost)
})
r.Get("/", getAllBlogPosts)
r.Get("/{slug}", getBlogPost)
return r
}
func createBlogPost(w http.ResponseWriter, r *http.Request) {
return
}
func updateBlogPost(w http.ResponseWriter, r *http.Request) {
return
}
func getAllBlogPosts(w http.ResponseWriter, r *http.Request) {
return
}
func getBlogPost(w http.ResponseWriter, r *http.Request) {
return
}