updated services and models
This commit is contained in:
parent
d7090e5d81
commit
7b6b0c61c9
|
|
@ -12,4 +12,7 @@ public interface CustomerVehicleRepository extends JpaRepository<CustomerVehicle
|
|||
|
||||
List<CustomerVehicleEntity> findAllByUser_id(Long userId);
|
||||
|
||||
boolean existsByUser_IdAndVin(Long userId, String vin);
|
||||
|
||||
void deleteByUser_IdAndVin(Long userId, String vin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,4 +104,16 @@ public class CustomerService {
|
|||
|
||||
return customerMobilePhoneRepository.save(item);
|
||||
}
|
||||
|
||||
public boolean unregisterVehicle(Long userId, String vin) {
|
||||
|
||||
if(customerVehicleRepository.existsByUser_IdAndVin(userId, vin));
|
||||
{
|
||||
customerVehicleRepository.deleteByUser_IdAndVin(userId, vin);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.customer;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
|
||||
import eu.csc.ODPAppVehOwnServer.models.MessageDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.CustomerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -13,7 +19,16 @@ public class CustomerController extends AbstractRestController {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(CustomerController.class.getSimpleName());
|
||||
|
||||
@Autowired
|
||||
private CustomerService customerService;
|
||||
|
||||
@PostMapping
|
||||
@RequestMapping("/vehicle/unregister/{vin}")
|
||||
public ResponseEntity<MessageDto> registerCustomerVehicle(@PathVariable String vin){
|
||||
|
||||
boolean done =customerService.unregisterVehicle(getLoggedInWebUserId(), vin);
|
||||
|
||||
return getSuccessResponse(new MessageDto(42, "deleted: " + done));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package eu.csc.ODPAppVehOwnServer.models;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MessageDto implements Serializable {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue