Creating db method to paginate all orders
This commit is contained in:
		@ -516,11 +516,35 @@ func (app *application) ResetPassword(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) AllSales(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	allSales, err := app.DB.GetAllOrders(false)
 | 
			
		||||
	var payload struct {
 | 
			
		||||
		PageSize    int `json:"page_size"`
 | 
			
		||||
		CurrentPage int `json:"page"`
 | 
			
		||||
	}
 | 
			
		||||
	err := app.readJSON(w, r, &payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
	}
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, allSales)
 | 
			
		||||
 | 
			
		||||
	allSales, lastPage, totalRecords, err := app.DB.GetAllOrdersPaginated(false, 2, 1)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var resp struct {
 | 
			
		||||
		CurrentPage  int             `json:"current_page"`
 | 
			
		||||
		PageSize     int             `json:"page_size"`
 | 
			
		||||
		LastPage     int             `json:"last_page"`
 | 
			
		||||
		TotalRecords int             `json:"total_records"`
 | 
			
		||||
		Orders       []*models.Order `json:"orders"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	resp.CurrentPage = 1
 | 
			
		||||
	resp.PageSize = payload.PageSize
 | 
			
		||||
	resp.LastPage = lastPage
 | 
			
		||||
	resp.TotalRecords = totalRecords
 | 
			
		||||
	resp.Orders = allSales
 | 
			
		||||
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) AllSubscriptions(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user