remove unused function and get message queue
This commit is contained in:
		
							parent
							
								
									e658f15463
								
							
						
					
					
						commit
						b58ea19a86
					
				@ -298,8 +298,36 @@ func (app *application) postGuestbookCommentCreate(w http.ResponseWriter, r *htt
 | 
				
			|||||||
    http.Redirect(w, r, fmt.Sprintf("/guestbooks/%s", guestbookSlug), http.StatusSeeOther)
 | 
					    http.Redirect(w, r, fmt.Sprintf("/guestbooks/%s", guestbookSlug), http.StatusSeeOther)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (app *application) updateGuestbookComment(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *application) deleteGuestbookComment(w http.ResponseWriter, r *http.Request) {
 | 
					func (app *application) deleteGuestbookComment(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
    // slug := r.PathValue("id")
 | 
					    // slug := r.PathValue("id")
 | 
				
			||||||
    // shortId := slugToShortId(slug)
 | 
					    // shortId := slugToShortId(slug)
 | 
				
			||||||
    // app.guestbookComments.Delete(shortId)
 | 
					    // app.guestbookComments.Delete(shortId)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (app *application) getCommentQueue(w http.ResponseWriter, r *http.Request) []models.GuestbookComment {
 | 
				
			||||||
 | 
					    guestbookSlug := r.PathValue("id")
 | 
				
			||||||
 | 
					    guestbook, err := app.guestbooks.Get(slugToShortId(guestbookSlug))
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        if errors.Is(err, models.ErrNoRecord) {
 | 
				
			||||||
 | 
					            http.NotFound(w, r)
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            app.serverError(w, r, err)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return []models.GuestbookComment{}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    comments, err := app.guestbookComments.GetQueue(guestbook.ID)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        if errors.Is(err, models.ErrNoRecord) {
 | 
				
			||||||
 | 
					            http.NotFound(w, r)
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            app.serverError(w, r, err)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return []models.GuestbookComment{}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return comments
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -105,7 +105,3 @@ func openDB(dsn string) (*sql.DB, error) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return db, nil
 | 
					    return db, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func getUserId() int64 {
 | 
					 | 
				
			||||||
    return 1
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,35 @@ func (m *GuestbookCommentModel) Get(shortId uint64) (GuestbookComment, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (m *GuestbookCommentModel) GetAll(guestbookId int64) ([]GuestbookComment, error) {
 | 
					func (m *GuestbookCommentModel) GetAll(guestbookId int64) ([]GuestbookComment, error) {
 | 
				
			||||||
    stmt := `SELECT Id, ShortId, GuestbookId, ParentId, AuthorName, AuthorEmail, AuthorSite,
 | 
					    stmt := `SELECT Id, ShortId, GuestbookId, ParentId, AuthorName, AuthorEmail, AuthorSite,
 | 
				
			||||||
    CommentText, PageUrl, Created, IsPublished, IsDeleted FROM guestbook_comments WHERE GuestbookId = ? AND IsDeleted = FALSE ORDER BY Created DESC`
 | 
					    CommentText, PageUrl, Created, IsPublished, IsDeleted 
 | 
				
			||||||
 | 
						    FROM guestbook_comments 
 | 
				
			||||||
 | 
						    WHERE GuestbookId = ? AND IsDeleted = FALSE AND IsPublished = TRUE
 | 
				
			||||||
 | 
						    ORDER BY Created DESC`
 | 
				
			||||||
 | 
					    rows, err := m.DB.Query(stmt, guestbookId)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
						return nil, err
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    var comments []GuestbookComment
 | 
				
			||||||
 | 
					    for rows.Next() {
 | 
				
			||||||
 | 
						var c GuestbookComment
 | 
				
			||||||
 | 
						err = rows.Scan(&c.ID, &c.ShortId, &c.GuestbookId, &c.ParentId, &c.AuthorName, &c.AuthorEmail, &c.AuthorSite, &c.CommentText, &c.PageUrl, &c.Created, &c.IsPublished, &c.IsDeleted)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
						    return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						comments = append(comments, c)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if err = rows.Err(); err != nil {
 | 
				
			||||||
 | 
						return nil, err
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return comments, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *GuestbookCommentModel) GetQueue(guestbookId int64) ([]GuestbookComment, error) {
 | 
				
			||||||
 | 
					    stmt := `SELECT Id, ShortId, GuestbookId, ParentId, AuthorName, AuthorEmail, AuthorSite,
 | 
				
			||||||
 | 
					    CommentText, PageUrl, Created, IsPublished, IsDeleted 
 | 
				
			||||||
 | 
						    FROM guestbook_comments 
 | 
				
			||||||
 | 
						    WHERE GuestbookId = ? AND IsDeleted = FALSE AND IsPublished = FALSE
 | 
				
			||||||
 | 
						    ORDER BY Created DESC`
 | 
				
			||||||
    rows, err := m.DB.Query(stmt, guestbookId)
 | 
					    rows, err := m.DB.Query(stmt, guestbookId)
 | 
				
			||||||
    if err != nil {
 | 
					    if err != nil {
 | 
				
			||||||
	return nil, err
 | 
						return nil, err
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user