Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
oprstchn committed Aug 19, 2018
1 parent e59a18d commit 9503bce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions webapp/go/isuda.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ func topHandler(w http.ResponseWriter, r *http.Request) {
// TABLE id, entry_ids, contents

// TODO:
// html, keyword
rows, err := db.Query(fmt.Sprintf(
"SELECT * FROM entry ORDER BY updated_at DESC LIMIT %d OFFSET %d",
// "SELECT * FROM entry ORDER BY updated_at DESC LIMIT %d OFFSET %d",
"SELECT id, author_id, keyword, description FROM entry ORDER BY updated_at DESC LIMIT %d OFFSET %d",
perPage, perPage*(page-1),
))
if err != nil && err != sql.ErrNoRows {
Expand All @@ -112,7 +114,8 @@ func topHandler(w http.ResponseWriter, r *http.Request) {
entries := make([]*Entry, 0, 10)
for rows.Next() {
e := Entry{}
err := rows.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt)
// err := rows.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt)
err := rows.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description)
panicIf(err)
e.Html = htmlify(w, r, e.Description)
e.Stars = loadStars(e.Keyword)
Expand Down Expand Up @@ -280,7 +283,7 @@ func keywordByKeywordHandler(w http.ResponseWriter, r *http.Request) {
row := db.QueryRow(`SELECT * FROM entry WHERE keyword = ?`, keyword)
e := Entry{}
//TODO: UpdatedAt, CreatedAt, Id, AuthorID は未使用
err = row.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt)
err = row.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt, &e.KeyWordLength)
if err == sql.ErrNoRows {
notFound(w)
return
Expand Down Expand Up @@ -318,7 +321,7 @@ func keywordByKeywordDeleteHandler(w http.ResponseWriter, r *http.Request) {
}
row := db.QueryRow(`SELECT * FROM entry WHERE keyword = ?`, keyword)
e := Entry{}
err := row.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt)
err := row.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt, &e.KeyWordLength)
if err == sql.ErrNoRows {
notFound(w)
return
Expand Down Expand Up @@ -349,8 +352,9 @@ func htmlify(w http.ResponseWriter, r *http.Request, content string) string {
for rows.Next() {
e := Entry{}
// TODO: とるのKeywordだけにする
err := rows.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt)
err := rows.Scan(&e.ID, &e.AuthorID, &e.Keyword, &e.Description, &e.UpdatedAt, &e.CreatedAt, &e.KeyWordLength)
panicIf(err)
fmt.Println("entry", e)
entries = append(entries, &e)
}
rows.Close()
Expand Down Expand Up @@ -387,6 +391,7 @@ func loadStars(keyword string) []*Star {
var data struct {
Result []*Star `json:result`
}
// fmt.Println(data)
err = json.NewDecoder(resp.Body).Decode(&data)
panicIf(err)
return data.Result
Expand Down
1 change: 1 addition & 0 deletions webapp/go/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Entry struct {
Description string
UpdatedAt time.Time
CreatedAt time.Time
KeyWordLength int

Html string
Stars []*Star
Expand Down

0 comments on commit 9503bce

Please sign in to comment.