From 582ab5e7b9a2941e78603e03fb51167898bcdd53 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Wed, 8 Oct 2025 12:46:10 +0700 Subject: [PATCH] updated --- backend/database/operations.go | 3 ++ backend/default_operations.json | 87 ++++++++++++++++----------------- backend/model/Operation.go | 6 +-- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/backend/database/operations.go b/backend/database/operations.go index d66e7b8..1354884 100644 --- a/backend/database/operations.go +++ b/backend/database/operations.go @@ -44,6 +44,9 @@ func GetAllOperations(userid string) ([]model.Operation, error) { return nil, e } for i := range operations { + if operations[i].CategoryID == "" { + continue + } var category model.Category e := Db.First(&category, "ID = ?", operations[i].CategoryID).Error if e != nil { diff --git a/backend/default_operations.json b/backend/default_operations.json index d6ff419..88fdc87 100644 --- a/backend/default_operations.json +++ b/backend/default_operations.json @@ -1,45 +1,44 @@ [ - { - "title": "Operation 1", - "amount": 100, - "date": "2022-01-01T00:00:00Z", - "type": "income", - "icon": "😀", - "categoryid": "8f8b5f62-5d30-44a0-8de0-0485200f53a5" - }, - { - "title": "Operation 2", - "amount": 200, - "date": "2022-01-02T00:00:00Z", - "type": "expense", - "icon": "😂" - }, - { - "title": "Operation 2", - "amount": 200, - "date": "2022-01-02T00:00:00Z", - "type": "expense", - "icon": "😂" - }, - { - "title": "Operation 1", - "amount": 100, - "date": "2022-01-02T00:00:00Z", - "type": "income", - "icon": "😀" - }, - { - "title": "Operation 2", - "amount": 200, - "date": "2022-06-02T00:00:00Z", - "type": "expense", - "icon": "😂" - }, - { - "title": "Operation 2", - "amount": 200, - "date": "2022-06-22T00:00:00Z", - "type": "expense", - "icon": "😂" - } -] \ No newline at end of file + { + "title": "Operation 1", + "amount": 100, + "date": "2022-01-01T00:00:00Z", + "type": "income", + "icon": "😀" + }, + { + "title": "Operation 2", + "amount": 200, + "date": "2022-01-02T00:00:00Z", + "type": "expense", + "icon": "😂" + }, + { + "title": "Operation 2", + "amount": 200, + "date": "2022-01-02T00:00:00Z", + "type": "expense", + "icon": "😂" + }, + { + "title": "Operation 1", + "amount": 100, + "date": "2022-01-02T00:00:00Z", + "type": "income", + "icon": "😀" + }, + { + "title": "Operation 2", + "amount": 200, + "date": "2022-06-02T00:00:00Z", + "type": "expense", + "icon": "😂" + }, + { + "title": "Operation 2", + "amount": 200, + "date": "2022-06-22T00:00:00Z", + "type": "expense", + "icon": "😂" + } +] diff --git a/backend/model/Operation.go b/backend/model/Operation.go index dbf40a0..6db17af 100644 --- a/backend/model/Operation.go +++ b/backend/model/Operation.go @@ -10,7 +10,7 @@ type Operation struct { Date string `json:"date"` UserID string `json:"userid"` CategoryID string `json:"categoryid"` - SubcategoryID string `json:"subcategoryid"` - Category Category `gorm:"foreignKey:CategoryID"` - Subcategory Subcategory `gorm:"foreignKey:SubcategoryID"` + SubcategoryID *string `json:"subcategoryid,omitempty"` + Category Category `json:"category,omitzero"` + Subcategory Subcategory `json:"subcategory,omitzero"` }