Skip to content
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

Put routes #13

Merged
merged 3 commits into from
Jul 4, 2024
Merged
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
21 changes: 21 additions & 0 deletions src/main/java/com/maires/wnet/controller/EquipmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.ResponseStatus;
Expand Down Expand Up @@ -106,4 +107,24 @@ public ResponseEntity<Map<String, String>> dissociateEquipment(@PathVariable Lon
return equipmentService.dissociateEquipment(equipmentId);
}

/**
* Update equipment dto.
*
* @param equipmentId the equipment id
* @param equipmentCreationDto the equipment creation dto
* @return the equipment dto
* @throws EquipmentNotFoundException the equipment not found exception
*/
@PutMapping("/{equipmentId}")
public EquipmentDto updateEquipment(
@PathVariable Long equipmentId,
@RequestBody EquipmentCreationDto equipmentCreationDto
) throws EquipmentNotFoundException {

Equipment equipmentToUpdate = equipmentService.updateEquipment(equipmentId,
equipmentCreationDto.toEntity());

return EquipmentDto.fromEntity(equipmentToUpdate);
}

}
22 changes: 21 additions & 1 deletion src/main/java/com/maires/wnet/controller/PlanController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.ResponseStatus;
Expand Down Expand Up @@ -80,7 +81,8 @@ public PlanDto createPlan(@RequestBody PlanCreationDto planCreationDto) {
*
* @param planId the plan id
* @return the plan dto
* @throws PlanNotFoundException the plan not found exception
* @throws PlanNotFoundException the plan not found exception
* @throws PlanCannotBeExcludedException the plan cannot be excluded exception
*/
@DeleteMapping("/{planId}")
public PlanDto removePlanById(@PathVariable Long planId)
Expand All @@ -90,4 +92,22 @@ public PlanDto removePlanById(@PathVariable Long planId)
);
}

/**
* Update plan dto.
*
* @param planId the plan id
* @param planCreationDto the plan creation dto
* @return the plan dto
* @throws PlanNotFoundException the plan not found exception
*/
@PutMapping("/{planId}")
public PlanDto updatePlan(
@PathVariable Long planId,
@RequestBody PlanCreationDto planCreationDto
) throws PlanNotFoundException {

Plan planToUpdate = planService.updatePlan(planId, planCreationDto.toEntity());

return PlanDto.fromEntity(planToUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.ResponseStatus;
Expand Down Expand Up @@ -81,7 +82,8 @@ public TechnicianDto createTechnician(@RequestBody TechnicianCreationDto technic
*
* @param technicianId the technician id
* @return the technician dto
* @throws TechnicianNotFoundException the technician not found exception
* @throws TechnicianNotFoundException the technician not found exception
* @throws TechnicianCannotBeExcludedException the technician cannot be excluded exception
*/
@DeleteMapping("/{technicianId}")
public TechnicianDto removeTechnicianById(@PathVariable Long technicianId)
Expand All @@ -91,4 +93,24 @@ public TechnicianDto removeTechnicianById(@PathVariable Long technicianId)
);
}

/**
* Update technician dto.
*
* @param technicianId the technician id
* @param technicianCreationDto the technician creation dto
* @return the technician dto
* @throws TechnicianNotFoundException the technician not found exception
*/
@PutMapping("/{technicianId}")
public TechnicianDto updateTechnician(
@PathVariable Long technicianId,
@RequestBody TechnicianCreationDto technicianCreationDto
) throws TechnicianNotFoundException {

Technician updatedTechnician = technicianService.updateTechnician(technicianId,
technicianCreationDto.toEntity());

return TechnicianDto.fromEntity(updatedTechnician);
}

}
22 changes: 22 additions & 0 deletions src/main/java/com/maires/wnet/service/EquipmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,26 @@ public ResponseEntity<Map<String, String>> dissociateEquipment(Long equipmentId)
Map<String, String> response = Map.of("message", "Equipment successful dissociated!");
return ResponseEntity.ok(response);
}


/**
* Update equipment.
*
* @param equipmentId the equipment id
* @param equipment the equipment
* @return the equipment
* @throws EquipmentNotFoundException the equipment not found exception
*/
public Equipment updateEquipment(Long equipmentId, Equipment equipment)
throws EquipmentNotFoundException {
Equipment equipmentToUpdate = findEquipmentById(equipmentId);

equipmentToUpdate.setType(equipment.getType());
equipmentToUpdate.setModel(equipment.getModel());
equipmentToUpdate.setSerialNumber(equipment.getSerialNumber());
equipmentToUpdate.setManufacturer(equipment.getManufacturer());

return equipmentRepository.save(equipmentToUpdate);

}
}
21 changes: 20 additions & 1 deletion src/main/java/com/maires/wnet/service/PlanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public Plan createPlan(Plan plan) {
*
* @param planId the plan id
* @return the plan
* @throws PlanNotFoundException the plan not found exception
* @throws PlanNotFoundException the plan not found exception
* @throws PlanCannotBeExcludedException the plan cannot be excluded exception
*/
public Plan removePlanById(Long planId)
throws PlanNotFoundException, PlanCannotBeExcludedException {
Expand All @@ -74,4 +75,22 @@ public Plan removePlanById(Long planId)
planRepository.delete(deletedPlan);
return deletedPlan;
}

/**
* Update plan plan.
*
* @param planId the plan id
* @param plan the plan
* @return the plan
* @throws PlanNotFoundException the plan not found exception
*/
public Plan updatePlan(Long planId, Plan plan) throws PlanNotFoundException {
Plan planToUpdate = findPlanById(planId);

planToUpdate.setName(plan.getName());
planToUpdate.setSpeed(plan.getSpeed());
planToUpdate.setPrice(plan.getPrice());

return planRepository.save(planToUpdate);
}
}
23 changes: 22 additions & 1 deletion src/main/java/com/maires/wnet/service/TechnicianService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public Technician createTechnician(Technician technician) {
*
* @param technicianId the technician id
* @return the technician
* @throws TechnicianNotFoundException the technician not found exception
* @throws TechnicianNotFoundException the technician not found exception
* @throws TechnicianCannotBeExcludedException the technician cannot be excluded exception
*/
public Technician removeTechnicianById(Long technicianId)
throws TechnicianNotFoundException, TechnicianCannotBeExcludedException {
Expand All @@ -76,4 +77,24 @@ public Technician removeTechnicianById(Long technicianId)
technicianRepository.delete(deletedTechnician);
return deletedTechnician;
}

/**
* Update technician technician.
*
* @param technicianId the technician id
* @param technician the technician
* @return the technician
* @throws TechnicianNotFoundException the technician not found exception
*/
public Technician updateTechnician(Long technicianId, Technician technician)
throws TechnicianNotFoundException {

Technician technicianToUpdate = findTechnicianById(technicianId);

technicianToUpdate.setName(technician.getName());
technicianToUpdate.setPhone(technician.getPhone());
technicianToUpdate.setEmail(technician.getEmail());

return technicianRepository.save(technicianToUpdate);
}
}
Loading