完成课程资源
This commit is contained in:
@@ -6,6 +6,8 @@ package course_resource
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
|
||||
@@ -18,10 +20,18 @@ import (
|
||||
func DeleteCourseResourceHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeleteCourseResourceReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
pathParts := strings.Split(r.URL.Path, "/")
|
||||
if len(pathParts) < 3 { // 确保路径格式正确
|
||||
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||
return
|
||||
}
|
||||
idStr := pathParts[3]
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID"))
|
||||
return
|
||||
}
|
||||
req.Id = int(id)
|
||||
|
||||
mysqlCfg := cfg.MySQL
|
||||
dsn := fmt.Sprintf(
|
||||
|
||||
@@ -6,6 +6,8 @@ package course_resource
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
|
||||
@@ -18,10 +20,19 @@ import (
|
||||
func GetCourseResourceHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetCourseResourceReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
pathParts := strings.Split(r.URL.Path, "/")
|
||||
fmt.Println(pathParts)
|
||||
if len(pathParts) < 3 { // 确保路径格式正确
|
||||
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||
return
|
||||
}
|
||||
idStr := pathParts[3]
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID"))
|
||||
return
|
||||
}
|
||||
req.Id = int(id)
|
||||
|
||||
mysqlCfg := cfg.MySQL
|
||||
dsn := fmt.Sprintf(
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
package types
|
||||
|
||||
type CreateCourseResourceReq struct {
|
||||
CourseId int `json:"course_id" form:"course_id" validate:"required"`
|
||||
Title string `json:"title" form:"title" validate:"required,max=255"`
|
||||
ResourceUrl string `json:"resource_url" form:"resource_url" validate:"required,max=512"`
|
||||
Size int `json:"size" form:"size" validate:"omitempty,min=0"`
|
||||
Sort int `json:"sort" form:"sort" validate:"omitempty,min=0"`
|
||||
CourseId int `json:"course_id" validate:"required"`
|
||||
Title string `json:"title" validate:"required,max=255"`
|
||||
ResourceUrl string `json:"resource_url" validate:"required,max=512"`
|
||||
Size int `json:"size" validate:"omitempty,min=0"`
|
||||
Sort int `json:"sort" validate:"omitempty,min=0"`
|
||||
}
|
||||
|
||||
type CreateCourseResourceResp struct {
|
||||
@@ -38,9 +38,9 @@ type GetCourseResourceResp struct {
|
||||
}
|
||||
|
||||
type ListCourseResourceReq struct {
|
||||
CourseId int `form:"course_id" validate:"omitempty"`
|
||||
Page int `form:"page" validate:"required,min=1"`
|
||||
PageSize int `form:"page_size" validate:"required,min=1,max=100"`
|
||||
CourseId int `json:"course_id" validate:"omitempty"`
|
||||
Page int `json:"page" validate:"required,min=1"`
|
||||
PageSize int `json:"page_size" validate:"required,min=1,max=100"`
|
||||
}
|
||||
|
||||
type ListCourseResourceResp struct {
|
||||
|
||||
Reference in New Issue
Block a user