Skip to content

Commit

Permalink
fix: fix issues mentioned by code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayanami1314 committed Aug 11, 2024
1 parent fb872aa commit 778d27c
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 178 deletions.
4 changes: 2 additions & 2 deletions cmd/load/extend_teacher_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
if len(teachers) == 1 {
teachers[0].Email = t.Mail
teachers[0].ProfileURL = t.ProfileUrl
teachers[0].ProfileDesc = t.ProfileDescription
teachers[0].Biography = t.Biography
teachers[0].Picture = t.HeadImage
db.Save(&teachers[0])
continue
Expand All @@ -43,7 +43,7 @@ func main() {
if tt.Department == t.Department {
tt.Email = t.Mail
tt.ProfileURL = t.ProfileUrl
tt.ProfileDesc = t.ProfileDescription
tt.Biography = t.Biography
tt.Picture = t.HeadImage
db.Save(&tt)
confirm = true
Expand Down
5 changes: 2 additions & 3 deletions cmd/load/extend_training_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
Department: tp.Department,
EntryYear: strconv.Itoa(tp.EntryYear),
TotalYear: tp.TotalYear,
MinPoints: tp.MinPoints,
MinCredits: tp.MinCredits,
MajorCode: tp.Code,
MajorClass: tp.MajorClass,
}
Expand All @@ -63,8 +63,7 @@ func main() {
tpc_po := po.TrainingPlanCoursePO{
TrainingPlanID: int64(tp_po.ID),
CourseID: int64(course.ID),
SuggestYear: int64(c.SuggestYear),
SuggestSemester: int64(c.SuggestSemester),
SuggestSemester: c.SuggestSemester,
Department: c.Department,
}
cresult = db.Model(po.TrainingPlanCoursePO{}).Create(&tpc_po)
Expand Down
2 changes: 1 addition & 1 deletion handler/teacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSearchTeacherListHandler(t *testing.T) {
}{
"valid-multi-req": {"name=古金宇&page=1&page_size=3", http.StatusOK},
"valid-single-req": {"name=古金宇&department=电子信息与电气工程学院&page=1&page_size=3", http.StatusOK},
"invalid-value-req": {"name=你谁", http.StatusBadRequest},
"invalid-value-req": {"name=你谁", http.StatusOK},
"invalid-page-req": {"page=-1&page_size=10086", http.StatusOK},
"overflow-page-req": {"page=10086&page_size=1", http.StatusOK},
"invalid-key-req": {"hello=1", http.StatusBadRequest},
Expand Down
2 changes: 1 addition & 1 deletion model/converter/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func ConvertTrainingPlanPOToDomain(trainingPlan po.TrainingPlanPO) domain.Traini
EntryYear: trainingPlan.EntryYear,
MajorCode: trainingPlan.MajorCode,
MajorClass: trainingPlan.MajorClass,
MinPoints: trainingPlan.MinPoints,
MinCredits: trainingPlan.MinCredits,
TotalYear: int(trainingPlan.TotalYear),
}
}
2 changes: 1 addition & 1 deletion model/converter/teacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ConvertTeacherPOToDomain(teacher *po.TeacherPO) *domain.Teacher {
Title: teacher.Title,
Picture: teacher.Picture,
ProfileURL: teacher.ProfileURL,
ProfileDesc: teacher.ProfileDesc,
ProfileDesc: teacher.Biography,
}
}

Expand Down
4 changes: 1 addition & 3 deletions model/converter/trainingplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func ConvertTrainingPlanCourseDomainToDTO(courseDomain domain.TrainingPlanCourse
Name: courseDomain.Name,
Code: courseDomain.Code,
Credit: courseDomain.Credit,
SuggestYear: courseDomain.SuggestYear,
SuggestSemester: courseDomain.SuggestSemester,
}
}
Expand All @@ -31,7 +30,7 @@ func ConvertTrainingPlanDomainToDTO(domain domain.TrainingPlanDetail) dto.Traini
Department: domain.Department,
EntryYear: int64(entryYear),
MajorName: domain.Major,
MinPoints: domain.MinPoints,
MinCredits: domain.MinCredits,
MajorClass: domain.MajorClass,
TotalYear: int64(domain.TotalYear),
Courses: courses,
Expand All @@ -52,7 +51,6 @@ func ConvertTrainingPlanCoursePOToDomain(coursePO po.TrainingPlanCoursePO, baseC
Name: baseCoursePO.Name,
Credit: baseCoursePO.Credit,
SuggestSemester: coursePO.SuggestSemester,
SuggestYear: coursePO.SuggestYear,
Department: coursePO.Department,
}
}
20 changes: 4 additions & 16 deletions model/domain/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ type TrainingPlan struct {
type TrainingPlanDetail struct {
ID int64
Major string
Department string
EntryYear string
MajorCode string
MajorClass string
MinPoints float64
Department string
EntryYear string
MinCredits float64
TotalYear int
Courses []TrainingPlanCourse
}
Expand All @@ -54,21 +54,9 @@ type TrainingPlanCourse struct {
Code string
Name string
Credit float64
SuggestYear int64
SuggestSemester int64
SuggestSemester string
Department string
}
type TrainingPlanRateInfo struct {
Avg float64
Count int64
TrainingPlanID int64
Rates []TrainingPlanRate
}
type TrainingPlanRate struct {
TrainingPlanID int64
UserID int64
Rate int64
}

type TrainingPlanFilter struct {
Page int64
Expand Down
6 changes: 2 additions & 4 deletions model/dto/trainingplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ type TrainingPlanCourseDTO struct {
Code string `json:"code"`
Name string `json:"name"`
Credit float64 `json:"credit"`
SuggestYear int64 `json:"suggest_year"`
SuggestSemester int64 `json:"suggest_semester"`
SuggestSemester string `json:"suggest_semester"`
Department string `json:"department"`
}

type TrainingPlanListItemDTO struct {
ID int64 `json:"id"`
Code string `json:"code"`
MajorName string `json:"name"`
MinPoints float64 `json:"min_points"`
MinCredits float64 `json:"min_credits"`
MajorClass string `json:"major_class"`
EntryYear int64 `json:"entry_year"`
Department string `json:"department"`
TotalYear int64 `json:"total_year"`
Grade float32 `json:"grade"`
Degree string `json:"degree"`
Courses []TrainingPlanCourseDTO `json:"courses"`
}
Expand Down
8 changes: 3 additions & 5 deletions model/po/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type TrainingPlanPO struct {
EntryYear string `gorm:"index;index:uniq_training_plan,unique"` //==Grade,年级
MajorCode string `gorm:"index;index:uniq_training_plan,unique"`
TotalYear int `gorm:"index;index:uniq_training_plan,unique"`
MinPoints float64 `gorm:"index;index:uniq_training_plan,unique"`
MinCredits float64 `gorm:"index;index:uniq_training_plan,unique"`
MajorClass string `gorm:"index;index:uniq_training_plan,unique"` // 专业类
}

Expand All @@ -84,10 +84,8 @@ type TrainingPlanCoursePO struct {
gorm.Model
CourseID int64 `gorm:"index;index:uniq_training_plan_course,unique"`
TrainingPlanID int64 `gorm:"index;index:uniq_training_plan_course,unique"`
//SuggestTime string `gorm:"index;index:uniq_training_plan_course,unique"`
// 推荐修读时间:学年+学期,如 2023-2024-2
SuggestYear int64 `gorm:"index;index:uniq_training_plan_course,unique"`
SuggestSemester int64 `gorm:"index;index:uniq_training_plan_course,unique"`
// SuggestSemester:学年+学期,如 2023-2024-2
SuggestSemester string `gorm:"index;index:uniq_training_plan_course,unique"`
Department string `gorm:"index;"`
}

Expand Down
20 changes: 10 additions & 10 deletions model/po/teacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import "gorm.io/gorm"

type TeacherPO struct {
gorm.Model
Name string `gorm:"index"`
Code string `gorm:"index:,unique"`
Email string `gorm:"index"`
Department string `gorm:"index"`
Title string
Pinyin string `gorm:"index"`
PinyinAbbr string `gorm:"index"`
Picture string // picture URL
ProfileURL string
ProfileDesc string
Name string `gorm:"index"`
Code string `gorm:"index:,unique"`
Email string `gorm:"index"`
Department string `gorm:"index"`
Title string
Pinyin string `gorm:"index"`
PinyinAbbr string `gorm:"index"`
Picture string // picture URL
ProfileURL string
Biography string // 个人简述
}

func (po *TeacherPO) TableName() string {
Expand Down
10 changes: 2 additions & 8 deletions repository/trainingplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,11 @@ type ITrainingPlanCourseQuery interface {
WithTrainingPlanID(trainingPlanID int64) DBOption
WithCourseID(courseID int64) DBOption
WithCourseIDs(courseIDs []int64) DBOption
WithSuggestSemester(semester int64) DBOption
WithSuggestYear(year int64) DBOption
WithSuggestSemester(semester string) DBOption
WithDepartment(department string) DBOption
}

func (t *TrainingPlanCourseQuery) WithSuggestYear(year int64) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("suggest_year = ?", year)
}
}
func (t *TrainingPlanCourseQuery) WithSuggestSemester(semester int64) DBOption {
func (t *TrainingPlanCourseQuery) WithSuggestSemester(semester string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("suggest_semester = ?", semester)
}
Expand Down
2 changes: 1 addition & 1 deletion service/trainingplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func SearchTrainingPlanList(ctx context.Context, filter domain.TrainingPlanFilte

func GetTrainingPlanListByIDs(ctx context.Context, trainingPlanIDs []int64) (map[int64]domain.TrainingPlanDetail, error) {

domainTrainingPlans := make(map[int64]domain.TrainingPlanDetail, 0)
domainTrainingPlans := make(map[int64]domain.TrainingPlanDetail)
for _, id := range trainingPlanIDs {
data, err := GetTrainingPlanDetail(ctx, id)
if err != nil {
Expand Down
53 changes: 53 additions & 0 deletions util/selenium-get/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import requests
from typing import Callable
from selenium.webdriver.common.by import By
from argparse import ArgumentParser
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
class Automator:
timeout = 60
def __init__(self, description:str="") -> None:
# automate downloading chrome driver if
# 1.you haven't installed chrome
# 2.imcompatible with your browser
service = Service()
options = webdriver.ChromeOptions()
self.driver = webdriver.Chrome(service=service, options=options)
self.parser = ArgumentParser(description=description)
self.parser.add_argument("-n", "--name", type=str, action="store", help="jacount for login")
self.parser.add_argument("-p", "--password", type=str, action="store", help="password for login")
self.parser.add_argument("-d","--debug", action="store_true", help="In debug mode, the program will not save the result.")
self.parser.add_argument("-v", "--verbose", action="store_true", help="Verbose mode")
self.has_login = False
def login(self, name:str, password:str):
login_url = "https://i.sjtu.edu.cn/jaccountlogin"
self.driver.implicitly_wait(time_to_wait=self.timeout)
self.driver.get(url=login_url)
username_input = self.driver.find_element(By.ID, "input-login-user")
password_input = self.driver.find_element(By.ID, "input-login-pass")
username_input.send_keys("{}".format(name))
password_input.send_keys("{}".format(password))
# driver -> bool
cond:Callable[[object], bool] = EC.url_contains("https://i.sjtu.edu.cn/xtgl")
WebDriverWait(self.driver, self.timeout).until(cond)
session = requests.Session()
# 获取登录后的 Cookie
cookies = self.driver.get_cookies()

# 将 Cookie 转换为 requests 库可以使用的格式
for cookie in cookies:
session.cookies.set(cookie['name'], cookie['value'])
self.session = session
self.has_login = True
def gen_driver(self):
return self.driver

def end(self):
self.driver.close()

def get_session(self):
if not self.login:
raise Exception("Please login first")
return self.session
Loading

0 comments on commit 778d27c

Please sign in to comment.