Skip to content

Feature/restfunctions #2

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
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package com.accenture.codingtest.springbootcodingtest.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.accenture.codingtest.springbootcodingtest.entity.Project;
import com.accenture.codingtest.springbootcodingtest.entity.Task;
import com.accenture.codingtest.springbootcodingtest.entity.User;
import com.accenture.codingtest.springbootcodingtest.service.CodingTestService;


@RestController
@RequestMapping(path = "api/v1")
public class CodingTestController {


@Autowired
CodingTestService testService;

enum Role {
ADMIN, PRODUCT_OWNER
}

enum Status {
NOT_STARTED, IN_PROGRESS, READY_FOR_TEST, COMPLETED
}

@GetMapping("/users/{role}")
private List<User> getUsers(@PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
return testService.getUsers();
} else {
return null;
}
}

@PostMapping("/users/{role}")
private String saveUser(@RequestBody User user, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(user);
return user.getId();
} else {
return null;
}
}

@PutMapping("/users/{id}/{role}")
private String updateUser(@RequestBody User user, @PathVariable("id") String id,
@PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.updateById(user, id);
return user.getId();
} else {
return null;
}
}

@PatchMapping("/users/{id}/{role}")
private String patchUser(@RequestBody User user, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.updateById(user, id);
return user.getId();
} else {
return null;
}
}

@GetMapping("/user/{id}/{role}")
private User getUserById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
return testService.getUserById(id);
}else {
return null;
}
}

@DeleteMapping("/user/{id}/{role}")
private void deleteUser(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}

@GetMapping("/projects/{role}")
private List<Project> getProjects(@PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getProjects();
}else {
return null;
}

}

@PostMapping("/projects/{role}")
private String saveProject(@RequestBody Project project, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(project);
return project.getId();
}else {
return null;
}
}

@PutMapping("/projects/{id}/{role}")
private String updateUser(@RequestBody Project project, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(project, id);
return project.getId();
}else {
return null;
}
}

@PatchMapping("/projects/{id}/{role}")
private String patchUser(@RequestBody Project project, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(project, id);
return project.getId();
}else {
return null;
}
}

@GetMapping("/project/{id}/{role}")
private Project getProjectById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getProjectById(id);
}else {
return null;
}

}

@DeleteMapping("/project/{id}/{role}")
private void deleteProject(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}

@GetMapping("/tasks/{role}")
private List<Task> getTasks(@PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getTasks();
}else {
return null;
}
}

@GetMapping("/tasks/{role}/{userId}")
private List<Task> getTasksByUserId(@PathVariable("role") String role,@PathVariable("userId") String userId) {
return testService.getTasksByUserId(userId);
}

@PostMapping("/tasks/{role}")
private String saveTask(@RequestBody Task task, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(task);
return task.getId();
}else {
return null;
}
}

@PutMapping("/tasks/{id}/{role}")
private String updateTask(@RequestBody Task task, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(task, id);
return task.getId();
}else {
return null;
}
}

@PatchMapping("/tasks/{id}/{role}/{userId}")
private String patchTask(@RequestBody Task task, @PathVariable("id") String id, @PathVariable("role") String role,@PathVariable("userId") String userId) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(task, id);
return task.getId();
}else {
testService.updateById(task, id,userId);
return task.getId();
}
}

@GetMapping("/task/{id}/{role}")
private Task getTaskById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getTaskById(id);
}else {
return null;
}

}

@DeleteMapping("/task/{id}/{role}")
private void deleteTask(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}

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


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

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

@Id
@Column(name = "id")
private String id;
@Column(name = "name", length = 250, unique = true)
private String name;

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;
}

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


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

@Entity
@Table(name = "task")
public class Task {

@Id
@Column(name = "id")
private String id;
@Column(name = "title", length = 250, nullable = false)
private String title;
@Column(name = "description")
private String description;
@Column(name = "status", nullable = false)
private String status;
@Column(name = "project_id", nullable = false)
private String projectId;
@Column(name = "user_id", nullable = false)
private String userId;

public String getId() {
return id;
}

public void setId(String id) {
this.id = 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 String getProjectId() {
return projectId;
}

public void setProjectId(String projectId) {
this.projectId = projectId;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.accenture.codingtest.springbootcodingtest.entity;


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

@Entity
@Table(name = "user")
public class User {

@Id
@Column(name = "id")
private String id;
@Column(name = "user_name", length = 150, unique = true)
private String userName;
@Column(name = "password", length = 50)
private String password;

public String getId() {
return id;
}

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

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}
Loading