modified: bot.db
modified: handlers/dashboard.go modified: main.go modified: services/openrouter.go modified: templates/dashboard.html
This commit is contained in:
@@ -116,16 +116,37 @@ func UpdateAppointmentHandler(c *gin.Context) {
|
||||
|
||||
// POST /admin/chat
|
||||
func NewChatHandler(c *gin.Context) {
|
||||
// Insert a new chat record. In SQLite, this is enough to generate an ID.
|
||||
res, err := db.Conn.Exec("INSERT INTO chats (title) VALUES ('New Chat')")
|
||||
if err != nil {
|
||||
log.Println("Database Error in NewChat:", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create chat"})
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
id, _ := res.LastInsertId()
|
||||
c.JSON(http.StatusOK, gin.H{"id": id})
|
||||
// Return the ID so the frontend can select it immediately
|
||||
c.JSON(200, gin.H{"id": id, "title": "New Chat"})
|
||||
}
|
||||
|
||||
// DELETE /admin/chat/:id
|
||||
func DeleteChatHandler(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
// Delete messages first (foreign key cleanup usually, but we'll do manual for SQLite safety)
|
||||
db.Conn.Exec("DELETE FROM messages WHERE chat_id = ?", id)
|
||||
db.Conn.Exec("DELETE FROM chats WHERE id = ?", id)
|
||||
c.Status(200)
|
||||
}
|
||||
|
||||
// PUT /admin/chat/:id/rename
|
||||
func RenameChatHandler(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
var body struct {
|
||||
Title string `json:"title"`
|
||||
}
|
||||
if err := c.BindJSON(&body); err != nil {
|
||||
c.Status(400)
|
||||
return
|
||||
}
|
||||
db.Conn.Exec("UPDATE chats SET title = ? WHERE id = ?", body.Title, id)
|
||||
c.Status(200)
|
||||
}
|
||||
|
||||
// GET /admin/chat/:id/messages
|
||||
|
||||
Reference in New Issue
Block a user