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)
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -7,6 +7,7 @@
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"axios": "^1.11.0",
|
||||
"bootstrap": "^5.3.7",
|
||||
"chart.js": "^4.5.0",
|
||||
"classnames": "^2.5.1",
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
File renamed without changes.
File renamed without changes.
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
File renamed without changes.
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,14 @@
|
||||
import axios from "axios";
|
||||
import routes from "../routes";
|
||||
|
||||
const fetchCategories = async () => {
|
||||
try {
|
||||
const response = await axios.get(routes.categories);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching categories:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default fetchCategories;
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -55,7 +55,7 @@ const CategorySign = ({ icon, title, subcategories }) => {
|
||||
style={{ borderRadius: "25px", padding: "0 15px" }}
|
||||
key={subcategory.id}
|
||||
>
|
||||
{subcategory.name}
|
||||
{subcategory.title}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,60 @@
|
||||
import getDateString from "../../logic/getDateString";
|
||||
import { Button } from "react-bootstrap";
|
||||
import classNames from "classnames";
|
||||
import styles from "./OperationSign.module.css";
|
||||
|
||||
const OperationSign = ({ operation }) => {
|
||||
return (
|
||||
<div className="gap-2">
|
||||
<div className="d-flex flex-row gap-3 p-2">
|
||||
<div
|
||||
className="p-2 justify-content-start align-items-start d-flex flex-column"
|
||||
style={{ fontSize: "30px" }}
|
||||
>
|
||||
<div>😀</div>
|
||||
</div>
|
||||
<div className="d-flex flex-column p-0 justify-content-start align-items-start w-100">
|
||||
<h3
|
||||
className="mb-0 fw-bolder"
|
||||
style={
|
||||
operation.type === "income"
|
||||
? { fontSize: "1.1rem", fontWeight: 700, color: "#2DBB4D" }
|
||||
: { fontSize: "1.1rem", fontWeight: 700 }
|
||||
}
|
||||
>
|
||||
{operation.type === "income" ? "" : "-"}
|
||||
{operation.amount} ₽
|
||||
</h3>
|
||||
<div className="text-muted small mb-1" style={{ fontSize: "0.8rem" }}>
|
||||
{operation.category}
|
||||
</div>
|
||||
{!operation.subcategory ? (
|
||||
""
|
||||
) : (
|
||||
<div
|
||||
className="text-muted small mb-1"
|
||||
style={{ fontSize: "0.8rem" }}
|
||||
>
|
||||
{operation.subcategory.title}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-muted small mb-1" style={{ fontSize: "0.8rem" }}>
|
||||
{operation.note && operation.note !== ""
|
||||
? operation.note
|
||||
: "No note"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-0 m-0" style={{ width: "100%", height: "100%" }}>
|
||||
<div
|
||||
className="text-muted small mb-1 text-end"
|
||||
style={{ fontSize: "0.8rem" }}
|
||||
>
|
||||
{getDateString(operation.date)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OperationSign;
|
||||
@@ -0,0 +1,7 @@
|
||||
.hideScrollbar {
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
}
|
||||
.hideScrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,8 @@
|
||||
const getDateString = (date) => {
|
||||
const dateData = new Date(date);
|
||||
return [
|
||||
dateData.getHours().toString().padStart(2, "0"),
|
||||
dateData.getMinutes().toString().padStart(2, "0"),
|
||||
].join(":");
|
||||
};
|
||||
export default getDateString;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+32
-24
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState, useMemo, useCallback } from "react";
|
||||
import { useTheme } from "../../contexts/ThemeContext";
|
||||
import {
|
||||
Modal,
|
||||
@@ -13,12 +13,31 @@ import {
|
||||
import styles from "./CategoriesModal.module.css";
|
||||
import CategorySign from "../../components/CategorySign/CategorySign";
|
||||
import AddCategoryModal from "../../modals/AddCategoryModal/AddCategoryModal";
|
||||
import fetchCategories from "../../category/GetAllCategories";
|
||||
|
||||
const CategoriesModal = ({ variant }) => {
|
||||
let [categories, setCategories] = useState([]);
|
||||
const { theme } = useTheme();
|
||||
const [show, setShow] = useState(false);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const handleClose = () => setShow(false);
|
||||
const handleShow = () => setShow(true);
|
||||
useEffect(() => {
|
||||
fetchCategories().then((data) => {
|
||||
setCategories(data);
|
||||
console.log(data);
|
||||
});
|
||||
}, []);
|
||||
const filteredCategories = useMemo(() => {
|
||||
if (!searchTerm) return categories;
|
||||
const term = searchTerm.toLowerCase();
|
||||
return categories.filter((category) =>
|
||||
category.title.toLowerCase().includes(term),
|
||||
);
|
||||
}, [categories, searchTerm]);
|
||||
const handleSearch = useCallback((e) => {
|
||||
setSearchTerm(e.target.value);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
@@ -61,6 +80,8 @@ const CategoriesModal = ({ variant }) => {
|
||||
placeholder="Search"
|
||||
aria-label="Search"
|
||||
aria-describedby="basic-addon1"
|
||||
value={searchTerm}
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</InputGroup>
|
||||
</div>
|
||||
@@ -79,29 +100,16 @@ const CategoriesModal = ({ variant }) => {
|
||||
className={styles.scrollableContent}
|
||||
style={{ padding: "10px" }}
|
||||
>
|
||||
<CategorySign
|
||||
icon="😀"
|
||||
title="Cash Loan"
|
||||
subcategories={[]}
|
||||
/>
|
||||
<CategorySign
|
||||
icon="😀"
|
||||
title="Cash Loan"
|
||||
subcategories={[
|
||||
{ id: 0, name: "Tbank" },
|
||||
{ id: 1, name: "Sber" },
|
||||
{ id: 2, name: "VTB" },
|
||||
{ id: 0, name: "Tbank" },
|
||||
{ id: 1, name: "Sber" },
|
||||
{ id: 2, name: "VTB" },
|
||||
{ id: 0, name: "Tbank" },
|
||||
{ id: 1, name: "Sber" },
|
||||
{ id: 2, name: "VTB" },
|
||||
{ id: 0, name: "Tbank" },
|
||||
{ id: 1, name: "Sber" },
|
||||
{ id: 2, name: "VTB" },
|
||||
]}
|
||||
/>
|
||||
{filteredCategories.map((category) => (
|
||||
<CategorySign
|
||||
key={category.id}
|
||||
icon={category.icon}
|
||||
title={category.title}
|
||||
subcategories={
|
||||
category.subcategories ? category.subcategories : []
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
File renamed without changes.
+22
-4
@@ -1,14 +1,23 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTheme } from "../../contexts/ThemeContext";
|
||||
import { ListGroup, Tabs, Tab, Modal, Button } from "react-bootstrap";
|
||||
import styles from "./HistoryModal.module.css";
|
||||
import AddOperationModal from "../AddOperationModal/AddOperationModal";
|
||||
import GetAllOperation from "../../operation/GetAllOperation";
|
||||
import OperationSign from "../../components/OperationSign/OperationSign";
|
||||
|
||||
const HistoryModal = () => {
|
||||
const { theme } = useTheme();
|
||||
const [show, setShow] = useState(false);
|
||||
const handleClose = () => setShow(false);
|
||||
const handleShow = () => setShow(true);
|
||||
const [operations, setOperations] = useState([]);
|
||||
useEffect(() => {
|
||||
GetAllOperation().then((data) => {
|
||||
console.log(data);
|
||||
setOperations(data);
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
@@ -38,7 +47,16 @@ const HistoryModal = () => {
|
||||
// style={{ maxHeight: "calc(100vh - 200px)", overflowY: "auto" }}
|
||||
>
|
||||
<div className={styles.scrollableContent}>
|
||||
<div className="d-flex m-1">
|
||||
{operations.map((operation) => {
|
||||
return (
|
||||
<ListGroup className="mb-3 mt-0">
|
||||
<ListGroup.Item className="p-0">
|
||||
<OperationSign operation={operation} />
|
||||
</ListGroup.Item>
|
||||
</ListGroup>
|
||||
);
|
||||
})}
|
||||
{/* <div className="d-flex m-1">
|
||||
<div className="d-flex flex-column p-0 justify-content-start align-items-start w-100">
|
||||
<h3
|
||||
className="mb-0 fw-bolder"
|
||||
@@ -636,8 +654,8 @@ const HistoryModal = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ListGroup.Item>
|
||||
</ListGroup>
|
||||
</ListGroup.Item> */}
|
||||
{/* </ListGroup> */}
|
||||
</div>
|
||||
</Tab>
|
||||
<Tab eventKey="W" title="W" className="pt-2 pb-2"></Tab>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,9 @@
|
||||
import routes from "../routes";
|
||||
|
||||
const GetAllOperation = async () => {
|
||||
const response = await fetch(routes.operations);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export default GetAllOperation;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,7 @@
|
||||
const host = window.location.origin;
|
||||
const prefix = "/api";
|
||||
const routes = {
|
||||
categories: `${host}${prefix}/category`,
|
||||
operations: `${host}${prefix}/operation`,
|
||||
};
|
||||
export default routes;
|
||||
File renamed without changes.
Reference in new issue
Block a user