Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToDoAppAngular Task #9

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e983679
todo-service initial commit with Configure JAX-RS and Filter Responses
raihanzohir May 21, 2023
9b98170
README.md updated
raihanzohir May 21, 2023
a224770
Added persistence.xml for DataSource (MySQL)
raihanzohir May 21, 2023
18db742
Item entity added as persistence object
raihanzohir May 21, 2023
e4d10bf
Interface EntityService that used only for naming convention for meth…
raihanzohir May 21, 2023
235bcfe
Service added for Todo Item Create, Read and Update
raihanzohir May 21, 2023
d5f4f55
Added Restful API endpoints to Resource
raihanzohir May 21, 2023
cac1057
Added data.sql for some initial data in items table
raihanzohir May 22, 2023
e76f3ff
todo-web (AngularJS) initial commit
raihanzohir May 24, 2023
c149f1e
For todo features (Todo List, Add Todo) added by adding .html, .js files
raihanzohir May 24, 2023
98aa6af
Update README.md
raihanzohir May 24, 2023
7f9dcef
Update README.md
raihanzohir May 24, 2023
116ff6c
Full project updated
raihanzohir May 24, 2023
71f7727
Update ItemResource.java
raihanzohir Jul 10, 2023
869467e
Update EntityService.java
raihanzohir Jul 10, 2023
4b72c99
Update ItemService.java
raihanzohir Jul 10, 2023
37e9614
Update ItemResource.java
raihanzohir Jul 10, 2023
8fec1d5
Fix Delete Operation
raihanzohir Jul 11, 2023
ecee9c0
Add isUrgent attribute added in Item.java and add a validation
raihanzohir Jul 12, 2023
93372f9
Item Date validation based on isUrgent value
raihanzohir Jul 12, 2023
108ae4b
Item Date validation message updated
raihanzohir Jul 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/todo-service/target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

/todo-service/.classpath
/todo-service/.project
/todo-service/.settings

.vscode/

#/todo-web/node_modules
71 changes: 55 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# ToDoApp

This is the job interview task for software developer position

## What to do
* Fork the repository
* After work is done, make a pull request and notify me by email

## Task description
You need to make a Todo app with these requirements:
1. Page for listing all the todo items
Expand All @@ -15,14 +9,59 @@ You need to make a Todo app with these requirements:

All the other specific requirements are up to you

## Technical requirements
* Use AngularJS for frontend
* For backend use Java EE
* Use any database (Postgres, Oracle, etc.)
* Make a Maven project
## Technologies used in this application
* AngularJS for frontend
* JavaEE for backend (Maven project)
* MySQL database

## JavaEE Application (Backend)
### Environment Setup
* Download JDK 1.8 or higher and configure
* Download Eclipse IDE for JavaEE Developers (https://www.eclipse.org/downloads/packages/release/kepler/sr2/eclipse-ide-java-ee-developers)
* Download Wildfly 18.0.0.Final (.zip) (https://download.jboss.org/wildfly/18.0.0.Final/wildfly-18.0.0.Final.zip). Chage the port to 8089
* Add datasouce named 'TestDS' in the standalone.xml
```
<datasource jndi-name="java:jboss/datasources/TestDS" pool-name="TestDS">
<connection-url>jdbc:mysql://localhost:3306/todo</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
```
* Add Wildfly server to Eclipse
* Download MySQL and install (ignore if already available). Create a database named 'todo'.
* Clone the repo and open the 'todo-service' in Eclipse
* Configure datasource in persistance.xml
```
<persistence-unit name="TestDS" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/TestDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>
<property name="javax.persistence.sql-load-script-source" value="META-INF/sql/data.sql"/>
</properties>
</persistence-unit>
```
* Select project root > Run As > Run on server
* Test the resouce endpoint in postman:
* For All Items (GET Method)
```
http://localhost:8089/todo-service/resources/items
```

## AngularJS Web Application (Frontend)
### Environment Setup
* Download Node.js 14.x (https://nodejs.org/en/blog/release/v14.17.3)
* Download VSCode and install
* Open 'todo-web' form the previously cloned repository
* Run the project with the following commands:
```
npm install
```
```
gulp
```

## Main points
* Structure your code
* Use best practises
* Use naming conventions
* Show understanding of software development concepts
55 changes: 55 additions & 0 deletions todo-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.todo.service</groupId>
<artifactId>todo-service</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<javaee-api.version>7.0</javaee-api.version>
</properties>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.15.6.Final</version>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.todo.sample.config;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

/**
* Created by Md. Zohir Raihan on 5/21/2023.
*/

@ApplicationPath("resources")
public class JAXRSConfiguration extends Application {

}
88 changes: 88 additions & 0 deletions todo-service/src/main/java/com/todo/sample/entity/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.todo.sample.entity;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.math.BigDecimal;
import java.sql.Date;

/**
* Created by Md. Zohir Raihan on 5/21/2023.
*/

@XmlRootElement
@Entity
@Table(name = "items")
@NamedQuery(name = Item.FIND_ALL, query = "select i from Item i")
public class Item {

public static final String FIND_ALL = "Item.findAll";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

private String name;

private String description;

private Date date;

private boolean isUrgent;

public boolean isUrgent() {
return isUrgent;
}

public void setUrgent(boolean isUrgent) {
this.isUrgent = isUrgent;
}

public Item() {
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

@Override
public String toString() {
return "Item [id=" + id + ", name=" + name + ", description=" + description + ", date=" + date + ", isUrgent="
+ isUrgent + "]";
}

// @Override
// public String toString() {
// return "Item [id=" + id + ", name=" + name + ", description=" + description + ", date=" + date + "]";
// }



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.todo.sample.filter;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;

/**
* Created by Md. Zohir Raihan on 5/21/2023.
*/
@Provider
public class ResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
responseContext.getHeaders().putSingle("Access-Control-Allow-Credentials", "true");
responseContext.getHeaders().putSingle("Access-Control-Allow-Origin", "*");
responseContext.getHeaders().putSingle("Access-Control-Allow-Headers", "Content-Type");
responseContext.getHeaders().putSingle("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.todo.sample.resource;

import java.net.URI;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.todo.sample.entity.Item;
import com.todo.sample.service.ItemService;

/**
* Created by Md. Zohir Raihan on 5/21/2023.
*/

@Path("/items")
public class ItemResource {

@Context
UriInfo uriInfo;

@EJB
ItemService itemService;

@POST
@Consumes(value = MediaType.APPLICATION_JSON)
@Produces(value = MediaType.APPLICATION_JSON)
public Response create(Item item) {

if(item.isUrgent()) {
LocalDate dateTwoDaysLater = LocalDate.now().plusDays(2);
LocalDate itemDate = LocalDate.parse(item.getDate().toString());
if(itemDate.isAfter(dateTwoDaysLater)) {
return Response.status(422).entity("Item Date should be in the next 2 days when it is urgent!").build();
}
}

itemService.create(item);

URI uri = uriInfo.getAbsolutePathBuilder().path(String.valueOf(item.getId())).build();
return Response.created(uri).build();
}

@GET
@Path("{id}")
@Produces(value = MediaType.APPLICATION_JSON)
public Item find(@PathParam("id") int id) {
return itemService.find(id);
}

@GET
@Produces(value = MediaType.APPLICATION_JSON)
public List<Item> find() {
return itemService.find();
}

@PUT
@Path("{id}")
@Consumes(value = MediaType.APPLICATION_JSON)
@Produces(value = MediaType.APPLICATION_JSON)
public Response update(@PathParam("id") int id, Item item) {
Item existingItem = itemService.find(id);
if(existingItem != null) {
itemService.update(existingItem);
return Response.noContent().build();
}
return Response.status(422).build();
}

@DELETE
@Path("{id}")
@Produces(value = MediaType.APPLICATION_JSON)
public Response delete(@PathParam("id") int id) {
itemService.delete(id);
return Response.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.todo.sample.service;

import java.util.List;

/**
* Created by Md. Zohir Raihan on 5/21/2023.
*
* Interface that used only for naming convention for methods for services
*/
public interface EntityService<E> {

void create(E e);

E find(int id);

E update(E e);

void delete(int id);

List<E> find();

}
Loading