Quellcode durchsuchen

API карточки группы и фикс вариативных часов

GhoosToy vor 5 Jahren
Ursprung
Commit
0614c3a56a
3 geänderte Dateien mit 66 neuen und 1 gelöschten Zeilen
  1. 63 0
      api/cardofgroup.go
  2. 1 1
      api/studyplan.go
  3. 2 0
      main.go

+ 63 - 0
api/cardofgroup.go

@@ -0,0 +1,63 @@
+package api
+
+import (
+	"../settings"
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"strconv"
+	"strings"
+)
+
+
+
+func CardOfGroupRoute(w http.ResponseWriter, r *http.Request) {
+
+	showAPIRequest(r)
+	w.Header().Set("Content-Type", "application/json")
+
+	path := replacePath(r.URL.Path, "/api/cardofgroup/")
+	var groupnum1 string
+	var semesternum1 string
+	
+	if path != "" && strings.Contains(path, "semester/") && r.Method == "GET" {
+		// парсим для нахождения номера группы и семестра
+		list := strings.Split(path, "/semester/")
+		groupnum1 = list[0]
+		semesternum1 = list[1]
+		
+		// преобразовывает в int
+		groupnum, err := strconv.Atoi(groupnum1)
+	  	if err != nil {
+	  	json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error1"})
+	  	fmt.Println(err)
+	  	return
+	 	}
+	 	semesternum, err := strconv.Atoi(semesternum1)
+	  	if err != nil {
+	  	json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error2"})
+	  	fmt.Println(err)
+	  	return
+	 	}
+
+	 	GetCardOfGroup(w, r, groupnum, semesternum)
+	 	return
+	}
+
+	json.NewEncoder(w).Encode(struct{ Error string }{Error: "This method is not supported"})
+}
+
+func GetCardOfGroup(w http.ResponseWriter, r *http.Request,groupnum int ,semesternum int) {
+ 	var semester Semester
+ 	var group Group
+ 	var subjectofgroup []Subjectofgroup
+
+ 	settings.DB.Where("id = ?", semesternum).First(&semester)
+	settings.DB.Where("groupnumber = ?", groupnum).First(&group)
+	settings.DB.Where("id_group = ? AND  id_semester = ?", group.ID, semester.ID).Find(&subjectofgroup)
+
+
+ 	json.NewEncoder(w).Encode(subjectofgroup)
+ 	
+ 	return
+}

+ 1 - 1
api/studyplan.go

@@ -140,7 +140,7 @@ func VariativeHoursByGroup(w http.ResponseWriter, r *http.Request, groupnum int)
 	  for j := range SubjectOfPlan {
 	  	for i := range opop {
 	  		if opop[i].IDSubject == SubjectOfPlan[j].IDSubject {
-	  			Freehours1 :=  SubjectOfPlan[j].Totalhours - opop[i].Hoursquantitytotal
+	  			Freehours1 :=  SubjectOfPlan[j].Hoursquantitytotal - opop[i].Totalhours  
 	  			IDSubject1 := opop[i].IDSubject
 	  			vh = VariateHours{ IDSubject: IDSubject1, Freehours: Freehours1}
 	  			Variatehours= append(Variatehours, vh)

+ 2 - 0
main.go

@@ -82,6 +82,8 @@ func main() {
 	http.HandleFunc("/api/logs", testPage)
 	http.HandleFunc("/api/getteachers", api.GetDataTeachers)
 	http.HandleFunc("/api/getgroups/", api.GetDataGroups)
+	// API Карточки группы
+	http.HandleFunc("/api/cardofgroup/", api.CardOfGroupRoute)
 	// API functions handling end
 
 	// HTTP pages handling start