Skip to content

Commit

Permalink
feat: get log detail
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Dec 24, 2024
1 parent 4db4fa6 commit 40d6d56
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 59 deletions.
61 changes: 41 additions & 20 deletions service/aiproxy/controller/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func GetLogs(c *gin.Context) {
requestID := c.Query("request_id")
mode, _ := strconv.Atoi(c.Query("mode"))
codeType := c.Query("code_type")
logs, total, err := model.GetLogs(
withBody, _ := strconv.ParseBool(c.Query("with_body"))
result, err := model.GetLogs(
startTimestampTime,
endTimestampTime,
modelName,
Expand All @@ -57,15 +58,13 @@ func GetLogs(c *gin.Context) {
order,
mode,
model.CodeType(codeType),
withBody,
)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, gin.H{
"logs": logs,
"total": total,
})
middleware.SuccessResponse(c, result)
}

func GetGroupLogs(c *gin.Context) {
Expand Down Expand Up @@ -100,7 +99,8 @@ func GetGroupLogs(c *gin.Context) {
requestID := c.Query("request_id")
mode, _ := strconv.Atoi(c.Query("mode"))
codeType := c.Query("code_type")
logs, total, err := model.GetGroupLogs(
withBody, _ := strconv.ParseBool(c.Query("with_body"))
result, err := model.GetGroupLogs(
group,
startTimestampTime,
endTimestampTime,
Expand All @@ -115,15 +115,13 @@ func GetGroupLogs(c *gin.Context) {
order,
mode,
model.CodeType(codeType),
withBody,
)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, gin.H{
"logs": logs,
"total": total,
})
middleware.SuccessResponse(c, result)
}

func SearchLogs(c *gin.Context) {
Expand Down Expand Up @@ -155,7 +153,8 @@ func SearchLogs(c *gin.Context) {
requestID := c.Query("request_id")
mode, _ := strconv.Atoi(c.Query("mode"))
codeType := c.Query("code_type")
logs, total, err := model.SearchLogs(
withBody, _ := strconv.ParseBool(c.Query("with_body"))
result, err := model.SearchLogs(
keyword,
p,
perPage,
Expand All @@ -171,15 +170,13 @@ func SearchLogs(c *gin.Context) {
order,
mode,
model.CodeType(codeType),
withBody,
)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, gin.H{
"logs": logs,
"total": total,
})
middleware.SuccessResponse(c, result)
}

func SearchGroupLogs(c *gin.Context) {
Expand Down Expand Up @@ -211,7 +208,8 @@ func SearchGroupLogs(c *gin.Context) {
requestID := c.Query("request_id")
mode, _ := strconv.Atoi(c.Query("mode"))
codeType := c.Query("code_type")
logs, total, err := model.SearchGroupLogs(
withBody, _ := strconv.ParseBool(c.Query("with_body"))
result, err := model.SearchGroupLogs(
group,
keyword,
p,
Expand All @@ -227,15 +225,38 @@ func SearchGroupLogs(c *gin.Context) {
order,
mode,
model.CodeType(codeType),
withBody,
)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, gin.H{
"logs": logs,
"total": total,
})
middleware.SuccessResponse(c, result)
}

func GetLogDetail(c *gin.Context) {
logID, _ := strconv.Atoi(c.Param("log_id"))
log, err := model.GetLogDetail(logID)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, log)
}

func GetGroupLogDetail(c *gin.Context) {
group := c.Param("group")
if group == "" {
middleware.ErrorResponse(c, http.StatusOK, "group is required")
return
}
logID, _ := strconv.Atoi(c.Param("log_id"))
log, err := model.GetGroupLogDetail(group, logID)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, log)
}

func DeleteHistoryLogs(c *gin.Context) {
Expand Down
Loading

0 comments on commit 40d6d56

Please sign in to comment.