1
0

scheduletemplate.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package api
  2. import (
  3. "../settings"
  4. "encoding/json"
  5. "fmt"
  6. "net/http"
  7. "../schedule"
  8. // "strconv"
  9. // "errors"
  10. // "math/rand"
  11. )
  12. var tmpteachers []schedule.Teacher
  13. var tmpcabinets []schedule.Cabinet
  14. var tmpgroups []schedule.Group
  15. var tmpsubjects []schedule.Subject
  16. // var tmplessons []schedule.LessonJSON
  17. func GetDataTeachers(w http.ResponseWriter, r *http.Request) {
  18. var classrooms []Classroom
  19. var teachers []Teacher
  20. settings.DB.Find(&teachers)
  21. settings.DB.Find(&classrooms)
  22. var cabinet schedule.Cabinet
  23. for _, room := range classrooms{
  24. cabinet.Name = room.Name
  25. cabinet.IsComputer = room.Iscomputer
  26. tmpcabinets = append(tmpcabinets, cabinet)
  27. }
  28. for _, teacher := range teachers{
  29. var scheduleTeacher schedule.Teacher
  30. scheduleTeacher.Name = teacher.Name + " " + string(teacher.Surname[:2]) + "." + string(teacher.Patronymic[:2]) + "."
  31. for _, room := range classrooms{
  32. if teacher.IDClassroom == room.ID {
  33. var tmpcabinet schedule.Cabinet
  34. tmpcabinet.Name = room.Name
  35. tmpcabinet.IsComputer = room.Iscomputer
  36. scheduleTeacher.Cabinets = append(scheduleTeacher.Cabinets, tmpcabinet)
  37. tmpcabinet = schedule.Cabinet{}
  38. break
  39. }
  40. }
  41. tmpteachers = append(tmpteachers, scheduleTeacher)
  42. }
  43. json.NewEncoder(w).Encode(tmpteachers)
  44. return
  45. }
  46. func GetDataGroups(w http.ResponseWriter, r *http.Request){
  47. // tmp := replacePath(r.URL.Path, "/api/getgroups/")
  48. // num, err := strconv.Atoi(tmp)
  49. // if err != nil{
  50. // json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error"})
  51. // }
  52. var groups []Group
  53. var subjects []Subject
  54. // var tmpsubofgroup1 []Subjectofgroup
  55. // var tmpsubofgroup2 []Subjectofgroup
  56. var tmpsubofgroup []Subjectofgroup
  57. settings.DB.Find(&groups)
  58. settings.DB.Find(&subjects)
  59. // settings.DB.Where("id_group = ?", num).Find(&tmpsubofgroup)
  60. for _, group := range groups{
  61. settings.DB.Where("id_group = ?", group.ID).Find(&tmpsubofgroup)
  62. var tmpgroup schedule.Group
  63. tmpgroup.Name = group.Groupnumber
  64. tmpgroup.Quantity = group.Studentsquantity
  65. for _, subject := range tmpsubofgroup{
  66. // scheduleTeacher.Name = teacher.Name + " " + string(teacher.Surname[:2]) + "." + string(teacher.Patronymic[:2]) + "."
  67. var tmpsubject schedule.Subject
  68. var tsubject Subject
  69. var teacher Teacher
  70. var semester Semester
  71. settings.DB.Where("id = ?", subject.ID).First(&tsubject)
  72. settings.DB.Where("id = ?", subject.IDTeacher).First(&teacher)
  73. settings.DB.Where("id = ?", subject.IDSemester).First(&semester)
  74. tmpsubject.Name = tsubject.Shortname
  75. tmpsubject.Teacher = teacher.Name + " " + string(teacher.Surname[:2]) + "." + string(teacher.Patronymic[:2]) + "."
  76. tmpsubject.Teacher2 = tmpsubject.Teacher // TODO
  77. if tsubject.IDStype == 1{
  78. tmpsubject.IsComputer = false
  79. tmpsubject.Theory = 0
  80. tmpsubject.Practice.A = subject.Hoursquantity/2
  81. tmpsubject.Practice.B = subject.Hoursquantity/2
  82. } else if tsubject.IDStype == 0{
  83. tmpsubject.IsComputer = true
  84. tmpsubject.Theory = subject.Hoursquantity/2
  85. tmpsubject.Practice.A = 0
  86. tmpsubject.Practice.B = 0
  87. }
  88. fmt.Println(semester)
  89. tmpsubject.WeekLessons.A = (subject.Hoursquantity/semester.Weeksquantity)/2
  90. tmpsubject.WeekLessons.B = (subject.Hoursquantity/semester.Weeksquantity)/2
  91. tmpsubjects = append(tmpsubjects, tmpsubject)
  92. }
  93. }
  94. // for i, sub := range tmpsubofgroup1{
  95. // var subof Subjectofgroup
  96. // for j, gr := range tmpsubofgroup2{
  97. // if gr == sub{
  98. // subof = gr
  99. // tmpsubofgroup1 = append(tmpsubofgroup1[:i], tmpsubofgroup[i+1:]...)
  100. // tmpsubofgroup2 = append(tmpsubofgroup1[:j], tmpsubofgroup[j+1:]...)
  101. // break
  102. // }
  103. // }
  104. // tmpsubofgroup = append(tmpsubofgroup, subof)
  105. // subof = Subjectofgroup{}
  106. // }
  107. json.NewEncoder(w).Encode(tmpsubjects)
  108. // for _, subject := range subjects{
  109. // var tmpsubject schedue.Subject
  110. // tmpsubject.Name = subject.ShortName
  111. // tmpsubject.teacher =
  112. // }
  113. }