up
This commit is contained in:
@@ -30,7 +30,7 @@ type TabCalendarEvent struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
CalendarID uint `gorm:"not null;index;comment:关联日历ID"`
|
||||
UserID uint `gorm:"not null;comment:创建人ID"`
|
||||
UsersID []uint `gorm:"type:json; null;comment:其他关联用户ID"`
|
||||
//UsersID []uint `gorm:"type:json; null;comment:其他关联用户ID"`
|
||||
Title string `gorm:"size:200;not null;comment:事件标题"`
|
||||
StartDate *time.Time `gorm:"size:10;not null;index;comment:开始日期 YYYY-MM-DD"`
|
||||
EndDate *time.Time `gorm:"size:10;not null;index;comment:结束日期 YYYY-MM-DD"`
|
||||
@@ -88,9 +88,10 @@ type fromGetCalendarEvents struct {
|
||||
type fromAddCalendarEvent struct {
|
||||
CalendarID uint `json:"calendar_id" binding:"required"`
|
||||
Title string `json:"title" binding:"required"`
|
||||
Start *time.Time `json:"start" binding:"required"`
|
||||
End *time.Time `json:"end" binding:"required"`
|
||||
Start string `json:"start" binding:"required"`
|
||||
End string `json:"end" binding:"required"`
|
||||
Color string `json:"color"`
|
||||
ScheduleType string `json:"schedule_type"`
|
||||
Is_public bool `json:"is_public"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
@@ -98,9 +99,10 @@ type fromAddCalendarEvent struct {
|
||||
type fromUpdateCalendarEvent struct {
|
||||
ID uint `json:"id" binding:"required"`
|
||||
Title string `json:"title" binding:"required"`
|
||||
Start *time.Time `json:"start" binding:"required"`
|
||||
End *time.Time `json:"end" binding:"required"`
|
||||
Start string `json:"start" binding:"required"`
|
||||
End string `json:"end" binding:"required"`
|
||||
Color string `json:"color"`
|
||||
ScheduleType string `json:"schedule_type"`
|
||||
Is_public bool `json:"is_public"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
@@ -352,24 +354,41 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
r.POST("/calendar/addevent", func(ctx *gin.Context) {
|
||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||
if isAuth {
|
||||
var from fromAddCalendarEvent
|
||||
if err := mapstructure.Decode(data, &from); err == nil {
|
||||
// 先检查必需字段
|
||||
calendarIDRaw, ok := data["calendar_id"].(float64)
|
||||
if !ok || calendarIDRaw == 0 {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
return
|
||||
}
|
||||
calendarID := uint(calendarIDRaw)
|
||||
|
||||
// 检查日历是否存在
|
||||
var calendar TabCalendar
|
||||
if models.DB.Where("id = ? AND deleted_at IS NULL", from.CalendarID).First(&calendar).Error != nil {
|
||||
if models.DB.Where("id = ? AND deleted_at IS NULL", calendarID).First(&calendar).Error != nil {
|
||||
ReturnJson(ctx, "calendar_not_find", nil)
|
||||
return
|
||||
}
|
||||
|
||||
// 解析日期
|
||||
startStr, _ := data["start"].(string)
|
||||
endStr, _ := data["end"].(string)
|
||||
title, _ := data["title"].(string)
|
||||
color, _ := data["color"].(string)
|
||||
remark, _ := data["remark"].(string)
|
||||
isPublic, _ := data["is_public"].(bool)
|
||||
|
||||
startDate, _ := time.Parse("2006-01-02 15:04:05", startStr)
|
||||
endDate, _ := time.Parse("2006-01-02 15:04:05", endStr)
|
||||
|
||||
event := TabCalendarEvent{
|
||||
CalendarID: from.CalendarID,
|
||||
CalendarID: calendarID,
|
||||
UserID: user.ID,
|
||||
Title: from.Title,
|
||||
StartDate: from.Start,
|
||||
EndDate: from.End,
|
||||
BgColor: from.Color,
|
||||
IsPublic: from.Is_public,
|
||||
Remark: from.Remark,
|
||||
Title: title,
|
||||
StartDate: &startDate,
|
||||
EndDate: &endDate,
|
||||
BgColor: color,
|
||||
IsPublic: isPublic,
|
||||
Remark: remark,
|
||||
}
|
||||
if event.BgColor == "" {
|
||||
event.BgColor = calendar.Color
|
||||
@@ -391,9 +410,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
} else {
|
||||
ReturnJson(ctx, "apiErr", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "userCookieError", nil)
|
||||
}
|
||||
@@ -403,23 +419,40 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
r.POST("/calendar/updateevent", func(ctx *gin.Context) {
|
||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||
if isAuth {
|
||||
var from fromUpdateCalendarEvent
|
||||
if err := mapstructure.Decode(data, &from); err == nil {
|
||||
// 先检查必需字段
|
||||
idRaw, ok := data["id"].(float64)
|
||||
if !ok || idRaw == 0 {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
return
|
||||
}
|
||||
eventID := uint(idRaw)
|
||||
|
||||
oldEvent := TabCalendarEvent{}
|
||||
if models.DB.Where("id = ?", from.ID).First(&oldEvent).Error == nil {
|
||||
if models.DB.Where("id = ?", eventID).First(&oldEvent).Error == nil {
|
||||
// 检查权限(只有创建人可以修改)
|
||||
if oldEvent.UserID != user.ID {
|
||||
ReturnJson(ctx, "permission_denied", nil)
|
||||
return
|
||||
}
|
||||
|
||||
// 解析字段
|
||||
startStr, _ := data["start"].(string)
|
||||
endStr, _ := data["end"].(string)
|
||||
title, _ := data["title"].(string)
|
||||
color, _ := data["color"].(string)
|
||||
remark, _ := data["remark"].(string)
|
||||
isPublic, _ := data["is_public"].(bool)
|
||||
|
||||
startDate, _ := time.Parse("2006-01-02 15:04:05", startStr)
|
||||
endDate, _ := time.Parse("2006-01-02 15:04:05", endStr)
|
||||
|
||||
newEvent := TabCalendarEvent{
|
||||
Title: from.Title,
|
||||
StartDate: from.Start,
|
||||
EndDate: from.End,
|
||||
BgColor: from.Color,
|
||||
IsPublic: from.Is_public,
|
||||
Remark: from.Remark,
|
||||
Title: title,
|
||||
StartDate: &startDate,
|
||||
EndDate: &endDate,
|
||||
BgColor: color,
|
||||
IsPublic: isPublic,
|
||||
Remark: remark,
|
||||
}
|
||||
if newEvent.BgColor == "" {
|
||||
// 获取日历颜色
|
||||
@@ -449,9 +482,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
} else {
|
||||
ReturnJson(ctx, "event_not_find", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "userCookieError", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user