This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 文件结构更新,删除无关接口,增加批量添加Todo接口
- Loading branch information
Showing
24 changed files
with
177 additions
and
406 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` // 外键关联 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
Oops, something went wrong.