Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
refactor: 文件结构更新,删除无关接口,增加批量添加Todo接口
Browse files Browse the repository at this point in the history
  • Loading branch information
meowrain committed Oct 2, 2024
1 parent cddd7ff commit c7ab6b1
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 406 deletions.
File renamed without changes.
42 changes: 0 additions & 42 deletions app/api/controller/feedBackHandler/feedBackHandler.go

This file was deleted.

103 changes: 0 additions & 103 deletions app/api/controller/todoHandler/todo_handler.go

This file was deleted.

16 changes: 0 additions & 16 deletions app/api/routes/feedback_routes.go

This file was deleted.

37 changes: 0 additions & 37 deletions app/api/routes/todo_routes.go

This file was deleted.

36 changes: 0 additions & 36 deletions app/api/service/feedBackService/feedBackService.go

This file was deleted.

86 changes: 0 additions & 86 deletions app/api/service/todoService/todo_service.go

This file was deleted.

38 changes: 38 additions & 0 deletions app/api/todo/controller/todo_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package controller

import (
"github.com/gin-gonic/gin"
"net/http"
"todoBackend/app/api/todo/models"
"todoBackend/app/api/todo/service"
"todoBackend/utils/jwts"
. "todoBackend/utils/responses"
)

func AddAllTodo(c *gin.Context) {
userId, err := jwts.ExtractTokenID(c)
if err != nil {
c.JSON(http.StatusBadRequest, ErrorResponse(err, "ExtractTokenID failed"))
return
}
var todoList []models.TodoRequest
if err := c.ShouldBindJSON(&todoList); err != nil {
c.JSON(http.StatusBadRequest, ErrorResponse(err, "error"))
return
}
if err := service.AddAllTodo(todoList, userId); err != nil {
c.JSON(http.StatusBadRequest, ErrorResponse(err, "service error"))
}
c.JSON(http.StatusOK, SuccessResponse(todoList, "Add success!"))

}

// GetAllTodo 获取所有todo
func GetAllTodo(c *gin.Context) {
userId, err := jwts.ExtractTokenID(c)
todos, err := service.GetAllTodo(userId)
if err != nil {
c.JSON(http.StatusBadRequest, ErrorResponse(err, "获取全部todo失败"))
}
c.JSON(http.StatusOK, SuccessResponse(todos, "get successfully!"))
}
16 changes: 16 additions & 0 deletions app/api/todo/models/todo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package models

import (
"gorm.io/gorm"
"todoBackend/app/api/user/models"
)

// Todo 结构表示了一个任务
type Todo struct {
gorm.Model // gorm 提供的基本 model 结构
Content string `json:"content"` // 任务内容
Completed bool `json:"completed"` // 任务状态
UserID uint `json:"user_id"` // 用户ID
Tag string `json:"tag"` // 任务标签
User models.User `gorm:"foreignKey:UserID;references:ID"` // 外键关联
}
7 changes: 7 additions & 0 deletions app/api/todo/models/todo_req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

type TodoRequest struct {
Content string `json:"content"`
Completed bool `json:"completed"`
Tag string `json:"tag"`
}
Loading

0 comments on commit c7ab6b1

Please sign in to comment.