Skip to content

Feature/core functions #25

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 8 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
422 changes: 422 additions & 0 deletions docs/Test.postman_collection.json

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,27 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</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>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.accenture.codingtest.springbootcodingtest.constants;

public enum Status {
NOT_STARTED, IN_PROGRESS, READY_FOR_TEST, COMPLETED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/api")
public class ProjectController {
@Autowired
private ProjectService projectService;

@GetMapping("/v1/projects")
public ResponseEntity<List<Project>> getAllProjects() {
return projectService.getAllProjects();
}

@PostMapping("/v1/projects/{role}")
public ResponseEntity<Project> saveProject(@RequestBody Project project,
@PathVariable("role") String role) {
ResponseEntity<Project> response;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = projectService.saveProject(project);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@GetMapping("/v1/projects/{project_id}")
public ResponseEntity<Project> getProjectById(@PathVariable("project_id") String project_id) {
return projectService.getProjectById(project_id);
}

@PutMapping("/v1/projects")
public ResponseEntity<Project> updateProject(@RequestBody Project project) {
return projectService.updateProject(project);
}

@DeleteMapping("/v1/projects/{project_id}")
public ResponseEntity<Void> deleteProjectById(@PathVariable("project_id") String project_id) {
return projectService.deleteProject(project_id);
}

@GetMapping
public Page<Project> getProjects(@RequestParam(value = "q", required = false) String searchKeyword, @RequestParam(value = "pageIndex", defaultValue = "0") int pageIndex, @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
@RequestParam(value = "sortBy", defaultValue = "name") String sortBy, @RequestParam(value = "sortDirection", defaultValue = "ASC") String sortDirection) {

Sort.Direction direction = Sort.Direction.ASC;
if (sortDirection.equalsIgnoreCase("DESC")) {
direction = Sort.Direction.DESC;
}

Sort sort = Sort.by(direction, sortBy);
PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, sort);

if (searchKeyword != null && !searchKeyword.isEmpty()) {
return projectService.searchProjectsByName(searchKeyword, pageRequest);
} else {
return projectService.getAllProjects(pageRequest);
}
}

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

import java.util.List;

import com.accenture.codingtest.springbootcodingtest.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/api")
public class TaskController {
@Autowired
private TaskService taskService;

@GetMapping("/v1/tasks")
public ResponseEntity<List<Task>> getAllTasks() {
return taskService.getAllTasks();
}

@PostMapping("/v1/tasks/{role}")
public ResponseEntity<Task> saveTask(@RequestBody Task task, @PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.saveTask(task);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@GetMapping("/v1/tasks/{task_id}")
public ResponseEntity<Task> getTaskById(@PathVariable("task_id") String task_id) {
return taskService.getTaskById(task_id);
}

@PatchMapping("/v1/tasks/{role}")
public ResponseEntity<Task> updateTask(@RequestBody Task task,
@PathVariable("userId") String userId,
@PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.updateTask(task, userId);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@PutMapping("/v1/tasks/{role}")
public ResponseEntity<Task> updateTask(@RequestBody Task task, @PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.updateTask(task);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}


@DeleteMapping("/v1/tasks/{task_id}")
public ResponseEntity<Void> deleteTaskById(@PathVariable("task_id") String task_id) {
return taskService.deleteTask(task_id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import com.accenture.codingtest.springbootcodingtest.entity.User;
import com.accenture.codingtest.springbootcodingtest.model.Role;
import com.accenture.codingtest.springbootcodingtest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UserController {

@Autowired
private UserService userService;

@GetMapping("/v1/users/{role}")
public ResponseEntity<List<User>> getAllUsers(@PathVariable("role") String role) {
ResponseEntity<List<User>> response = null;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = userService.getAllUsers();
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@GetMapping("/v1/users/{user_id}/{role}")
public ResponseEntity<User> getUserById(@PathVariable("user_id") String user_id,
@PathVariable("role") String role) {
ResponseEntity<User> response = null;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = userService.getUserById(user_id);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@PostMapping("/v1/users/{role}")
public ResponseEntity<User> saveUser(@RequestBody User user, @PathVariable("role") String role) {

ResponseEntity<User> response = null;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = userService.saveUser(user);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@PutMapping("/v1/users")
public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable("role") String role) {
ResponseEntity<User> response = null;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = userService.updateUser(user);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}

@DeleteMapping("/v1/users/{user_id}")
public ResponseEntity<Void> deleteUserById(@PathVariable("user_id") String user_id,
@PathVariable("role") String role) {
ResponseEntity<Void> response;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = userService.deleteUser(user_id);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.accenture.codingtest.springbootcodingtest.entity;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Project")
public class Project {

@Id
private String id;
private String name;

public Project() {
super();
// TODO Auto-generated constructor stub
}

public String getId() {
return id;
}

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

public String getName() {
return name;
}

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

public Project(String id, String name) {
super();
this.id = id;
this.name = name;
}

@Override
public String toString() {
return "Project [id=" + id + ", name=" + name + "]";
}

}
Loading