up
This commit is contained in:
@@ -30,7 +30,7 @@ type TabCalendarEvent struct {
|
|||||||
ID uint `gorm:"primarykey"`
|
ID uint `gorm:"primarykey"`
|
||||||
CalendarID uint `gorm:"not null;index;comment:关联日历ID"`
|
CalendarID uint `gorm:"not null;index;comment:关联日历ID"`
|
||||||
UserID uint `gorm:"not null;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:事件标题"`
|
Title string `gorm:"size:200;not null;comment:事件标题"`
|
||||||
StartDate *time.Time `gorm:"size:10;not null;index;comment:开始日期 YYYY-MM-DD"`
|
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"`
|
EndDate *time.Time `gorm:"size:10;not null;index;comment:结束日期 YYYY-MM-DD"`
|
||||||
@@ -88,9 +88,10 @@ type fromGetCalendarEvents struct {
|
|||||||
type fromAddCalendarEvent struct {
|
type fromAddCalendarEvent struct {
|
||||||
CalendarID uint `json:"calendar_id" binding:"required"`
|
CalendarID uint `json:"calendar_id" binding:"required"`
|
||||||
Title string `json:"title" binding:"required"`
|
Title string `json:"title" binding:"required"`
|
||||||
Start *time.Time `json:"start" binding:"required"`
|
Start string `json:"start" binding:"required"`
|
||||||
End *time.Time `json:"end" binding:"required"`
|
End string `json:"end" binding:"required"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
|
ScheduleType string `json:"schedule_type"`
|
||||||
Is_public bool `json:"is_public"`
|
Is_public bool `json:"is_public"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
}
|
}
|
||||||
@@ -98,9 +99,10 @@ type fromAddCalendarEvent struct {
|
|||||||
type fromUpdateCalendarEvent struct {
|
type fromUpdateCalendarEvent struct {
|
||||||
ID uint `json:"id" binding:"required"`
|
ID uint `json:"id" binding:"required"`
|
||||||
Title string `json:"title" binding:"required"`
|
Title string `json:"title" binding:"required"`
|
||||||
Start *time.Time `json:"start" binding:"required"`
|
Start string `json:"start" binding:"required"`
|
||||||
End *time.Time `json:"end" binding:"required"`
|
End string `json:"end" binding:"required"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
|
ScheduleType string `json:"schedule_type"`
|
||||||
Is_public bool `json:"is_public"`
|
Is_public bool `json:"is_public"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
}
|
}
|
||||||
@@ -352,24 +354,41 @@ func ApiCalendar(r *gin.RouterGroup) {
|
|||||||
r.POST("/calendar/addevent", func(ctx *gin.Context) {
|
r.POST("/calendar/addevent", func(ctx *gin.Context) {
|
||||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||||
if isAuth {
|
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
|
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)
|
ReturnJson(ctx, "calendar_not_find", nil)
|
||||||
return
|
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{
|
event := TabCalendarEvent{
|
||||||
CalendarID: from.CalendarID,
|
CalendarID: calendarID,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
Title: from.Title,
|
Title: title,
|
||||||
StartDate: from.Start,
|
StartDate: &startDate,
|
||||||
EndDate: from.End,
|
EndDate: &endDate,
|
||||||
BgColor: from.Color,
|
BgColor: color,
|
||||||
IsPublic: from.Is_public,
|
IsPublic: isPublic,
|
||||||
Remark: from.Remark,
|
Remark: remark,
|
||||||
}
|
}
|
||||||
if event.BgColor == "" {
|
if event.BgColor == "" {
|
||||||
event.BgColor = calendar.Color
|
event.BgColor = calendar.Color
|
||||||
@@ -391,9 +410,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
|||||||
} else {
|
} else {
|
||||||
ReturnJson(ctx, "apiErr", nil)
|
ReturnJson(ctx, "apiErr", nil)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ReturnJson(ctx, "jsonErr", nil)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ReturnJson(ctx, "userCookieError", nil)
|
ReturnJson(ctx, "userCookieError", nil)
|
||||||
}
|
}
|
||||||
@@ -403,23 +419,40 @@ func ApiCalendar(r *gin.RouterGroup) {
|
|||||||
r.POST("/calendar/updateevent", func(ctx *gin.Context) {
|
r.POST("/calendar/updateevent", func(ctx *gin.Context) {
|
||||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||||
if isAuth {
|
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{}
|
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 {
|
if oldEvent.UserID != user.ID {
|
||||||
ReturnJson(ctx, "permission_denied", nil)
|
ReturnJson(ctx, "permission_denied", nil)
|
||||||
return
|
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{
|
newEvent := TabCalendarEvent{
|
||||||
Title: from.Title,
|
Title: title,
|
||||||
StartDate: from.Start,
|
StartDate: &startDate,
|
||||||
EndDate: from.End,
|
EndDate: &endDate,
|
||||||
BgColor: from.Color,
|
BgColor: color,
|
||||||
IsPublic: from.Is_public,
|
IsPublic: isPublic,
|
||||||
Remark: from.Remark,
|
Remark: remark,
|
||||||
}
|
}
|
||||||
if newEvent.BgColor == "" {
|
if newEvent.BgColor == "" {
|
||||||
// 获取日历颜色
|
// 获取日历颜色
|
||||||
@@ -449,9 +482,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
|||||||
} else {
|
} else {
|
||||||
ReturnJson(ctx, "event_not_find", nil)
|
ReturnJson(ctx, "event_not_find", nil)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ReturnJson(ctx, "jsonErr", nil)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ReturnJson(ctx, "userCookieError", nil)
|
ReturnJson(ctx, "userCookieError", nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user