-
Notifications
You must be signed in to change notification settings - Fork 2
/
handlers.go
69 lines (59 loc) · 1.24 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"log"
"github.com/Blogify/models"
repo "github.com/Blogify/repositories"
"github.com/kataras/iris"
"gopkg.in/mgo.v2/bson"
)
func index(ctx iris.Context) {
posts, _ := repo.GetAll()
ctx.ViewData("Posts", posts)
ctx.View("index.html")
}
func loginUser(ctx iris.Context) {
// Login User
}
func fetchPosts(ctx iris.Context) {
// Fetch Posts
posts, _ := repo.GetAll()
ctx.JSON(posts)
}
func newPost(ctx iris.Context) {
ctx.View("create_posts.html")
}
func createPosts(ctx iris.Context) {
post := models.Post{}
err := ctx.ReadForm(&post)
if err != nil {
log.Println(err.Error())
}
post.ID = bson.NewObjectId()
repo.CreateOne(post)
ctx.Redirect("/")
}
func updatePosts(ctx iris.Context) {
var post models.Post
_ = ctx.ReadJSON(&post)
repo.Update(post)
ctx.ViewData("Post", models.Post{
ID: post.ID,
Name: post.Name,
Description: post.Description,
})
ctx.View("update_posts.html")
}
func deletePosts(ctx iris.Context) {
var post models.Post
_ = ctx.ReadJSON(&post)
repo.Delete(post)
ctx.ViewData("Post", models.Post{
ID: post.ID,
Name: post.Name,
Description: post.Description,
})
ctx.View("delete_posts.html")
}
func logoutUser(ctx iris.Context) {
// Logout User
}