-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
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
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,55 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"text/template" | ||
"time" | ||
|
||
"github.com/Akshat120/Task-Management-System/internal/repos" | ||
) | ||
|
||
type createTaskHandler struct { | ||
tmpl *template.Template | ||
repo repos.TaskRepo | ||
} | ||
|
||
func NewCreateTaskHandler(tmpl *template.Template, repo repos.TaskRepo) *createTaskHandler { | ||
return &createTaskHandler{repo: repo, tmpl: tmpl} | ||
} | ||
|
||
func (handler *createTaskHandler) HandleShowForm(w http.ResponseWriter, r *http.Request) { | ||
if err := handler.tmpl.Execute(w, nil); err != nil { | ||
http.Error(w, "Error rendering template", http.StatusInternalServerError) | ||
} | ||
} | ||
|
||
func (handler *createTaskHandler) HandleCreateTask(w http.ResponseWriter, r *http.Request) { | ||
var due_date time.Time | ||
var err error | ||
layout := "2006-01-02" | ||
if r.FormValue("due_date") != "" { | ||
due_date, err = time.Parse(layout, r.FormValue("due_date")) | ||
if err != nil { | ||
fmt.Println("err:", err) | ||
http.Error(w, "Error in parsing due_date", http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
|
||
task := repos.Task{ | ||
Title: r.FormValue("title"), | ||
Description: r.FormValue("description"), | ||
Status: r.FormValue("status"), | ||
DueDate: &due_date, | ||
} | ||
|
||
drn_id, err := handler.repo.Upsert(&task) | ||
if err != nil { | ||
fmt.Println("err:", err) | ||
http.Error(w, "Error in creating task", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
http.Redirect(w, r, fmt.Sprintf("/preview?id=%v", drn_id.String()), http.StatusMovedPermanently) | ||
} |
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 @@ | ||
package handler |
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
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 @@ | ||
package handler |
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
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
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,89 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Create Task</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
padding: 20px; | ||
} | ||
.container { | ||
background-color: #fff; | ||
padding: 20px; | ||
max-width: 600px; | ||
margin: 0 auto; | ||
border-radius: 5px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
h1 { | ||
text-align: center; | ||
} | ||
.form-group { | ||
margin-bottom: 15px; | ||
} | ||
.form-group label { | ||
display: block; | ||
margin-bottom: 5px; | ||
} | ||
.form-group input, | ||
.form-group textarea, | ||
.form-group select { | ||
width: 100%; | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
.form-group button { | ||
padding: 10px 20px; | ||
background-color: #28a745; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
.form-group button:hover { | ||
background-color: #218838; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h1>Create New Task</h1> | ||
<form action="/new" method="POST"> | ||
<div class="form-group"> | ||
<label for="title">Task Title</label> | ||
<input type="text" id="title" name="title" required> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="description">Task Description</label> | ||
<textarea id="description" name="description" rows="4"></textarea> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="status">Task Status</label> | ||
<select id="status" name="status" required> | ||
<option value="Pending">Pending</option> | ||
<option value="In Progress">In Progress</option> | ||
<option value="Completed">Completed</option> | ||
</select> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="due_date">Due Date</label> | ||
<input type="date" id="due_date" name="due_date"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<button type="submit">Create Task</button> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</body> | ||
</html> |
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