功能更新
This commit is contained in:
263
internal/controller/team.go
Normal file
263
internal/controller/team.go
Normal file
@@ -0,0 +1,263 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"nl-pms-api/internal/commonservice"
|
||||
"nl-pms-api/internal/service"
|
||||
)
|
||||
|
||||
// TeamController 团队协作 HTTP 绑定。
|
||||
type TeamController struct {
|
||||
Svc *service.TeamService
|
||||
}
|
||||
|
||||
func (h *TeamController) Create(c *gin.Context) {
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
out, err := h.Svc.Create(commonservice.UserID(c), req.Name)
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, out)
|
||||
}
|
||||
|
||||
func (h *TeamController) List(c *gin.Context) {
|
||||
out, err := h.Svc.List(commonservice.UserID(c))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
func (h *TeamController) Rename(c *gin.Context) {
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.Rename(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.Name); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) SetDigestTime(c *gin.Context) {
|
||||
var req struct {
|
||||
DigestTime string `json:"digestTime"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.SetDigestTime(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.DigestTime); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) Dissolve(c *gin.Context) {
|
||||
if err := h.Svc.Dissolve(commonservice.ParseID(c.Param("id")), commonservice.UserID(c)); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) Leave(c *gin.Context) {
|
||||
if err := h.Svc.Leave(commonservice.ParseID(c.Param("id")), commonservice.UserID(c)); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) Members(c *gin.Context) {
|
||||
out, err := h.Svc.Members(commonservice.ParseID(c.Param("id")), commonservice.UserID(c))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
func (h *TeamController) Invite(c *gin.Context) {
|
||||
var req struct {
|
||||
Username string `json:"username"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.Invite(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.Username, req.Role); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) SetRole(c *gin.Context) {
|
||||
var req struct {
|
||||
Role string `json:"role"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.SetRole(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), commonservice.ParseID(c.Param("userId")), req.Role); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) RemoveMember(c *gin.Context) {
|
||||
if err := h.Svc.RemoveMember(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), commonservice.ParseID(c.Param("userId"))); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) TaskSave(c *gin.Context) {
|
||||
var req service.TeamTaskDTO
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
req.TeamID = commonservice.ParseID(c.Param("id"))
|
||||
if tid := commonservice.ParseID(c.Param("taskId")); tid > 0 {
|
||||
req.ID = tid
|
||||
}
|
||||
out, err := h.Svc.TaskSave(commonservice.UserID(c), req)
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, out)
|
||||
}
|
||||
|
||||
func (h *TeamController) TaskSetStatus(c *gin.Context) {
|
||||
var req struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.TaskSetStatus(commonservice.ParseID(c.Param("id")), commonservice.ParseID(c.Param("taskId")), commonservice.UserID(c), req.Status); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) TaskUrge(c *gin.Context) {
|
||||
if err := h.Svc.TaskUrge(commonservice.ParseID(c.Param("id")), commonservice.ParseID(c.Param("taskId")), commonservice.UserID(c)); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) TaskDelete(c *gin.Context) {
|
||||
if err := h.Svc.TaskDelete(commonservice.ParseID(c.Param("id")), commonservice.ParseID(c.Param("taskId")), commonservice.UserID(c)); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) TaskList(c *gin.Context) {
|
||||
out, err := h.Svc.TaskList(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), c.Query("filter"))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
func (h *TeamController) SharedItems(c *gin.Context) {
|
||||
out, err := h.Svc.SharedItems(commonservice.ParseID(c.Param("id")), commonservice.UserID(c))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
func (h *TeamController) UrgeShared(c *gin.Context) {
|
||||
var req struct {
|
||||
Kind string `json:"kind"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.UrgeShared(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.Kind, req.UUID); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) ReportSubmit(c *gin.Context) {
|
||||
var req struct {
|
||||
Date string `json:"date"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.ReportSubmit(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.Date, req.Content); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) ReportBoardGet(c *gin.Context) {
|
||||
out, err := h.Svc.ReportBoardGet(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), c.Param("date"))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, out)
|
||||
}
|
||||
|
||||
func (h *TeamController) ReportUrge(c *gin.Context) {
|
||||
var req struct {
|
||||
UserID int64 `json:"userId"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.ReportUrge(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), req.UserID, req.Date); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func (h *TeamController) DigestSave(c *gin.Context) {
|
||||
var req struct {
|
||||
Content string `json:"content"`
|
||||
Provider string `json:"provider"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Svc.DigestSave(commonservice.ParseID(c.Param("id")), commonservice.UserID(c), c.Param("date"), req.Content, req.Provider); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
Reference in New Issue
Block a user