Skip to content

Commit

Permalink
Deployments (#13)
Browse files Browse the repository at this point in the history
* Changed deployment object structure

* Removed '_' from deployment variable

* Added NotNull annotation to requested fields (deployment object)
  • Loading branch information
theioakiti authored Dec 13, 2022
1 parent 4affdb2 commit 3dc9dbc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.config.EnableMongoAuditing;

@SpringBootApplication
@EnableMongoAuditing
public class DbApiApplication {
public static void main(String[] args) {
SpringApplication.run(DbApiApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public class DeploymentController {
@GetMapping("/deployments")
public List<Deployment> getAllDeployments(@RequestParam(value = "user_id",required = false) String userId,
@RequestParam(value = "service_id",required = false) String serviceId,
@RequestParam(value = "workflow_id",required = false) String workflowId) {
@RequestParam(value = "workflow_id",required = false) String workflowId,
@RequestParam(value = "user",required = false) String user,
@RequestParam(value = "service_url",required = false) String service_url,
@RequestParam(value = "project",required = false) String project) {
Query query = new Query();
if (userId != null) {
query.addCriteria(Criteria.where("user_id").is(userId));
Expand All @@ -37,6 +40,15 @@ public List<Deployment> getAllDeployments(@RequestParam(value = "user_id",requir
if (workflowId != null) {
query.addCriteria(Criteria.where("workflow_id").is(workflowId));
}
if (user != null) {
query.addCriteria(Criteria.where("user").is(user));
}
if (service_url != null) {
query.addCriteria(Criteria.where("service_url").is(service_url));
}
if (project != null) {
query.addCriteria(Criteria.where("project").is(project));
}
return template.find(query, Deployment.class, "deployments");
//return repository.findAll();
}
Expand All @@ -49,8 +61,8 @@ public Optional<Deployment> getDeployment(@PathVariable("id") String id) {
@PostMapping("/deployments")
public ResponseEntity<Deployment> createDeployment(@RequestBody @Valid Deployment deployment) {
try {
Deployment _deployment = repository.save(deployment);
return new ResponseEntity<>(_deployment, HttpStatus.CREATED);
Deployment db_deployment = repository.save(deployment);
return new ResponseEntity<>(db_deployment, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand All @@ -62,19 +74,26 @@ public ResponseEntity<Deployment> updateDeployment(@PathVariable("id") String id
Optional<Deployment> deploymentData = repository.findById(id);

if (deploymentData.isPresent()) {
Deployment _deployment = deploymentData.get();
_deployment.setUser_id(deployment.getUser_id());
_deployment.setGit_credentials_id(deployment.getGit_credentials_id());
_deployment.setName(deployment.getName());
_deployment.setUrl(deployment.getUrl());
_deployment.setWorkflow_id(deployment.getWorkflow_id());
_deployment.setService_id(deployment.getService_id());
_deployment.setVersion(deployment.getVersion());
_deployment.setState(deployment.getState());
_deployment.setCreated(deployment.getCreated());
_deployment.setUpdated(deployment.getUpdated());
Deployment db_deployment = deploymentData.get();
db_deployment.setUser_id(deployment.getUser_id());
db_deployment.setUser(deployment.getUser());
db_deployment.setGit_credentials_id(deployment.getGit_credentials_id());
db_deployment.setName(deployment.getName());
//db_deployment.setUrl(deployment.getUrl());
db_deployment.setService_url(deployment.getService_url());
db_deployment.setProject(deployment.getProject());
db_deployment.setPort(deployment.getPort());
db_deployment.setReplicas(deployment.getReplicas());
db_deployment.setK8s_url(deployment.getK8s_url());
db_deployment.setWorkflow_id(deployment.getWorkflow_id());
db_deployment.setService_id(deployment.getService_id());
db_deployment.setVersion(deployment.getVersion());
db_deployment.setState(deployment.getState());
db_deployment.setCreated(deployment.getCreated());
//db_deployment.setUpdated(deployment.getUpdated());
db_deployment.setStopped(deployment.getStopped());

return new ResponseEntity<>(repository.save(_deployment), HttpStatus.OK);
return new ResponseEntity<>(repository.save(db_deployment), HttpStatus.OK);
}
else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;
import org.springframework.data.mongodb.core.mapping.Field;
Expand All @@ -21,6 +23,8 @@ public class Deployment {
@NotNull
private String user_id;

private String user;

//@DocumentReference
//private User user;

Expand All @@ -33,10 +37,21 @@ public class Deployment {
@NotNull
private String name;

@NotNull
private String url;
private String project;

//@NotNull
//private String url;

@NotNull
private String service_url;

private String k8s_url;

private Integer port;

private Integer replicas;

//@NotNull
private String workflow_id;

//@DocumentReference
Expand All @@ -57,10 +72,17 @@ public class Deployment {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Field("created_at")
@JsonProperty("created_at")
@CreatedDate
private Date created;

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Field("updated_at")
@JsonProperty("updated_at")
@LastModifiedDate
private Date updated;

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Field("stopped_at")
@JsonProperty("stopped_at")
private Date stopped;
}

0 comments on commit 3dc9dbc

Please sign in to comment.