forked from BaoXuebin/beancount-gs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
- [X] 投资管理(FIFO) | ||
- [X] 第三方账单导入(支付宝,微信,工商银行,农业银行) | ||
- [X] 分期记账 | ||
- [ ] 事件 | ||
- [X] 事件 | ||
|
||
## 如何使用 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
) | ||
|
||
func isWindows() bool { | ||
return false | ||
os := runtime.GOOS | ||
return os == "windows" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,79 @@ | ||
package service | ||
|
||
import "github.com/gin-gonic/gin" | ||
import ( | ||
"fmt" | ||
"github.com/beancount-gs/script" | ||
"github.com/gin-gonic/gin" | ||
"strings" | ||
) | ||
|
||
type Event struct { | ||
Date string `json:"date"` | ||
Type string `json:"type"` | ||
Description string `json:"description"` | ||
Date string `form:"date" binding:"required" json:"date"` | ||
Type string `form:"type" binding:"required" json:"type"` | ||
Description string `form:"description" binding:"required" json:"description"` | ||
} | ||
|
||
func GetAllEvents(c *gin.Context) { | ||
OK(c, nil) | ||
ledgerConfig := script.GetLedgerConfigFromContext(c) | ||
output := script.BeanReportAllEvents(ledgerConfig) | ||
script.LogInfo(ledgerConfig.Mail, output) | ||
|
||
events := make([]Event, 0) | ||
lines := strings.Split(output, "\n") | ||
// foreach lines | ||
for idx, line := range lines { | ||
if idx < 2 || idx > len(lines)-3 { | ||
continue | ||
} | ||
if strings.Trim(line, " ") == "" { | ||
continue | ||
} | ||
// split line by " " | ||
words := strings.Fields(line) | ||
events = append(events, Event{ | ||
Date: words[0], | ||
Type: words[1], | ||
Description: words[2], | ||
}) | ||
} | ||
OK(c, events) | ||
} | ||
|
||
func AddEvent(c *gin.Context) { | ||
var event Event | ||
if err := c.ShouldBindJSON(&event); err != nil { | ||
BadRequest(c, err.Error()) | ||
return | ||
} | ||
|
||
ledgerConfig := script.GetLedgerConfigFromContext(c) | ||
filePath := script.GetLedgerEventsFilePath(ledgerConfig.DataPath) | ||
|
||
line := fmt.Sprintf("%s event \"%s\" \"%s\"", event.Date, event.Type, event.Description) | ||
// 写入文件 | ||
err := script.AppendFileInNewLine(filePath, line) | ||
if err != nil { | ||
InternalError(c, err.Error()) | ||
return | ||
} | ||
OK(c, event) | ||
} | ||
|
||
func DeleteEvent(c *gin.Context) { | ||
var event Event | ||
if err := c.ShouldBindJSON(&event); err != nil { | ||
BadRequest(c, err.Error()) | ||
return | ||
} | ||
|
||
ledgerConfig := script.GetLedgerConfigFromContext(c) | ||
filePath := script.GetLedgerEventsFilePath(ledgerConfig.DataPath) | ||
|
||
line := fmt.Sprintf("%s event \"%s\" \"%s\"", event.Date, event.Type, event.Description) | ||
err := script.DeleteLinesWithText(filePath, line) | ||
if err != nil { | ||
InternalError(c, err.Error()) | ||
return | ||
} | ||
OK(c, nil) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters