diff options
-rw-r--r-- | courses.go | 6 | ||||
-rw-r--r-- | docs/courses_example.csv | 28 | ||||
-rw-r--r-- | endpoint_export.go | 4 | ||||
-rw-r--r-- | endpoint_newcourses.go | 23 | ||||
-rw-r--r-- | sql/schema.sql | 4 |
5 files changed, 44 insertions, 21 deletions
@@ -47,6 +47,8 @@ type courseT struct { Group string Teacher string Location string + CourseID string + SectionID string Usems sync.Map /* string, *usemT */ } @@ -63,7 +65,7 @@ const staffDepartment = "Staff" func setupCourses(ctx context.Context) error { rows, err := db.Query( ctx, - "SELECT id, nmax, title, ctype, cgroup, teacher, location FROM courses", + "SELECT id, nmax, title, ctype, cgroup, teacher, location, course_id, section_id FROM courses", ) if err != nil { return wrapError(errUnexpectedDBError, err) @@ -89,6 +91,8 @@ func setupCourses(ctx context.Context) error { ¤tCourse.Group, ¤tCourse.Teacher, ¤tCourse.Location, + ¤tCourse.CourseID, + ¤tCourse.SectionID, ) if err != nil { return wrapError(errUnexpectedDBError, err) diff --git a/docs/courses_example.csv b/docs/courses_example.csv index 271d41f..89b4f33 100644 --- a/docs/courses_example.csv +++ b/docs/courses_example.csv @@ -1,14 +1,14 @@ -Title,Max,Teacher,Location,Type,Group -Floorball,65535,Chen Xiaojia,Gym,Sport,MW3 -Fakeball,65535,Foo Bar,Gym,Sport,MW1 -Chamber Music,65535,Bar Baz,Music Rooms,Non-sport,MW1 -Programming Club,65535,Foo Baz,Library,Non-sport,MW1 -Flag Football,65535,Ding Zhaoyuan,Pitch,Sport,MW2 -Table Tennis,65535,Somebody,Table Tennis Room,Sport,MW2 -Spinning,65535,Somebody,Spinning Room,Sport,MW2 -Some Music,65535,Eeeee,Music Rooms,Non-sport,TT1 -Some More Music,65535,Eeeee,Music Rooms,Non-sport,TT1 -Math and Computer Science,65535,Jeff Zhang,2307,Non-sport,TT2 -Basketball,65535,Somebody,Gym,Sport,TT2 -Chinese Drama,65535,Monica Chen (?),Black Box (?),Non-sport,TT2 -Actually Flag Football,30,Hmm,Pitch,Sport,TT3 +Title,Max,Teacher,Location,Type,Group,Section ID,Course ID +Floorball,65535,Chen Xiaojia,Gym,Sport,MW3,FL,FL +Fakeball,65535,Foo Bar,Gym,Sport,MW1,FK,FK +Chamber Music,65535,Bar Baz,Music Rooms,Non-sport,MW1,CM,CM +Programming Club,65535,Foo Baz,Library,Non-sport,MW1,PC,PC +Flag Football,65535,Ding Zhaoyuan,Pitch,Sport,MW2,FF,FF +Table Tennis,65535,Somebody,Table Tennis Room,Sport,MW2,TT,TT +Spinning,65535,Somebody,Spinning Room,Sport,MW2,SP,SP +Some Music,65535,Eeeee,Music Rooms,Non-sport,TT1,SM,SM +Some More Music,65535,Eeeee,Music Rooms,Non-sport,TT1,SMM,SMM +Math and Computer Science,65535,Jeff Zhang,2307,Non-sport,TT2,MC,MC +Basketball,65535,Somebody,Gym,Sport,TT2,BB,BB +Chinese Drama,65535,Monica Chen (?),Black Box (?),Non-sport,TT2,CD,CD +Actually Flag Football,30,Hmm,Pitch,Sport,TT3,AFF,AFF diff --git a/endpoint_export.go b/endpoint_export.go index 3f55a00..cf824bb 100644 --- a/endpoint_export.go +++ b/endpoint_export.go @@ -152,6 +152,8 @@ func handleExport(w http.ResponseWriter, req *http.Request) { currentDepartment, course.Title, course.Group, + course.SectionID, + course.CourseID, }, ) } @@ -165,6 +167,8 @@ func handleExport(w http.ResponseWriter, req *http.Request) { "Grade/Year", "Group/Activity", "Container", + "Section ID", + "Course ID", }) if err != nil { wstr( diff --git a/endpoint_newcourses.go b/endpoint_newcourses.go index d00c3e9..9f26b73 100644 --- a/endpoint_newcourses.go +++ b/endpoint_newcourses.go @@ -104,16 +104,17 @@ func handleNewCourses(w http.ResponseWriter, req *http.Request) { ) return } - if len(titleLine) != 6 { + if len(titleLine) != 8 { wstr( w, http.StatusBadRequest, - "First line has more than 6 elements", + "First line has more than 8 elements", ) return } var titleIndex, maxIndex, teacherIndex, locationIndex, - typeIndex, groupIndex int = -1, -1, -1, -1, -1, -1 + typeIndex, groupIndex, sectionIDIndex, + courseIDIndex int = -1, -1, -1, -1, -1, -1, -1, -1 for i, v := range titleLine { switch v { case "Title": @@ -128,6 +129,10 @@ func handleNewCourses(w http.ResponseWriter, req *http.Request) { typeIndex = i case "Group": groupIndex = i + case "Section ID": + sectionIDIndex = i + case "Course ID": + courseIDIndex = i } } @@ -165,6 +170,12 @@ func handleNewCourses(w http.ResponseWriter, req *http.Request) { if check("Group", groupIndex) { return } + if check("Course ID", courseIDIndex) { + return + } + if check("Section ID", sectionIDIndex) { + return + } } lineNumber := 1 @@ -233,7 +244,7 @@ func handleNewCourses(w http.ResponseWriter, req *http.Request) { ) return false } - if len(line) != 6 { + if len(line) != 8 { wstr( w, http.StatusBadRequest, @@ -272,13 +283,15 @@ func handleNewCourses(w http.ResponseWriter, req *http.Request) { } _, err = tx.Exec( ctx, - "INSERT INTO courses(nmax, title, teacher, location, ctype, cgroup) VALUES ($1, $2, $3, $4, $5, $6)", + "INSERT INTO courses(nmax, title, teacher, location, ctype, cgroup, section_id, course_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", line[maxIndex], line[titleIndex], line[teacherIndex], line[locationIndex], line[typeIndex], line[groupIndex], + line[sectionIDIndex], + line[courseIDIndex], ) if err != nil { wstr( diff --git a/sql/schema.sql b/sql/schema.sql index ee69906..c888768 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -5,7 +5,9 @@ CREATE TABLE courses ( teacher TEXT NOT NULL, location TEXT NOT NULL, ctype TEXT NOT NULL, - cgroup TEXT NOT NULL + cgroup TEXT NOT NULL, + course_id TEXT NOT NULL, + section_id TEXT NOT NULL ); CREATE TABLE users ( id TEXT PRIMARY KEY NOT NULL, -- should be UUID |