Skip to content

Commit

Permalink
Implemented method to get the assignments by consultantId or by custo…
Browse files Browse the repository at this point in the history
…merId

Added tests
  • Loading branch information
Kaj Van der Hallen committed Sep 25, 2015
1 parent 201ea7d commit 73eba34
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class Assignment {
private String consultantId;
private String customerId;

private Date startDate;
private Date endDate;
private String startDate;
private String endDate;

public Assignment(String id, String consultantId, String customerId, Date startDate, Date endDate) {
public Assignment(String id, String consultantId, String customerId, String startDate, String endDate) {
this.id = id;
this.consultantId = consultantId;
this.customerId = customerId;
Expand All @@ -29,6 +29,13 @@ public Assignment() {

}

public Assignment(String consultantId, String customerId, String startDate, String endDate) {
this.consultantId = consultantId;
this.customerId = customerId;
this.startDate = startDate;
this.endDate = endDate;
}

public String getId() {
return id;
}
Expand All @@ -53,19 +60,19 @@ public void setCustomerId(String customerId) {
this.customerId = customerId;
}

public Date getStartDate() {
public String getStartDate() {
return startDate;
}

public void setStartDate(Date startDate) {
public void setStartDate(String startDate) {
this.startDate = startDate;
}

public Date getEndDate() {
public String getEndDate() {
return endDate;
}

public void setEndDate(Date endDate) {
public void setEndDate(String endDate) {
this.endDate = endDate;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package be.foreseegroup.micro.resourceservice.assignment.service;

import be.foreseegroup.micro.resourceservice.assignment.model.Assignment;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.mongodb.repository.MongoRepository;

/**
* Created by Kaj on 24/09/15.
*/
public interface AssignmentRepository extends CrudRepository<Assignment, String> {
public interface AssignmentRepository extends MongoRepository<Assignment, String> {
Iterable<Assignment> findByConsultantId(String consultantId);
Iterable<Assignment> findByCustomerId(String customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
*/

@RestController
@RequestMapping("/assignments")
public class AssignmentService {
private static final Logger LOG = LoggerFactory.getLogger(AssignmentService.class);

@Autowired
AssignmentRepository repo;

@RequestMapping(method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.GET, value = "/assignments")
public ResponseEntity<Iterable<Assignment>> getAll() {
Iterable<Assignment> assignments = repo.findAll();
LOG.info("/assignments getAll method called, response size: {}", repo.count());
return new ResponseEntity<>(assignments, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.GET, value = "{id}")
@RequestMapping(method = RequestMethod.GET, value = "/assignments/{id}")
public ResponseEntity<Assignment> getById(@PathVariable String id) {
LOG.info("/assignments getById method called");
Assignment assignment = repo.findOne(id);
Expand All @@ -36,14 +35,28 @@ public ResponseEntity<Assignment> getById(@PathVariable String id) {
return new ResponseEntity<>(assignment, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.GET, value = "/assignmentsbycid/{consultantId}")
public ResponseEntity<Iterable<Assignment>> getByConsultantId(@PathVariable String consultantId) {
LOG.info("/contracts getByConsultantId method called");
Iterable<Assignment> assignments = repo.findByConsultantId(consultantId);
return new ResponseEntity<>(assignments, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.GET, value = "/assignmentsbycuid/{customerId}")
public ResponseEntity<Iterable<Assignment>> getByCustomerId(@PathVariable String customerId) {
LOG.info("/contracts getByCustomerId method called");
Iterable<Assignment> assignments = repo.findByCustomerId(customerId);
return new ResponseEntity<>(assignments, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.POST, value = "/assignments")
public ResponseEntity<Assignment> create(@RequestBody Assignment assignment) {
LOG.info("/assignments create method called");
Assignment createdAssignment = repo.save(assignment);
return new ResponseEntity<>(createdAssignment, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.PUT, value = "{id}")
@RequestMapping(method = RequestMethod.PUT, value = "/assignments/{id}")
public ResponseEntity<Assignment> update(@PathVariable String id, @RequestBody Assignment assignment) {
LOG.info("/assignments update method called");
Assignment update = repo.findOne(id);
Expand All @@ -57,13 +70,13 @@ public ResponseEntity<Assignment> update(@PathVariable String id, @RequestBody A
return new ResponseEntity<>(updatedAssignment, HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.DELETE, value = "{id}")
@RequestMapping(method = RequestMethod.DELETE, value = "/assignments/{id}")
public ResponseEntity<Assignment> delete(@PathVariable String id) {
LOG.info("/assignments delete method called");
Assignment assignment = repo.findOne(id);
if (assignment == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
repo.delete(assignment);
return new ResponseEntity<>(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Loading

0 comments on commit 73eba34

Please sign in to comment.