Continue on ynab import
This commit is contained in:
39
http/http.go
39
http/http.go
@ -80,12 +80,51 @@ func (h *Handler) Serve() {
|
||||
{
|
||||
transaction.Use(h.verifyLoginWithRedirect)
|
||||
transaction.POST("/new", h.newTransaction)
|
||||
transaction.POST("/import/ynab", h.importYNAB)
|
||||
}
|
||||
}
|
||||
|
||||
router.Run(":1323")
|
||||
}
|
||||
|
||||
func (h *Handler) importYNAB(c *gin.Context) {
|
||||
transactionsFile, err := c.FormFile("transactions")
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
transactions, err := transactionsFile.Open()
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
budgetID, succ := c.GetPostForm("budget_id")
|
||||
if !succ {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
if !succ {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
ynab, err := NewYNABImport(h.Service.DB, budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = ynab.Import(transactions)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) verifyLoginWithRedirect(c *gin.Context) {
|
||||
_, err := h.verifyLogin(c)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user