Skip to content

Commit 117ca96

Browse files
committed
feat(api): 完善网关层
1 parent 876bd37 commit 117ca96

7 files changed

Lines changed: 342 additions & 6 deletions

File tree

api/handler/api/course_service.go

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/model/api/api.go

Lines changed: 141 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pack/course.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ limitations under the License.
1717
package pack
1818

1919
import (
20+
api "github.com/west2-online/fzuhelper-server/api/model/api"
2021
courseModel "github.com/west2-online/fzuhelper-server/api/model/model"
22+
courseKitex "github.com/west2-online/fzuhelper-server/kitex_gen/course"
2123
"github.com/west2-online/fzuhelper-server/kitex_gen/model"
2224
)
2325

@@ -117,3 +119,58 @@ func BuildAdjustCourseList(res []*model.AdjustCourse) []*courseModel.AdjustCours
117119
}
118120
return list
119121
}
122+
123+
// 自定义课程:kitex 模型 -> 网关模型
124+
func BuildCustomCourseItem(res *courseKitex.CustomCourseItem) *api.CustomCourseItem {
125+
if res == nil {
126+
return nil
127+
}
128+
return &api.CustomCourseItem{
129+
Id: res.Id,
130+
Name: res.Name,
131+
Teacher: res.Teacher,
132+
Location: res.Location,
133+
StartClass: res.StartClass,
134+
EndClass: res.EndClass,
135+
StartWeek: res.StartWeek,
136+
EndWeek: res.EndWeek,
137+
Weekday: res.Weekday,
138+
Single: res.Single,
139+
Double_: res.Double_,
140+
Color: res.Color,
141+
Remark: res.Remark,
142+
}
143+
}
144+
145+
func BuildCustomCourseItemList(res []*courseKitex.CustomCourseItem) []*api.CustomCourseItem {
146+
list := make([]*api.CustomCourseItem, 0, len(res))
147+
for _, v := range res {
148+
c := BuildCustomCourseItem(v)
149+
if c != nil {
150+
list = append(list, c)
151+
}
152+
}
153+
return list
154+
}
155+
156+
// 自定义课程:网关模型 -> kitex 模型(发给 RPC)
157+
func BuildCustomCourseItemForRPC(res *api.CustomCourseItem) *courseKitex.CustomCourseItem {
158+
if res == nil {
159+
return nil
160+
}
161+
return &courseKitex.CustomCourseItem{
162+
Id: res.Id,
163+
Name: res.Name,
164+
Teacher: res.Teacher,
165+
Location: res.Location,
166+
StartClass: res.StartClass,
167+
EndClass: res.EndClass,
168+
StartWeek: res.StartWeek,
169+
EndWeek: res.EndWeek,
170+
Weekday: res.Weekday,
171+
Single: res.Single,
172+
Double_: res.Double_,
173+
Color: res.Color,
174+
Remark: res.Remark,
175+
}
176+
}

api/router/api/api.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/router/api/middleware.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/rpc/course.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func InitCourseRPC() {
3535
courseClient = *c
3636
}
3737

38-
func GetCourseListRPC(ctx context.Context, req *course.CourseListRequest) (courses []*model.Course, err error) {
38+
func GetCourseListRPC(ctx context.Context, req *course.CourseListRequest) (*course.CourseListResponse, error) {
3939
resp, err := courseClient.GetCourseList(ctx, req)
4040
if err != nil {
4141
logger.WithCtx(ctx).Errorf("GetCourseListRPC: RPC called failed: %v", err.Error())
@@ -45,7 +45,7 @@ func GetCourseListRPC(ctx context.Context, req *course.CourseListRequest) (cours
4545
return nil, err
4646
}
4747

48-
return resp.Data, nil
48+
return resp, nil
4949
}
5050

5151
func GetCourseTermsListRPC(ctx context.Context, req *course.TermListRequest) (*course.TermListResponse, error) {
@@ -121,3 +121,27 @@ func UpdateAutoAdjustCourseRPC(ctx context.Context, req *course.UpdateAdjustCour
121121
}
122122
return nil
123123
}
124+
125+
func UpsertCustomCourseRPC(ctx context.Context, req *course.UpsertCustomCourseRequest) (*course.UpsertCustomCourseResponse, error) {
126+
resp, err := courseClient.UpsertCustomCourse(ctx, req)
127+
if err != nil {
128+
logger.WithCtx(ctx).Errorf("UpsertCustomCourseRPC: RPC called failed: %v", err.Error())
129+
return nil, errno.InternalServiceError.WithMessage(err.Error())
130+
}
131+
if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil {
132+
return nil, errno.BizError.WithMessage("保存自定义课程失败: " + resp.Base.Msg)
133+
}
134+
return resp, nil
135+
}
136+
137+
func DeleteCustomCourseRPC(ctx context.Context, req *course.DeleteCustomCourseRequest) error {
138+
resp, err := courseClient.DeleteCustomCourse(ctx, req)
139+
if err != nil {
140+
logger.WithCtx(ctx).Errorf("DeleteCustomCourseRPC: RPC called failed: %v", err.Error())
141+
return errno.InternalServiceError.WithMessage(err.Error())
142+
}
143+
if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil {
144+
return errno.BizError.WithMessage("删除自定义课程失败: " + resp.Base.Msg)
145+
}
146+
return nil
147+
}

0 commit comments

Comments
 (0)