Skip to content

Commit

Permalink
Added new fields in services' database schema
Browse files Browse the repository at this point in the history
  • Loading branch information
theioakiti committed Jun 15, 2022
1 parent 50bb4ae commit 866a464
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 21 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.smartclide.dbapi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.mapping.event.ValidatingMongoEventListener;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

@Configuration
public class MongoValidationConfig {
@Bean
public ValidatingMongoEventListener validatingMongoEventListener(LocalValidatorFactoryBean localValidatorFactoryBean) {
return new ValidatingMongoEventListener(localValidatorFactoryBean);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<CiManager> getCiManager(@PathVariable("id") String id) {
}

@PostMapping("/ci_managers")
public ResponseEntity<CiManager> createCiManager(@RequestBody CiManager ciManager) {
public ResponseEntity<CiManager> createCiManager(@RequestBody @Valid CiManager ciManager) {
try {
CiManager _ciManager = repository.save(ciManager);
return new ResponseEntity<>(_ciManager, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<CiManager> createCiManager(@RequestBody CiManager ciManage
}

@PutMapping("/ci_managers/{id}")
public ResponseEntity<CiManager> updateCiManager(@PathVariable("id") String id, @RequestBody CiManager ciManager) {
public ResponseEntity<CiManager> updateCiManager(@PathVariable("id") String id, @RequestBody @Valid CiManager ciManager) {
try {
Optional<CiManager> ciManagerData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<Deployment> getDeployment(@PathVariable("id") String id) {
}

@PostMapping("/deployments")
public ResponseEntity<Deployment> createDeployment(@RequestBody Deployment deployment) {
public ResponseEntity<Deployment> createDeployment(@RequestBody @Valid Deployment deployment) {
try {
Deployment _deployment = repository.save(deployment);
return new ResponseEntity<>(_deployment, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<Deployment> createDeployment(@RequestBody Deployment deplo
}

@PutMapping("/deployments/{id}")
public ResponseEntity<Deployment> updateDeployment(@PathVariable("id") String id, @RequestBody Deployment deployment) {
public ResponseEntity<Deployment> updateDeployment(@PathVariable("id") String id, @RequestBody @Valid Deployment deployment) {
try {
Optional<Deployment> deploymentData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<DeploymentPlatform> getDeploymentPlatform(@PathVariable("id") St
}

@PostMapping("deployment_platforms")
public ResponseEntity<DeploymentPlatform> createDeploymentPlatform(@RequestBody DeploymentPlatform deploymentPlatform) {
public ResponseEntity<DeploymentPlatform> createDeploymentPlatform(@RequestBody @Valid DeploymentPlatform deploymentPlatform) {
try {
DeploymentPlatform _deploymentPlatform = repository.save(deploymentPlatform);
return new ResponseEntity<>(_deploymentPlatform, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<DeploymentPlatform> createDeploymentPlatform(@RequestBody
}

@PutMapping("/deployment_platforms/{id}")
public ResponseEntity<DeploymentPlatform> updateDeploymentPlatform(@PathVariable("id") String id, @RequestBody DeploymentPlatform deploymentPlatform) {
public ResponseEntity<DeploymentPlatform> updateDeploymentPlatform(@PathVariable("id") String id, @RequestBody @Valid DeploymentPlatform deploymentPlatform) {
try {
Optional<DeploymentPlatform> deploymentPlatformData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<GitCredentials> getGitCredentials(@PathVariable("id") String id)
}

@PostMapping("/git_credentials")
public ResponseEntity<GitCredentials> createGitCredentials(@RequestBody GitCredentials gitCredentials) {
public ResponseEntity<GitCredentials> createGitCredentials(@RequestBody @Valid GitCredentials gitCredentials) {
try {
GitCredentials _gitCredentials = repository.save(gitCredentials);
return new ResponseEntity<>(_gitCredentials, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<GitCredentials> createGitCredentials(@RequestBody GitCrede
}

@PutMapping("/git_credentials/{id}")
public ResponseEntity<GitCredentials> updateGitCredentials(@PathVariable("id") String id, @RequestBody GitCredentials gitCredentials) {
public ResponseEntity<GitCredentials> updateGitCredentials(@PathVariable("id") String id, @RequestBody @Valid GitCredentials gitCredentials) {
try {
Optional<GitCredentials> gitCredentialsData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Optional;
Expand All @@ -29,7 +30,7 @@ public Optional<Service> getService(@PathVariable("id") String id) {
}

@PostMapping("/services")
public ResponseEntity<Service> createService(@RequestBody Service service) {
public ResponseEntity<Service> createService(@RequestBody @Valid Service service) {
try {
Service _service = repository.save(service);
return new ResponseEntity<>(_service, HttpStatus.CREATED);
Expand All @@ -39,7 +40,7 @@ public ResponseEntity<Service> createService(@RequestBody Service service) {
}

@PutMapping("/services/{id}")
public ResponseEntity<Service> updateService(@PathVariable("id") String id, @RequestBody Service service) {
public ResponseEntity<Service> updateService(@PathVariable("id") String id, @RequestBody @Valid Service service) {
try {
Optional<Service> serviceData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<ServiceRegistry> getServiceRegistry(@PathVariable("id") String i
}

@PostMapping("/service_registries")
public ResponseEntity<ServiceRegistry> creteServiceRegistry(@RequestBody ServiceRegistry serviceRegistry) {
public ResponseEntity<ServiceRegistry> creteServiceRegistry(@RequestBody @Valid ServiceRegistry serviceRegistry) {
try {
ServiceRegistry _serviceRegistry = repository.save(serviceRegistry);
return new ResponseEntity<>(_serviceRegistry, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<ServiceRegistry> creteServiceRegistry(@RequestBody Service
}

@PutMapping("/service_registries/{id}")
public ResponseEntity<ServiceRegistry> updateServiceRegistry(@PathVariable("id") String id, @RequestBody ServiceRegistry serviceRegistry) {
public ResponseEntity<ServiceRegistry> updateServiceRegistry(@PathVariable("id") String id, @RequestBody @Valid ServiceRegistry serviceRegistry) {
try {
Optional<ServiceRegistry> serviceRegistryData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<Team> getTeam(@PathVariable("id") String id) {
}

@PostMapping("/teams")
public ResponseEntity<Team> createTeam(@RequestBody Team team) {
public ResponseEntity<Team> createTeam(@RequestBody @Valid Team team) {
try {
Team _team = repository.save(team);
return new ResponseEntity<>(_team, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<Team> createTeam(@RequestBody Team team) {
}

@PutMapping("/teams/{id}")
public ResponseEntity<Team> updateTeam(@PathVariable("id") String id, @RequestBody Team team) {
public ResponseEntity<Team> updateTeam(@PathVariable("id") String id, @RequestBody @Valid Team team) {
try {
Optional<Team> teamData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<User> getUser(@PathVariable("id") String id) {
}

@PostMapping("/users")
public ResponseEntity<User> createUser(@RequestBody User user) {
public ResponseEntity<User> createUser(@RequestBody @Valid User user) {
try {
User _user = repository.save(user);
return new ResponseEntity<>(_user, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<User> createUser(@RequestBody User user) {
}

@PutMapping("/users/{id}")
public ResponseEntity<User> updateUser(@PathVariable("id") String id, @RequestBody User user) {
public ResponseEntity<User> updateUser(@PathVariable("id") String id, @RequestBody @Valid User user) {
try {
Optional<User> userData = repository.findById(id);
if (userData.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,7 +28,7 @@ public Optional<Workflow> getWorkflow(@PathVariable("id") String id) {
}

@PostMapping("/workflows")
public ResponseEntity<Workflow> createWorkflow(@RequestBody Workflow workflow) {
public ResponseEntity<Workflow> createWorkflow(@RequestBody @Valid Workflow workflow) {
try {
Workflow _workflow = repository.save(workflow);
return new ResponseEntity<>(_workflow, HttpStatus.CREATED);
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<Workflow> createWorkflow(@RequestBody Workflow workflow) {
}

@PutMapping("/workflows/{id}")
public ResponseEntity<Workflow> updateWorkflow(@PathVariable("id") String id, @RequestBody Workflow workflow) {
public ResponseEntity<Workflow> updateWorkflow(@PathVariable("id") String id, @RequestBody @Valid Workflow workflow) {
try {
Optional<Workflow> workflowData = repository.findById(id);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.smartclide.dbapi.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class AppExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, String> handleInvalidArgs(MethodArgumentNotValidException exception) {
Map<String, String> errorMap = new HashMap<>();
exception.getBindingResult().getFieldErrors().forEach(fieldError -> {
errorMap.put(fieldError.getField(), fieldError.getDefaultMessage());
});
return errorMap;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/smartclide/dbapi/exception/Error.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//package com.smartclide.dbapi.exception;
//
//public class Error {
//
// private String message;
// private int status;
// private Long timestamp;
//
// public String getMessage() {
// return message;
// }
//
// public void setMessage(String message) {
// this.message = message;
// }
//
// public int getStatus() {
// return status;
// }
//
// public void setStatus(int status) {
// this.status = status;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//package com.smartclide.dbapi.exception;
//
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Date;
//
//@ControllerAdvice
//public class GlobalExceptionHandlerController {
//
// @ExceptionHandler(ResourceNotFoundException.class)
// public ResponseEntity<Object> resourceNotFound(ResourceNotFoundException ex,
// HttpServletRequest request) {
// Error error = new Error();
// error.setMessage(ex.getMessage());
// error.setTimestamp(new Date().getTime());
// error.setStatus(HttpStatus.NOT_FOUND.value());
// return new ResponseEntity<>(error, null, HttpStatus.NOT_FOUND);
// }
//
// @ExceptionHandler(MethodArgumentNotValidException.class)
// public ResponseEntity<Object> badRequest(MethodArgumentNotValidException ex,
// HttpServletRequest request) {
// Error error = new Error();
// //error.setMessage(ex.getMessage());
// error.setMessage(ex.get);
// error.setTimestamp(new Date().getTime());
// error.setStatus(HttpStatus.BAD_REQUEST.value());
// return new ResponseEntity<>(error, null, HttpStatus.BAD_REQUEST);
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//package com.smartclide.dbapi.exception;
//
//public class ResourceNotFoundException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public ResourceNotFoundException(String message) {
// super(message);
// }
//}
7 changes: 7 additions & 0 deletions src/main/java/com/smartclide/dbapi/model/CiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;

import javax.validation.constraints.NotNull;

@Document(collection = "ci_managers")
@Data
public class CiManager {

@Id
private String id;

@NotNull
private String user_id;

//@DocumentReference
//private User user;

@NotNull
private String type;

@NotNull
private String url;

@NotNull
private String username;

@NotNull
private String token;
}
Loading

0 comments on commit 866a464

Please sign in to comment.