Skip to content

Commit

Permalink
fix: header cookies design error (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozline authored Jan 5, 2025
1 parent 0f00988 commit d210ada
Show file tree
Hide file tree
Showing 33 changed files with 358 additions and 598 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 辅助工具安装列表
# 执行 go install github.com/cloudwego/hertz/cmd/hz@latest
# 执行 go install github.com/cloudwego/kitex/tool/cmd/kitex@latest
# 执行 go install golang.org/x/tools/cmd/goimports@latest
# 执行 go install golang.org/x/vuln/cmd/govulncheck@latest
# 执行 go install mvdan.cc/gofumpt@latest
# 访问 https://golangci-lint.run/welcome/install/ 以查看安装 golangci-lint 的方法



# 默认输出帮助信息
.DEFAULT_GOAL := help
# 检查 tmux 是否存在
Expand Down
9 changes: 5 additions & 4 deletions api/handler/api/academic_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/handler/api/class_room_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/handler/api/course_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/handler/api/user_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions api/mw/get_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,29 @@ package mw

import (
"context"
"strings"

"github.com/cloudwego/hertz/pkg/app"

"github.com/west2-online/fzuhelper-server/api/model/api"
"github.com/west2-online/fzuhelper-server/api/pack"
"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/pkg/base/login_data"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/logger"
)

// GetHeaderParams 获取请求头的信息,处理 id 和 cookies 并附加到 Context 中
func GetHeaderParams() app.HandlerFunc {
return func(ctx context.Context, c *app.RequestContext) {
id := string(c.GetHeader("Id"))
temp := string(c.GetHeader("Cookies"))
if id == "" || len(temp) == 0 {
logger.Errorf("GetHeaderParams: Id or Cookies is empty")
cookies := string(c.GetHeader("Cookies"))
if id == "" || cookies == "" {
pack.RespError(c, errno.ParamMissingHeader)
c.Abort()
return
}
cookies := strings.Split(temp, ",")
ctx = api.NewContext(ctx, &model.LoginData{
ctx = login_data.NewContext(ctx, &model.LoginData{
Id: id,
Cookies: cookies,
})

c.Next(ctx)
}
}
8 changes: 4 additions & 4 deletions idl/academic.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include "model.thrift"

struct GetScoresRequest {
1: required string id
2: required list<string> cookies
2: required string cookies
}

struct GetScoresResponse {
Expand All @@ -13,7 +13,7 @@ struct GetScoresResponse {

struct GetGPARequest {
1: required string id
2: required list<string> cookies
2: required string cookies
}

struct GetGPAResponse {
Expand All @@ -23,7 +23,7 @@ struct GetGPAResponse {

struct GetCreditRequest {
1: required string id
2: required list<string> cookies
2: required string cookies
}

struct GetCreditResponse {
Expand All @@ -33,7 +33,7 @@ struct GetCreditResponse {

struct GetUnifiedExamRequest {
1: required string id
2: required list<string> cookies
2: required string cookies
}

struct GetUnifiedExamResponse {
Expand Down
86 changes: 38 additions & 48 deletions idl/model.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct BaseResp {

// 由前端给的登陆信息,包括id和cookies, 这个struct仅用于测试返回数据,因为登录实现在前端完成,不会在实际项目中使用
struct LoginData {
1: required string id // 教务处给出的标识,它的组成是时间+学号
2: required list<string> cookies // 登录凭证,访问资源的时候应该必须携带cookies
1: required string id // 教务处给出的标识,它的组成是时间+学号
2: required string cookies // 登录凭证,访问资源的时候应该必须携带cookies
}

// 空教室
Expand All @@ -31,27 +31,27 @@ struct ExamRoomInfo {

// 课程安排
struct CourseScheduleRule {
1: required string location
2: required i64 startClass
3: required i64 endClass
4: required i64 startWeek
5: required i64 endWeek
6: required i64 weekday
7: required bool single
8: required bool double
9: required bool adjust
1: required string location // 定制
2: required i64 startClass // 开始节数
3: required i64 endClass // 结束节数
4: required i64 startWeek // 起始周
5: required i64 endWeek // 结束周
6: required i64 weekday // 星期几
7: required bool single // 单周
8: required bool double // 双周
9: required bool adjust // 是否是调课
}

// 课程信息
struct Course {
1: required string name
2: required string teacher
3: required list<CourseScheduleRule> scheduleRules
4: required string remark
5: required string lessonplan
6: required string syllabus
7: required string rawScheduleRules
8: required string rawAdjust
1: required string name // 课程名称
2: required string teacher // 教师
3: required list<CourseScheduleRule> scheduleRules // 排课规则
4: required string remark // 备注
5: required string lessonplan // 授课计划
6: required string syllabus // 教学大纲
7: required string rawScheduleRules // (原始数据) 排课规则
8: required string rawAdjust // (原始数据) 调课规则
}

// 开屏页
Expand All @@ -74,38 +74,33 @@ struct Picture{
}


/*
* @Description 又拍云文件目录结构
* @Param basePath 当前所在路径
* @Param files 当前所在目录文件
* @Param folders 当前所在目录下的文件夹
*/
// 又拍云文件目录结构
struct UpYunFileDir {
1: optional string basePath,
2: required list<string> files,
3: required list<string> folders,
1: optional string basePath, // 当前所在路径
2: required list<string> files, // 当前所在目录文件
3: required list<string> folders, // 当前所在目录下的文件夹
}

// 课程成绩
struct Score {
1: required string credit
2: required string gpa
3: required string name
4: required string score
5: required string teacher
6: required string term
7: required string year
1: required string credit // 学分
2: required string gpa // 绩点
3: required string name // 课程名
4: required string score // 得分
5: required string teacher // 授课教师
6: required string term // 学期
7: required string year // 开课年份
}
// 绩点排名
struct GPABean {
1: required string time
2: required list<GPAData> data
1: required string time // 更新时间
2: required list<GPAData> data // 数据
}

// 绩点信息
struct GPAData {
1: required string type
2: required string value
1: required string type // 类型(如修读类别或总学分)
2: required string value // 信息(对应的信息)
}

// 学分统计字段
Expand All @@ -121,16 +116,11 @@ struct UnifiedExam {
3: required string term
}

/*
* @Description 又拍云文件目录结构,兼容旧版安卓
* @Param base_path 当前所在路径
* @Param files 当前所在目录文件,使用required保证files不为nil
* @Param folders 当前所在目录下的文件夹,使用required保证folders不为nil
*/
// 又拍云文件目录结构,兼容旧版安卓
struct PaperData {
1: optional string base_path,
2: required list<string> files,
3: required list<string> folders,
1: optional string base_path, // 当前所在路径
2: required list<string> files, // 当前所在目录文件,使用required保证files不为nil
3: required list<string> folders, // 当前所在目录下的文件夹,使用required保证folders不为nil
}

struct PaperUrlData {
Expand Down
16 changes: 0 additions & 16 deletions idl/template.thrift

This file was deleted.

2 changes: 1 addition & 1 deletion internal/academic/service/get_credit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestAcademicService_GetCredit(t *testing.T) {

req := &academic.GetCreditRequest{
Id: "102301517",
Cookies: []string{"cookie1=value1", "cookie2=value2"},
Cookies: "cookie1=value1; cookie2=value2",
}
defer mockey.UnPatchAll()
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion internal/academic/service/get_gpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestAcademicService_GetGPA(t *testing.T) {

req := &academic.GetGPARequest{
Id: "102301517",
Cookies: []string{"cookie1=value1", "cookie2=value2"},
Cookies: "cookie1=value1; cookie2=value2",
}
defer mockey.UnPatchAll()
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion internal/academic/service/get_scores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestAcademicService_GetScores(t *testing.T) {

req := &academic.GetScoresRequest{
Id: "102301517",
Cookies: []string{"cookie1=value1", "cookie2=value2"},
Cookies: "cookie1=value1; cookie2=value2",
}
defer mockey.UnPatchAll()
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion internal/academic/service/get_unified_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestAcademicService_GetUnifiedExam(t *testing.T) {

req := &academic.GetUnifiedExamRequest{
Id: "102301517",
Cookies: []string{"cookie1=value1", "cookie2=value2"},
Cookies: "cookie1=value1; cookie2=value2",
}

defer mockey.UnPatchAll()
Expand Down
2 changes: 1 addition & 1 deletion internal/course/service/get_course_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestCourseService_GetCourseList(t *testing.T) {

mockLoginData := &model.LoginData{
Id: "102301517",
Cookies: []string{"cookie1=value1", "cookie2=value2"},
Cookies: "cookie1=value1; cookie2=value2",
}
req := &course.CourseListRequest{
LoginData: mockLoginData,
Expand Down
Loading

0 comments on commit d210ada

Please sign in to comment.