api_list_recent_discuss.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package route
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "opennamu/route/tool"
  6. "strconv"
  7. )
  8. func Api_list_recent_discuss(call_arg []string) {
  9. db_set := map[string]string{}
  10. json.Unmarshal([]byte(call_arg[0]), &db_set)
  11. other_set := map[string]string{}
  12. json.Unmarshal([]byte(call_arg[1]), &other_set)
  13. db := tool.DB_connect(db_set)
  14. if db == nil {
  15. return
  16. }
  17. defer db.Close()
  18. limit_int, err := strconv.Atoi(other_set["limit"])
  19. if err != nil {
  20. return
  21. }
  22. if limit_int > 50 || limit_int < 0 {
  23. limit_int = 50
  24. }
  25. var stmt *sql.Stmt
  26. set_type := other_set["set_type"]
  27. if set_type == "normal" {
  28. stmt, err = db.Prepare(tool.DB_change(db_set, "select title, sub, date, code from rd where not stop = 'O' order by date desc limit ?"))
  29. } else if set_type == "close" {
  30. stmt, err = db.Prepare(tool.DB_change(db_set, "select title, sub, date, code from rd where stop = 'O' order by date desc limit ?"))
  31. } else {
  32. stmt, err = db.Prepare(tool.DB_change(db_set, "select title, sub, date, code from rd where stop != 'O' order by date asc limit ?"))
  33. }
  34. if err != nil {
  35. return
  36. }
  37. defer stmt.Close()
  38. rows, err := stmt.Query(limit_int)
  39. if err != nil {
  40. return
  41. }
  42. defer rows.Close()
  43. // var data_list [][]string
  44. // admin_auth := tool.Get_admin_auth(db, db_set, other_set["ip"])
  45. for rows.Next() {
  46. var title string
  47. var sub string
  48. var date string
  49. var code string
  50. err := rows.Scan(&title, &sub, &date, &code)
  51. if err != nil {
  52. return
  53. }
  54. stmt, err := db.Prepare(tool.DB_change(db_set, "select ip from topic where code = ? order by id + 0 desc limit 1"))
  55. if err != nil {
  56. return
  57. }
  58. defer stmt.Close()
  59. var ip string
  60. err = stmt.QueryRow(code).Scan(&ip)
  61. if err != nil {
  62. if err == sql.ErrNoRows {
  63. ip = ""
  64. } else {
  65. return
  66. }
  67. }
  68. }
  69. }