本来の期限に加えて自分の中での目標期限を設定できるよう仕様追加
This commit is contained in:
@@ -239,6 +239,7 @@ type CreateAssignmentInput struct {
|
||||
Subject string `json:"subject"`
|
||||
Priority string `json:"priority"`
|
||||
DueDate string `json:"due_date" binding:"required"`
|
||||
SoftDueDate string `json:"soft_due_date"`
|
||||
|
||||
ReminderEnabled bool `json:"reminder_enabled"`
|
||||
ReminderAt string `json:"reminder_at"`
|
||||
@@ -352,7 +353,17 @@ func (h *APIHandler) CreateAssignment(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
assignment, err := h.assignmentService.Create(userID, input.Title, input.Description, input.Subject, input.Priority, dueDate, input.ReminderEnabled, reminderAt, urgentReminder)
|
||||
var softDueDate *time.Time
|
||||
if input.SoftDueDate != "" {
|
||||
parsedSoft, err := parseDateString(input.SoftDueDate)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid soft_due_date format"})
|
||||
return
|
||||
}
|
||||
softDueDate = &parsedSoft
|
||||
}
|
||||
|
||||
assignment, err := h.assignmentService.Create(userID, input.Title, input.Description, input.Subject, input.Priority, dueDate, softDueDate, input.ReminderEnabled, reminderAt, urgentReminder)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create assignment"})
|
||||
return
|
||||
@@ -367,6 +378,7 @@ type UpdateAssignmentInput struct {
|
||||
Subject string `json:"subject"`
|
||||
Priority string `json:"priority"`
|
||||
DueDate string `json:"due_date"`
|
||||
SoftDueDate string `json:"soft_due_date"`
|
||||
ReminderEnabled *bool `json:"reminder_enabled"`
|
||||
ReminderAt string `json:"reminder_at"`
|
||||
UrgentReminderEnabled *bool `json:"urgent_reminder_enabled"`
|
||||
@@ -448,7 +460,17 @@ func (h *APIHandler) UpdateAssignment(c *gin.Context) {
|
||||
urgentReminderEnabled = *input.UrgentReminderEnabled
|
||||
}
|
||||
|
||||
assignment, err := h.assignmentService.Update(userID, uint(id), title, description, subject, priority, dueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
softDueDate := existing.SoftDueDate
|
||||
if input.SoftDueDate != "" {
|
||||
parsedSoft, err := parseDateString(input.SoftDueDate)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid soft_due_date format"})
|
||||
return
|
||||
}
|
||||
softDueDate = &parsedSoft
|
||||
}
|
||||
|
||||
assignment, err := h.assignmentService.Update(userID, uint(id), title, description, subject, priority, dueDate, softDueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update assignment"})
|
||||
return
|
||||
|
||||
@@ -111,14 +111,16 @@ func (h *AssignmentHandler) New(c *gin.Context) {
|
||||
now := time.Now()
|
||||
tomorrow := now.AddDate(0, 0, 1)
|
||||
defaultDue := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 23, 59, 0, 0, now.Location())
|
||||
defaultSoftDue := defaultDue.Add(-48 * time.Hour)
|
||||
|
||||
RenderHTML(c, http.StatusOK, "assignments/new.html", gin.H{
|
||||
"title": "課題登録",
|
||||
"isAdmin": role == "admin",
|
||||
"userName": name,
|
||||
"currentWeekday": int(now.Weekday()),
|
||||
"currentDay": now.Day(),
|
||||
"defaultDueDate": defaultDue.Format("2006-01-02T15:04"),
|
||||
"title": "課題登録",
|
||||
"isAdmin": role == "admin",
|
||||
"userName": name,
|
||||
"currentWeekday": int(now.Weekday()),
|
||||
"currentDay": now.Day(),
|
||||
"defaultDueDate": defaultDue.Format("2006-01-02T15:04"),
|
||||
"defaultSoftDueDate": defaultSoftDue.Format("2006-01-02T15:04"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -178,6 +180,16 @@ func (h *AssignmentHandler) Create(c *gin.Context) {
|
||||
dueDate = dueDate.Add(23*time.Hour + 59*time.Minute)
|
||||
}
|
||||
|
||||
var softDueDate *time.Time
|
||||
if softDueDateStr := c.PostForm("soft_due_date"); softDueDateStr != "" {
|
||||
if parsed, err := time.ParseInLocation("2006-01-02T15:04", softDueDateStr, time.Local); err == nil {
|
||||
softDueDate = &parsed
|
||||
} else if parsed, err := time.ParseInLocation("2006-01-02", softDueDateStr, time.Local); err == nil {
|
||||
p := parsed.Add(23*time.Hour + 59*time.Minute)
|
||||
softDueDate = &p
|
||||
}
|
||||
}
|
||||
|
||||
recurrenceType := c.PostForm("recurrence_type")
|
||||
if recurrenceType != "" && recurrenceType != "none" {
|
||||
|
||||
@@ -265,7 +277,7 @@ func (h *AssignmentHandler) Create(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
assignment, err := h.assignmentService.Create(userID, title, description, subject, priority, dueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
assignment, err := h.assignmentService.Create(userID, title, description, subject, priority, dueDate, softDueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
if err != nil {
|
||||
role, _ := c.Get(middleware.UserRoleKey)
|
||||
name, _ := c.Get(middleware.UserNameKey)
|
||||
@@ -352,7 +364,17 @@ func (h *AssignmentHandler) Update(c *gin.Context) {
|
||||
dueDate = dueDate.Add(23*time.Hour + 59*time.Minute)
|
||||
}
|
||||
|
||||
_, err = h.assignmentService.Update(userID, uint(id), title, description, subject, priority, dueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
var softDueDate *time.Time
|
||||
if softDueDateStr := c.PostForm("soft_due_date"); softDueDateStr != "" {
|
||||
if parsed, err := time.ParseInLocation("2006-01-02T15:04", softDueDateStr, time.Local); err == nil {
|
||||
softDueDate = &parsed
|
||||
} else if parsed, err := time.ParseInLocation("2006-01-02", softDueDateStr, time.Local); err == nil {
|
||||
p := parsed.Add(23*time.Hour + 59*time.Minute)
|
||||
softDueDate = &p
|
||||
}
|
||||
}
|
||||
|
||||
_, err = h.assignmentService.Update(userID, uint(id), title, description, subject, priority, dueDate, softDueDate, reminderEnabled, reminderAt, urgentReminderEnabled)
|
||||
if err != nil {
|
||||
c.Redirect(http.StatusFound, "/assignments")
|
||||
return
|
||||
@@ -501,10 +523,9 @@ func (h *AssignmentHandler) ExportCSV(c *gin.Context) {
|
||||
c.Header("Content-Disposition", "attachment; filename=\""+filename+"\"")
|
||||
|
||||
w := csv.NewWriter(c.Writer)
|
||||
// UTF-8 BOM for Excel compatibility
|
||||
c.Writer.Write([]byte("\xef\xbb\xbf"))
|
||||
|
||||
headers := []string{"ID", "タイトル", "科目", "説明", "重要度", "提出期限", "完了", "完了日時", "登録日時"}
|
||||
headers := []string{"ID", "タイトル", "科目", "説明", "重要度", "提出期限", "自分の期限", "完了", "完了日時", "登録日時"}
|
||||
w.Write(headers)
|
||||
|
||||
priorityLabel := map[string]string{"low": "低", "medium": "中", "high": "高"}
|
||||
@@ -517,6 +538,10 @@ func (h *AssignmentHandler) ExportCSV(c *gin.Context) {
|
||||
if a.CompletedAt != nil {
|
||||
completedAt = a.CompletedAt.Format("2006/01/02 15:04")
|
||||
}
|
||||
softDueDateStr := ""
|
||||
if a.SoftDueDate != nil {
|
||||
softDueDateStr = a.SoftDueDate.Format("2006/01/02 15:04")
|
||||
}
|
||||
label := priorityLabel[a.Priority]
|
||||
if label == "" {
|
||||
label = a.Priority
|
||||
@@ -528,6 +553,7 @@ func (h *AssignmentHandler) ExportCSV(c *gin.Context) {
|
||||
a.Description,
|
||||
label,
|
||||
a.DueDate.Format("2006/01/02 15:04"),
|
||||
softDueDateStr,
|
||||
completed,
|
||||
completedAt,
|
||||
a.CreatedAt.Format("2006/01/02 15:04"),
|
||||
|
||||
Reference in New Issue
Block a user