完成教学案例和视频案例后端
This commit is contained in:
@@ -6,6 +6,8 @@ package teaching_case
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case"
|
"github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case"
|
||||||
@@ -18,10 +20,19 @@ import (
|
|||||||
func DeleteTeachingCaseHandler(cfg *config.Config) http.HandlerFunc {
|
func DeleteTeachingCaseHandler(cfg *config.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeleteTeachingCaseReq
|
var req types.DeleteTeachingCaseReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
pathParts := strings.Split(r.URL.Path, "/")
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
if len(pathParts) < 3 { // 确保路径格式正确
|
||||||
|
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
fmt.Println("idStr:", idStr)
|
||||||
|
req.Id = int(id)
|
||||||
|
|
||||||
mysqlCfg := cfg.MySQL
|
mysqlCfg := cfg.MySQL
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package teaching_case
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case"
|
"github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case"
|
||||||
@@ -18,10 +20,19 @@ import (
|
|||||||
func GetTeachingCaseHandler(cfg *config.Config) http.HandlerFunc {
|
func GetTeachingCaseHandler(cfg *config.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.GetTeachingCaseReq
|
var req types.GetTeachingCaseReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
pathParts := strings.Split(r.URL.Path, "/")
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
if len(pathParts) < 3 { // 确保路径格式正确
|
||||||
|
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
fmt.Println("idStr:", idStr)
|
||||||
|
req.Id = int(id)
|
||||||
|
|
||||||
mysqlCfg := cfg.MySQL
|
mysqlCfg := cfg.MySQL
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type UpdateTeachingCaseLogic struct {
|
|||||||
func NewUpdateTeachingCaseLogic(ctx context.Context, cfg *config.Config, model model.TeachingCaseModel) *UpdateTeachingCaseLogic {
|
func NewUpdateTeachingCaseLogic(ctx context.Context, cfg *config.Config, model model.TeachingCaseModel) *UpdateTeachingCaseLogic {
|
||||||
return &UpdateTeachingCaseLogic{
|
return &UpdateTeachingCaseLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
model: model,
|
model: model,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type DeleteTeachingCaseReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetTeachingCaseReq struct {
|
type GetTeachingCaseReq struct {
|
||||||
Id int `json:"id" validate:"required" uri:"id"` // 案例ID
|
Id int `json:"id" path:"id" validate:"required" uri:"id"` // 案例ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListTeachingCaseReq struct {
|
type ListTeachingCaseReq struct {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package video_case
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case"
|
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case"
|
||||||
@@ -18,10 +20,19 @@ import (
|
|||||||
func DeleteVideoCaseHandler(cfg *config.Config) http.HandlerFunc {
|
func DeleteVideoCaseHandler(cfg *config.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeleteVideoCaseReq
|
var req types.DeleteVideoCaseReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
pathParts := strings.Split(r.URL.Path, "/")
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
if len(pathParts) < 3 { // 确保路径格式正确
|
||||||
|
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
fmt.Println("idStr:", idStr)
|
||||||
|
req.Id = int(id)
|
||||||
|
|
||||||
mysqlCfg := cfg.MySQL
|
mysqlCfg := cfg.MySQL
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package video_case
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||||
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case"
|
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case"
|
||||||
@@ -18,10 +20,19 @@ import (
|
|||||||
func GetVideoCaseHandler(cfg *config.Config) http.HandlerFunc {
|
func GetVideoCaseHandler(cfg *config.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.GetVideoCaseReq
|
var req types.GetVideoCaseReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
pathParts := strings.Split(r.URL.Path, "/")
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
if len(pathParts) < 3 { // 确保路径格式正确
|
||||||
|
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
fmt.Println("idStr:", idStr)
|
||||||
|
req.Id = int(id)
|
||||||
|
|
||||||
mysqlCfg := cfg.MySQL
|
mysqlCfg := cfg.MySQL
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
|
|||||||
Reference in New Issue
Block a user