Skip to content

Feature/rest api #15

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@EnableJpaRepositories("com.accenture.codingtest.springbootcodingtest.repository")
public class SpringBootCodingTestApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.accenture.codingtest.springbootcodingtest.model.Project;
import com.accenture.codingtest.springbootcodingtest.service.ProjectService;


@Controller("/api/v1/projects")
public class ProjectController {
@Autowired
private ProjectService projectService;

public ProjectController(ProjectService projectService) {
super();
this.projectService = projectService;
}

// GET retrieve all resources (ex. GET /api/v1/projects)
@GetMapping
public List<Project> retrieveAllProjects() {
return projectService.findAll();
}


// GET retrieve one resource by id (ex. GET /api/v1/projects/{project_id})
@GetMapping("/{project_id}")
public Optional<Project> getProjectById(@PathVariable("project_id") UUID id) {
return projectService.findById(id);
}
// POST create one resource (ex. POST /api/v1/projects)

@PostMapping
private void createProject(@RequestBody Project project) {
projectService.createProject(project);
}
// PUT update one resource idempotent (ex. PUT /api/v1/projects/{project_id})
@PutMapping("/{project_id}")
private void updateProject(@RequestBody Project project, @PathVariable("project_id") UUID id) {
projectService.updateProject(project, id);
}


// PATCH update one resource (ex. PATCH /api/v1/projects/{project_id})
@PatchMapping("/{project_id}")
private void patchProject(@RequestBody Project project, @PathVariable("project_id") UUID id) {
projectService.patchProject(project, id);
}
// DELETE remove one resource (ex. DELETE /api/v1/projects/{project_id})
@DeleteMapping("/{project_id}")
private void deleteProject(@PathVariable("project_id") UUID id) {
projectService.deleteProject(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.accenture.codingtest.springbootcodingtest.model.Task;
import com.accenture.codingtest.springbootcodingtest.model.Task;
import com.accenture.codingtest.springbootcodingtest.service.TaskService;


@Controller("/api/v1/tasks")
public class TaskController {

@Autowired
private TaskService taskService;

public TaskController(TaskService taskService) {
super();
this.taskService = taskService;
}
// GET retrieve all resources (ex. GET /api/v1/tasks)
@GetMapping
public List<Task> retrieveAllTasks() {
return taskService.findAll();
}


// GET retrieve one resource by id (ex. GET /api/v1/tasks/{task_id})
@GetMapping("/{task_id}")
public Optional<Task> getTaskById(@PathVariable("task_id") UUID id) {
return taskService.findById(id);
}
// POST create one resource (ex. POST /api/v1/tasks)

@PostMapping
private void createTask(@RequestBody Task task) {
taskService.createTask(task);
}
// PUT update one resource idempotent (ex. PUT /api/v1/tasks/{task_id})
@PutMapping("/{task_id}")
private void updateTask(@RequestBody Task task, @PathVariable("task_id") UUID id) {
taskService.updateTask(task, id);
}


// PATCH update one resource (ex. PATCH /api/v1/tasks/{task_id})
@PatchMapping("/{task_id}")
private void patchTask(@RequestBody Task task, @PathVariable("task_id") UUID id) {
taskService.patchTask(task, id);
}
// DELETE remove one resource (ex. DELETE /api/v1/tasks/{task_id})
@DeleteMapping("/{task_id}")
private void deleteTask(@PathVariable("task_id") UUID id) {
taskService.deleteTask(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.accenture.codingtest.springbootcodingtest.model.User;
import com.accenture.codingtest.springbootcodingtest.service.UserService;


@Controller("/api/v1/users")
public class UserController {

@Autowired
private UserService userService;

public UserController(UserService userService) {
super();
this.userService = userService;
}

// GET retrieve all resources (ex. GET /api/v1/users)
@GetMapping
public List<User> retrieveAllUsers() {
return userService.findAll();
}


// GET retrieve one resource by id (ex. GET /api/v1/users/{user_id})
@GetMapping("/{user_id}")
public Optional<User> getUserById(@PathVariable("user_id") UUID id) {
return userService.findById(id);
}
// POST create one resource (ex. POST /api/v1/users)

@PostMapping
private void createUser(@RequestBody User user) {
userService.createUser(user);
}
// PUT update one resource idempotent (ex. PUT /api/v1/users/{user_id})
@PutMapping("/{user_id}")
private void updateUser(@RequestBody User user, @PathVariable("user_id") UUID id) {
userService.updateUser(user, id);
}


// PATCH update one resource (ex. PATCH /api/v1/users/{user_id})
@PatchMapping("/{user_id}")
private void patchUser(@RequestBody User user, @PathVariable("user_id") UUID id) {
userService.patchUser(user, id);
}
// DELETE remove one resource (ex. DELETE /api/v1/users/{user_id})
@DeleteMapping("/{user_id}")
private void deleteUser(@PathVariable("user_id") UUID id) {
userService.deleteUser(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.accenture.codingtest.springbootcodingtest.controller;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.accenture.codingtest.springbootcodingtest.model;

import java.util.UUID;

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

import org.hibernate.annotations.GenericGenerator;

@Entity
public class Project {

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private UUID id;

@Column(unique = true, nullable = false)
private String name;

public UUID getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.accenture.codingtest.springbootcodingtest.model;

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;

import org.hibernate.annotations.GenericGenerator;

@Entity
public class Task {

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private UUID id;

@Column(nullable = false)
private String title;

@Column
private String description;

@Column(nullable = false)
private String status;

@JoinColumn(name="id", nullable=false)
private Project project_id;

@JoinColumn(name="id", nullable=false)
private User user_id;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

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

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public Project getProject_id() {
return project_id;
}

public void setProject_id(Project project_id) {
this.project_id = project_id;
}

public User getUser_id() {
return user_id;
}

public void setUser_id(User user_id) {
this.user_id = user_id;
}

public UUID getId() {
return id;
}

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


}
Loading