modified: bot.db

modified:   handlers/dashboard.go
	modified:   main.go
	modified:   services/openrouter.go
	modified:   templates/dashboard.html
This commit is contained in:
2026-03-01 07:39:40 -03:00
parent 6f7987c3fe
commit e47b12b0d9
5 changed files with 452 additions and 247 deletions

View File

@@ -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