added backend and 2 endpoints fetch
This commit is contained in:
1 parent
7c6db3dfbd
commit
ca99cfcf6d
56 files changed
+344
-29
No files matched your search
@@ -0,0 +1,2 @@
|
||||
go.sum
|
||||
backend
|
||||
@@ -0,0 +1,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"backend/internal/category"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GetAllCategories(c *fiber.Ctx) error {
|
||||
categories, err := category.GetAllCategories()
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
return c.JSON(categories)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"backend/internal/operation"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GetAllOperation(c *fiber.Ctx) error {
|
||||
operations, err := operation.GetAllOperation()
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
return c.JSON(operations)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
module backend
|
||||
|
||||
go 1.24.5
|
||||
|
||||
require (
|
||||
github.com/gofiber/fiber v1.14.6
|
||||
github.com/gofiber/fiber/v2 v2.52.9
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/gofiber/utils v0.0.10 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/schema v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.51.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
package category
|
||||
|
||||
import "backend/model"
|
||||
|
||||
func GetAllCategories() ([]model.Category, error) {
|
||||
return []model.Category{
|
||||
{
|
||||
ID: "1",
|
||||
Title: "Electronics",
|
||||
Icon: "😀",
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Title: "Clothing",
|
||||
Icon: "😁",
|
||||
},
|
||||
{
|
||||
ID: "3",
|
||||
Title: "Books",
|
||||
Icon: "😂",
|
||||
Subcategories: []model.Subcategory{
|
||||
{
|
||||
ID: "1",
|
||||
Title: "Fiction",
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Title: "Non-Fiction",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package operation
|
||||
|
||||
import "backend/model"
|
||||
|
||||
func GetAllOperation() ([]model.Operation, error) {
|
||||
return []model.Operation{
|
||||
{
|
||||
ID: "1",
|
||||
Title: "Operation 1",
|
||||
Amount: 100,
|
||||
Category: "Category 1",
|
||||
SubCategory: model.Subcategory{
|
||||
ID: "1",
|
||||
Title: "subcategory",
|
||||
},
|
||||
Date: "2022-01-01T00:00:00Z",
|
||||
Type: "income",
|
||||
Icon: "😀",
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Title: "Operation 2",
|
||||
Amount: 200,
|
||||
Category: "Category 2",
|
||||
Date: "2022-01-02T00:00:00Z",
|
||||
Type: "expense",
|
||||
Icon: "😂",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"backend/server"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
server.Configure(app)
|
||||
|
||||
app.Listen(":3000")
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package model
|
||||
|
||||
type Category struct {
|
||||
ID string `json:"id"`
|
||||
Icon string `json:"icon"`
|
||||
Title string `json:"title"`
|
||||
Subcategories []Subcategory `json:"subcategories"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
type Operation struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Amount float64 `json:"amount"`
|
||||
Category string `json:"category"`
|
||||
SubCategory Subcategory `json:"subcategory,omitzero"`
|
||||
Note string `json:"note,omitempty"`
|
||||
Icon string `json:"icon"`
|
||||
Type string `json:"type"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type Subcategory struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"backend/api"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Configure(app *fiber.App) {
|
||||
app.Static("/", "../frontend/build")
|
||||
apiGroup := app.Group("/api")
|
||||
|
||||
operationGroup := apiGroup.Group("/operation")
|
||||
operationGroup.Get("/", api.GetAllOperation)
|
||||
|
||||
categoryGroup := apiGroup.Group("/category")
|
||||
categoryGroup.Get("/", api.GetAllCategories)
|
||||
}
|
||||
Reference in new issue
Block a user