38 lines
		
	
	
		
			749 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			749 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package http
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"net/http"
 | 
						|
 | 
						|
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
						|
	"github.com/gin-gonic/gin"
 | 
						|
	"github.com/google/uuid"
 | 
						|
)
 | 
						|
 | 
						|
type BudgetData struct {
 | 
						|
	AlwaysNeededData
 | 
						|
	Transactions []postgres.GetTransactionsForBudgetRow
 | 
						|
}
 | 
						|
 | 
						|
func (h *Handler) budget(c *gin.Context) {
 | 
						|
	budgetID := c.Param("budgetid")
 | 
						|
	budgetUUID, err := uuid.Parse(budgetID)
 | 
						|
	if err != nil {
 | 
						|
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	transactions, err := h.Service.DB.GetTransactionsForBudget(context.Background(), budgetUUID)
 | 
						|
	if err != nil {
 | 
						|
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	d := BudgetData{
 | 
						|
		c.MustGet("data").(AlwaysNeededData),
 | 
						|
		transactions,
 | 
						|
	}
 | 
						|
 | 
						|
	c.HTML(http.StatusOK, "budget.html", d)
 | 
						|
}
 |