Skip to content

Commit

Permalink
Add Task Done
Browse files Browse the repository at this point in the history
  • Loading branch information
saishkulkarni committed Dec 5, 2023
1 parent fb32623 commit f727536
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/main/java/controller/AddTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.MyService;

@WebServlet("/add-task")
public class AddTask extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
MyService service=new MyService();
service.addTask(req,resp);
}
}
7 changes: 7 additions & 0 deletions src/main/java/dao/MyDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.persistence.Persistence;

import dto.Customer;
import dto.Task;

public class MyDao {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("dev");
Expand All @@ -26,4 +27,10 @@ public Customer findByEmail(String email) {
else
return customers.get(0);
}

public void saveTask(Task task) {
manager.getTransaction().begin();
manager.persist(task);
manager.getTransaction().commit();
}
}
22 changes: 22 additions & 0 deletions src/main/java/dto/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dto;

import java.time.LocalDateTime;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import lombok.Data;

@Entity
@Data
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
String name;
String description;
LocalDateTime createdTime;
boolean status;
}
18 changes: 18 additions & 0 deletions src/main/java/service/MyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.MyDao;
import dto.Customer;
import dto.Task;
import helper.AES;

public class MyService {
Expand Down Expand Up @@ -76,4 +78,20 @@ public void login(HttpServletRequest req, HttpServletResponse resp) throws IOExc
}
}
}

public void addTask(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
String name=req.getParameter("tname");
String description=req.getParameter("tdescription");

Task task=new Task();
task.setName(name);
task.setDescription(description);
task.setCreatedTime(LocalDateTime.now());

MyDao dao=new MyDao();
dao.saveTask(task);

resp.getWriter().print("<h1 align='center' style='color:green'>Task Saved Success</h1>");
req.getRequestDispatcher("Home.jsp").include(req, resp);
}
}
42 changes: 42 additions & 0 deletions src/main/webapp/AddTask.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Add Task</title>
<style>
div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div>
<h1>Add Task</h1>
<form action="add-task" method="post">
<fieldset>
<legend>Enter Task here,</legend>
<table>
<tr>
<th>Task Name: </th>
<th><input type="text" name="tname"></th>
</tr>
<tr>
<th>Task Description: </th>
<th><input type="text" name="tdescription"></th>
</tr>
<tr>
<th><button>Add</button></th>
<th><button type="reset">Cancel</button></th>
</tr>
</table>
</fieldset>
</form>
<br>
<br>
<a href="Home.jsp"><button>Back</button></a>
</div>
</body>
</html>
32 changes: 30 additions & 2 deletions src/main/webapp/Home.jsp
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home</title>
<style>
div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.extra {
margin-top: 20px;
margin-left: 305px;
}
</style>
</head>
<body>
<h1 align="center">This is Home Page</h1>
<h1 align="center">This is Home Page</h1>
<div>
<table border="1">
<tr>
<th>Task Name</th>
<th>Task Description</th>
<th>Status</th>
<th>Created Time</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</table>
</div>
<a href="AddTask.html"><button class="extra">Add Task</button></a>
<a href="Login.html"><button class="extra">Logout</button></a>
</body>
</html>
Binary file added target/classes/controller/AddTask.class
Binary file not shown.
Binary file modified target/classes/dao/MyDao.class
Binary file not shown.
Binary file added target/classes/dto/Task.class
Binary file not shown.
Binary file modified target/classes/service/MyService.class
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Mon Dec 04 19:25:24 IST 2023
#Tue Dec 05 20:35:17 IST 2023
m2e.projectLocation=C\:\\Users\\Faculty\\E5\\todo-app
m2e.projectName=todo-app
groupId=org.jsp
Expand Down

0 comments on commit f727536

Please sign in to comment.