获取session添加类型获取
This commit is contained in:
parent
e478c973ea
commit
2d7c14087d
|
|
@ -49,12 +49,12 @@ func FindSessionByID(id int) Session {
|
|||
}
|
||||
|
||||
// 获取用户最新的创建时间会话列表 50个
|
||||
func FindSessionByUserID(userID int) []Session {
|
||||
func FindSessionByUserID(userID, sessionType int) []Session {
|
||||
var sessions []Session
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
DB.Debug().Where("user_id = ?", userID).Order("created_at DESC").Limit(50).Find(&sessions)
|
||||
DB.Debug().Where("user_id = ? and type = ?", userID, sessionType).Order("created_at DESC").Limit(50).Find(&sessions)
|
||||
} else {
|
||||
DB.Where("user_id = ?", userID).Order("created_at DESC").Limit(50).Find(&sessions)
|
||||
DB.Where("user_id = ? and type = ?", userID, sessionType).Order("created_at DESC").Limit(50).Find(&sessions)
|
||||
}
|
||||
return sessions
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type Session struct {
|
|||
UserID int `json:"user_id" form:"user_id"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Type string `json:"type" form:"type"`
|
||||
SessionType int `json:"session_type" form:"session_type"`
|
||||
}
|
||||
|
||||
func CreateSession(c *gin.Context) {
|
||||
|
|
@ -46,14 +47,14 @@ func FindSession(c *gin.Context) {
|
|||
if err := c.ShouldBind(&req); err == nil {
|
||||
// 查找会话
|
||||
if req.Type == "ID" {
|
||||
err2, session := service.FindSessionByID(req.ID, userID)
|
||||
err2, session := service.FindSessionByID(req.ID, userID, req.SessionType)
|
||||
if err2 != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.SessionSearchFailed, "message": "failed"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": session})
|
||||
} else if req.Type == "UserID" {
|
||||
sessions := service.FindSessionByUserID(userID)
|
||||
sessions := service.FindSessionByUserID(userID, req.SessionType)
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": sessions})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"error": "type error", "code": proto.SessionSearchFailed, "message": "failed"})
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ func CreateSession(userID, Type int, name string) (error, uint) {
|
|||
}
|
||||
|
||||
// 查找用户的会话列表
|
||||
func FindSessionByUserID(userID int) []proto.SessionResponse {
|
||||
sessions := dao.FindSessionByUserID(userID)
|
||||
func FindSessionByUserID(userID, sessionType int) []proto.SessionResponse {
|
||||
sessions := dao.FindSessionByUserID(userID, sessionType)
|
||||
sessionsMsgCounts := dao.FindSessionMessageCountByUserID(userID)
|
||||
sessionsTokens := dao.FindModelTotalTokensBySessionID(userID)
|
||||
smap := make(map[int]int)
|
||||
|
|
@ -45,7 +45,7 @@ func FindSessionByUserID(userID int) []proto.SessionResponse {
|
|||
}
|
||||
return res
|
||||
}
|
||||
func FindSessionByID(id, userID int) (error, []dao.Session) {
|
||||
func FindSessionByID(id, userID, sessionType int) (error, []dao.Session) {
|
||||
session := dao.FindSessionByID(id)
|
||||
var res []dao.Session
|
||||
if session.UserID != userID {
|
||||
|
|
|
|||
Loading…
Reference in New Issue