pagination all-subscriptions
This commit is contained in:
		@ -556,11 +556,43 @@ func (app *application) AllSales(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) AllSubscriptions(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	allSubscriptions, err := app.DB.GetAllOrders(true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
	var payload struct {
 | 
			
		||||
		PageSize    int `json:"page_size"`
 | 
			
		||||
		CurrentPage int `json:"page"`
 | 
			
		||||
	}
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, allSubscriptions)
 | 
			
		||||
	err := app.readJSON(w, r, &payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	allSales, lastPage, totalRecords, err := app.DB.GetAllOrdersPaginated(
 | 
			
		||||
		true,
 | 
			
		||||
		payload.PageSize,
 | 
			
		||||
		payload.CurrentPage,
 | 
			
		||||
	)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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 = payload.CurrentPage
 | 
			
		||||
	resp.PageSize = payload.PageSize
 | 
			
		||||
	resp.LastPage = lastPage
 | 
			
		||||
	resp.TotalRecords = totalRecords
 | 
			
		||||
	resp.Orders = allSales
 | 
			
		||||
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) GetSale(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
 | 
			
		||||
@ -20,11 +20,15 @@ All Subscriptions
 | 
			
		||||
    <tbody>
 | 
			
		||||
    </tbody>
 | 
			
		||||
</table>
 | 
			
		||||
<nav>
 | 
			
		||||
    <ul id="paginator" class="pagination">
 | 
			
		||||
    </ul>
 | 
			
		||||
</nav>
 | 
			
		||||
{{end}}
 | 
			
		||||
 | 
			
		||||
{{define "js"}}
 | 
			
		||||
<script type="module">
 | 
			
		||||
    import {showTable} from "/static/js/all-subscriptions.js"
 | 
			
		||||
    showTable({{.API}});
 | 
			
		||||
    import {showTable, pageSize, currentPage} from "/static/js/all-subscriptions.js"
 | 
			
		||||
    showTable({{.API}}, pageSize, currentPage);
 | 
			
		||||
</script>
 | 
			
		||||
{{end}}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user