Skip to content

Commit e109827

Browse files
committedAug 21, 2019
add api and corresponding functions to insert meme abouts and tags
1 parent 4f39638 commit e109827

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎app/api.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,43 @@ func InsertMemeWithoutTags(w http.ResponseWriter, r *http.Request) {
6868
Tags: nil,
6969
},
7070
}
71+
7172
if err := insertMemes(db, memes); err != nil {
7273
log.Println(err.Error())
73-
http.Error(w, "can't insert memes without tags", http.StatusBadRequest)
74+
http.Error(w, "fail to insert memes without tags", http.StatusBadRequest)
75+
}
76+
}
77+
78+
// InsertMemeAboutsAndTags api to insert meme's advanced info, i.e. tags and about
79+
func InsertMemeAboutsAndTags(w http.ResponseWriter, r *http.Request) {
80+
db, connectErr := connectDB()
81+
if connectErr != nil {
82+
log.Println(connectErr.Error())
83+
http.Error(w, "connect db error", http.StatusBadRequest)
84+
}
85+
86+
memes := []memeDetail{
87+
memeDetail{
88+
Title: "corgi-1",
89+
ImageURL: "http://placecorgi.com/600/600",
90+
About: "",
91+
Tags: nil,
92+
},
93+
memeDetail{
94+
Title: "corgi-2",
95+
ImageURL: "http://placecorgi.com/600/600",
96+
About: "",
97+
Tags: nil,
98+
},
99+
}
100+
101+
if err := insertMemeAbouts(db, memes); err != nil {
102+
log.Println(err.Error())
103+
http.Error(w, "fail to insert meme abouts", http.StatusBadRequest)
104+
}
105+
106+
if err := insertMemeTags(db, memes); err != nil {
107+
log.Println(err.Error())
108+
http.Error(w, "fail to insert meme tags", http.StatusBadRequest)
74109
}
75110
}

‎main.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func main() {
1010
http.HandleFunc("/get_meme_details", app.GetMemeDetails)
1111
http.HandleFunc("/get_meme_without_tags", app.GetMemeWithoutTags)
1212
http.HandleFunc("/insert_meme_without_tags", app.InsertMemeWithoutTags)
13+
http.HandleFunc("/insert_meme_abouts_and_tags", app.InsertMemeAboutsAndTags)
1314

1415
// listen and serve
1516
if err := http.ListenAndServe(":8070", nil); err != nil {

2 commit comments

Comments
 (2)

Jasonnor commented on Aug 21, 2019

@Jasonnor
Member

No corgi, no

goan15910 commented on Aug 21, 2019

@goan15910
MemberAuthor
Please sign in to comment.