Skip to content

Commit

Permalink
feat: handle review
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasyRL committed Jan 11, 2025
1 parent 59fad77 commit dbc5124
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
7 changes: 3 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.

12 changes: 6 additions & 6 deletions api/handler/api/user_service.go

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

8 changes: 4 additions & 4 deletions internal/academic/service/get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package service

import (
"bytes"
"fmt"
"net/http"

"github.com/west2-online/fzuhelper-server/kitex_gen/academic"
"github.com/west2-online/fzuhelper-server/pkg/constants"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/utils"
"github.com/west2-online/jwch"
)
Expand All @@ -31,17 +31,17 @@ func (s *AcademicService) GetPlan(req *academic.GetPlanRequest) (*[]byte, error)
stu := jwch.NewStudent().WithLoginData(req.Id, utils.ParseCookies(req.Cookies))
url, err := stu.GetCultivatePlan()
if err != nil {
return nil, fmt.Errorf("AcademicService.GetPlan error:%w", err)
return nil, errno.Errorf(errno.InternalServiceErrorCode, "AcademicService.GetPlan error:%v", err)
}

urlReq, err := http.NewRequest(constants.GetPlanMethod, url, nil)
if err != nil {
return nil, fmt.Errorf("AcademicService.GetPlan request error:%w", err)
return nil, errno.Errorf(errno.InternalServiceErrorCode, "AcademicService.GetPlan request error:%v", err)
}
urlReq.Header.Set("Cookie", req.Cookies)
htmlSource, err := getHtmlSource(urlReq)
if err != nil {
return nil, fmt.Errorf("AcademicService.GetPlan getHtmlSource error:%w", err)
return nil, errno.Errorf(errno.InternalServiceErrorCode, "AcademicService.GetPlan getHtmlSource error:%v", err)
}

return htmlSource, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/user/service/get_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strconv"

db "github.com/west2-online/fzuhelper-server/pkg/db/model"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/jwch"
)

Expand All @@ -38,7 +39,7 @@ func (s *UserService) GetUserInfo(stuId string) (*db.Student, error) {
stu := jwch.NewStudent().WithLoginData(s.Identifier, s.cookies)
resp, err := stu.GetInfo()
if err != nil {
return nil, fmt.Errorf("service.GetUserInfo: jwch failed: %w", err)
return nil, errno.Errorf(errno.InternalServiceErrorCode, "service.GetUserInfo: jwch failed: %v", err)
}
grade, _ := strconv.Atoi(resp.Grade)
userModel := &db.Student{
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/user/create_student.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package user

import (
"context"
"fmt"

"github.com/west2-online/fzuhelper-server/pkg/db/model"
"github.com/west2-online/fzuhelper-server/pkg/errno"
)

func (c *DBUser) CreateStudent(ctx context.Context, userModel *model.Student) error {
if err := c.client.WithContext(ctx).Create(&userModel).Error; err != nil {
return fmt.Errorf("dal.CreateStudent error: %w", err)
return errno.Errorf(errno.InternalDatabaseErrorCode, "dal.CreateStudent error: %v", err)
}
return nil
}
4 changes: 2 additions & 2 deletions pkg/db/user/get_student.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package user
import (
"context"
"errors"
"fmt"

"gorm.io/gorm"

"github.com/west2-online/fzuhelper-server/pkg/db/model"
"github.com/west2-online/fzuhelper-server/pkg/errno"
)

func (c *DBUser) GetStudentById(ctx context.Context, stuId string) (bool, *model.Student, error) {
Expand All @@ -32,7 +32,7 @@ func (c *DBUser) GetStudentById(ctx context.Context, stuId string) (bool, *model
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil, nil
}
return false, nil, fmt.Errorf("dal.GetStudentById error:%w", err)
return false, nil, errno.Errorf(errno.InternalDatabaseErrorCode, "dal.GetStudentById error:%v", err)
}
return true, stuModel, nil
}

0 comments on commit dbc5124

Please sign in to comment.