No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list_projects.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package api
  2. import (
  3. "git.x2erp.com/qdy/go-base/ctx"
  4. "git.x2erp.com/qdy/go-base/model/response"
  5. )
  6. // MockProjectsHandler 模拟项目列表(临时使用)
  7. // 路由: GET /api/projects
  8. func MockProjectsHandler(reqCtx *ctx.RequestContext) (*response.QueryResult[interface{}], error) {
  9. // 模拟项目数据
  10. projects := []map[string]interface{}{
  11. {
  12. "id": "proj_1",
  13. "name": "示例项目1",
  14. "description": "这是第一个示例项目",
  15. "path": "./projects/proj_1",
  16. "tenant_id": reqCtx.TenantID,
  17. "creator": reqCtx.UserID,
  18. "created_at": "2024-01-01T00:00:00Z",
  19. },
  20. {
  21. "id": "proj_2",
  22. "name": "示例项目2",
  23. "description": "这是第二个示例项目",
  24. "path": "./projects/proj_2",
  25. "tenant_id": reqCtx.TenantID,
  26. "creator": reqCtx.UserID,
  27. "created_at": "2024-01-02T00:00:00Z",
  28. },
  29. {
  30. "id": "proj_3",
  31. "name": "示例项目3",
  32. "description": "这是第三个示例项目",
  33. "path": "./projects/proj_3",
  34. "tenant_id": reqCtx.TenantID,
  35. "creator": reqCtx.UserID,
  36. "created_at": "2024-01-03T00:00:00Z",
  37. },
  38. }
  39. // 如果有租户ID,过滤项目
  40. tenantID, _ := GetRequestContext(reqCtx)
  41. filteredProjects := []map[string]interface{}{}
  42. for _, project := range projects {
  43. if tenantID == "" || project["tenant_id"] == tenantID {
  44. filteredProjects = append(filteredProjects, project)
  45. }
  46. }
  47. return &response.QueryResult[interface{}]{
  48. Success: true,
  49. Data: filteredProjects,
  50. }, nil
  51. }