Explorar o código

Начато связывание генератора с БД

Anton %!s(int64=5) %!d(string=hai) anos
pai
achega
2250975eaf
Modificáronse 4 ficheiros con 60 adicións e 28 borrados
  1. 3 3
      api/check.go
  2. 5 1
      api/models.go
  3. 40 12
      api/scheduleGenerator.go
  4. 12 12
      schedule/models.go

+ 3 - 3
api/check.go

@@ -30,7 +30,7 @@ func CheckRoute(w http.ResponseWriter, r *http.Request){
 func planWithExample(w http.ResponseWriter, r *http.Request){
 	var subject Subjectofplan
 	json.NewDecoder(r.Body).Decode(&subject) // Декодируем JSON в экземпляр структуры
-	if subject != nil { // Проверка на пустой POST-запрос
+	if subject.IDPlan > 0 { // Проверка на пустой POST-запрос
 		json.NewEncoder(w).Encode(struct{ Error string }{ Error: "error during processing data" })
 		return
 	}
@@ -48,12 +48,12 @@ func planWithExample(w http.ResponseWriter, r *http.Request){
 	if subOfExample.Totalhours>=subject.Hoursquantitytotal{ // Если все в порядке, то возвращаем true и количество вариативных часов
 		var checkResult CheckResult
 		checkResult.Status = true
-		checkResult.Hours = subOfExample.Totalhours-subject.Hoursquantitytotal
+		checkResult.Hours = int(subOfExample.Totalhours)-int(subject.Hoursquantitytotal)
 		json.NewEncoder(w).Encode(checkResult)
 	} else{ // Если нет - возвращаем false и недостающее количество часов
 		var checkResult CheckResult
 		checkResult.Status = false
-		checkResult.Hours = subject.Hoursquantitytotal-subOfExample.Totalhours
+		checkResult.Hours = int(subject.Hoursquantitytotal)-int(subOfExample.Totalhours)
 		json.NewEncoder(w).Encode(checkResult)
 	}
 }

+ 5 - 1
api/models.go

@@ -1,5 +1,9 @@
 package api
 
+import(
+	"../schedule"
+)
+
 type Professionalmodule struct {
 	ID        uint
 	Name      string
@@ -87,7 +91,7 @@ type Schedule struct {
 	IsShort    bool
 	IDGroup    uint
 	IsEvenWeek bool
-	Weekday    string
+	Weekday    schedule.DayType
 }
 
 type Classroom struct {

+ 40 - 12
api/scheduleGenerator.go

@@ -5,7 +5,8 @@ import (
 	"fmt"
 	"net/http"
 
-	"../schedule"
+	// "../schedule"
+	// "../settings"
 )
 
 const (
@@ -15,17 +16,44 @@ const (
 func Generate(w http.ResponseWriter, r *http.Request) {
 	showAPIRequest(r)
 	if r.Method == "GET" {
-		var result [][]*schedule.Schedule
-		var generator = schedule.NewGenerator(&schedule.Generator{
-			Day: schedule.MONDAY,
-			// NumTables: 11,
-			Groups:   schedule.ReadGroups(INDATA + "groups.json"),
-			Teachers: schedule.ReadTeachers(INDATA + "teachers.json"),
-		})
-		for iter := 1; iter <= 7; iter++ {
-			result = append(result, generator.Generate(nil))
-		}
-		json.NewEncoder(w).Encode(result)
+		// var result [][]*schedule.Schedule
+		// var generator = schedule.NewGenerator(&schedule.Generator{
+		// 	Day: schedule.MONDAY,
+		// 	// NumTables: 11,
+		// 	Groups:   schedule.ReadGroups(INDATA + "groups.json"),
+		// 	Teachers: schedule.ReadTeachers(INDATA + "teachers.json"),
+		// })
+		// for iter := 1; iter <= 7; iter++ {
+		// 	midResult := generator.Generate(nil)
+		// 	result = append(result, midResult)
+		// 	var group Group
+		// 	settings.DB.Where("groupnumber = ?", midResult.Group).First(&group)
+		// 	var schedule Schedule
+		// 	schedule.IsShort = false
+		// 	schedule.IsEvenWeek = false
+		// 	schedule.Weekday = midResult.Day
+		// 	schedule.IDGroup = group.ID
+		// 	settings.DB.Create(&schedule)
+		// 	for i, row := range schedule.Row{
+		// 		if schedule.Row != nil {
+		// 			var schOfGroup Scheduleofgroup
+		// 			var subject Subject
+		// 			settings.DB.Where("shortname = ?", row.Subject[1]).First(&subject)
+		// 			schOfGroup.IDSubject = subject.ID
+		// 			schOfGroup.IDGroup = group.ID
+		// 			var sch Schedule
+		// 			settings.DB.Where(&schedule).First(&schedule)
+		// 			schOfGroup.IDSchedule = sch.ID
+		// 			schOfGroup.Lessonnumber = i
+
+		// 			var classroom Classroom
+		// 			settings.DB.Where("name = ?", row.Cabinet[1]).First(&classroom)
+
+		// 			schOfGroup.IDClassroom = classroom.ID
+		// 		}
+		// 	}
+		// }
+		// json.NewEncoder(w).Encode(result)
 	}
 }
 

+ 12 - 12
schedule/models.go

@@ -8,6 +8,18 @@ const (
 	IsSubTR   = 3
 )
 
+type Schedule struct {
+	Day   DayType
+	Group string
+	Table []Row
+}
+
+type Row struct {
+	Subject [ALL]string
+	Teacher [ALL]string
+	Cabinet [ALL]string
+}
+
 type PlanXLSX struct {
 	ProgramCode   string     `json:"program_code"`
 	NameCode      string     `json:"name_code"`
@@ -74,18 +86,6 @@ type Reserved struct {
 	Cabinets map[string][]bool
 }
 
-type Schedule struct {
-	Day   DayType
-	Group string
-	Table []Row
-}
-
-type Row struct {
-	Subject [ALL]string
-	Teacher [ALL]string
-	Cabinet [ALL]string
-}
-
 type Teacher struct {
 	Name     string    `json:"name"`
 	Cabinets []Cabinet `json:"cabinets"`