更新
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"level_go/internal/service"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CommonHandler struct {
|
||||
Service *service.CommonService
|
||||
}
|
||||
|
||||
func (h *CommonHandler) GetTradeCalendar(c *gin.Context) {
|
||||
resp, err := h.Service.GetTradeCalendar()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"level_go/internal/model"
|
||||
"level_go/internal/service"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type StockHandler struct {
|
||||
Service *service.StockService
|
||||
}
|
||||
|
||||
func NewStockHandler(s *service.StockService) *StockHandler {
|
||||
return &StockHandler{Service: s}
|
||||
}
|
||||
|
||||
// GetKlineData 获取指定股票从2024-09-24至今的K线
|
||||
func (h *StockHandler) GetKlineData(c *gin.Context) {
|
||||
code := c.Param("code")
|
||||
if code == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "股票代码不能为空"})
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.Service.GetHistoryKline(code)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (h *StockHandler) Analyze(c *gin.Context) {
|
||||
var req model.AnalyzeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误"})
|
||||
return
|
||||
}
|
||||
|
||||
results, err := h.Service.AnalyzePerformance(req.StartDate, req.EndDate)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, results)
|
||||
}
|
||||
Reference in New Issue
Block a user