fixed bugs added client
This commit is contained in:
parent
7b6b0c61c9
commit
9064a0a9a5
|
|
@ -17,9 +17,11 @@ import javax.persistence.Table;
|
|||
@Table(name = "tlanguages")
|
||||
public class LanguageEntity extends AbstractEntity {
|
||||
|
||||
@Column(unique = true)
|
||||
private String locale;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(nullable = false, name = "is_standard")
|
||||
private boolean isStandard;
|
||||
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ public class CustomerService {
|
|||
|
||||
public CustomerDeviceEntity registerDevice(Long userId, String serialnumber) {
|
||||
|
||||
var deviceArticle = deviceService.findOrThrowBySerialnumber(serialnumber);
|
||||
var deviceArticle = deviceService.findDeviceArticleBySerialnumber(serialnumber);
|
||||
|
||||
CustomerDeviceEntity entity = new CustomerDeviceEntity();
|
||||
entity.fillData(deviceArticle);
|
||||
entity.fillData(deviceArticle.get());
|
||||
entity.setUser_id(userId);
|
||||
|
||||
|
||||
|
|
@ -101,19 +101,18 @@ public class CustomerService {
|
|||
|
||||
item.setAccessToken(utilsService.generateAccessToken());
|
||||
|
||||
|
||||
return customerMobilePhoneRepository.save(item);
|
||||
}
|
||||
|
||||
public boolean unregisterVehicle(Long userId, String vin) {
|
||||
|
||||
if(customerVehicleRepository.existsByUser_IdAndVin(userId, vin));
|
||||
if(customerVehicleRepository.existsByUser_IdAndVin(userId, vin))
|
||||
{
|
||||
customerVehicleRepository.deleteByUser_IdAndVin(userId, vin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import eu.csc.ODPAppVehOwnServer.persistence.respository.LanguageRepository;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DataService {
|
||||
|
||||
|
|
@ -12,6 +14,9 @@ public class DataService {
|
|||
private LanguageRepository languageRepository;
|
||||
|
||||
|
||||
public List<LanguageEntity> getLanguages(){
|
||||
return languageRepository.findAll();
|
||||
}
|
||||
|
||||
public LanguageEntity getOrAddLanguage(String locale, String name, boolean isDefault){
|
||||
|
||||
|
|
@ -24,6 +29,5 @@ public class DataService {
|
|||
}
|
||||
|
||||
return languageEntity;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ public class DeviceService {
|
|||
return deviceArticleRepository.findByDeviceDevicenumberAndSerialNumber(devicenumber, name);
|
||||
}
|
||||
|
||||
public DeviceArticleEntity findOrThrowBySerialnumber( String serialnumber) {
|
||||
return findBySerialnumber(serialnumber).orElseThrow();
|
||||
public DeviceEntity findOrThrowByDeviceNumber( String deviceNumber) {
|
||||
return findByDeviceNumber(deviceNumber).orElseThrow();
|
||||
}
|
||||
public Optional<DeviceArticleEntity> findBySerialnumber( String serialnumber) {
|
||||
return deviceArticleRepository.findBySerialNumber(serialnumber);
|
||||
public Optional<DeviceEntity> findByDeviceNumber( String devicenumber) {
|
||||
return deviceRepository.findByDevicenumber(devicenumber);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.data;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.DataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -13,6 +15,9 @@ import java.util.List;
|
|||
@RequestMapping("languages")
|
||||
public class LanguageController {
|
||||
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<LanguageDto>> showLanguages(){
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.data;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.PropulsionTypeDto;
|
||||
import lombok.var;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/propulsiontypes")
|
||||
public class PropulsionTypeController {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<PropulsionTypeDto>> showPropulsionType(){
|
||||
|
||||
var result = new ArrayList<PropulsionTypeDto>();
|
||||
//result.add(new LanguageDto("en", "English"));
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,13 +3,11 @@ package eu.csc.ODPAppVehOwnServer.web.clients;
|
|||
import eu.csc.ODPAppVehOwnServer.client.ClientFactory;
|
||||
import eu.csc.ODPAppVehOwnServer.client.clients.VehOwnAppClient;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.AuthenticationService;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.DataClientService;
|
||||
import eu.csc.ODPAppVehOwnServer.models.regist.UserVehicleRegistrationDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceArticleEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.CustomerService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.DeviceService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.GsonService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.VehicleService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
|
@ -27,6 +25,7 @@ public abstract class AbstractClientTester {
|
|||
protected VehOwnAppClient client;
|
||||
|
||||
protected AuthenticationService authenticationService;
|
||||
protected DataClientService dataClientService;
|
||||
|
||||
|
||||
@Autowired
|
||||
|
|
@ -42,6 +41,8 @@ public abstract class AbstractClientTester {
|
|||
|
||||
@Autowired
|
||||
protected CustomerService customerService;
|
||||
@Autowired
|
||||
protected DataService dataService;
|
||||
|
||||
|
||||
|
||||
|
|
@ -71,7 +72,7 @@ public abstract class AbstractClientTester {
|
|||
|
||||
|
||||
protected void setUpDevices(){
|
||||
if(!deviceService.findBySerialnumber(deviceA.getDevicenumber()).isPresent()){
|
||||
if(!deviceService.findByDeviceNumber(deviceA.getDevicenumber()).isPresent()){
|
||||
deviceService.addDevice(deviceA.getDevicenumber(), deviceA.getName(), deviceA.getManufacturer());
|
||||
}
|
||||
|
||||
|
|
@ -90,10 +91,15 @@ public abstract class AbstractClientTester {
|
|||
|
||||
protected void initTestData(){
|
||||
|
||||
setUpLanguages();
|
||||
setUpDevices();
|
||||
setUpVehicles();
|
||||
}
|
||||
|
||||
private void setUpLanguages() {
|
||||
dataService.getOrAddLanguage("en", "English", true);
|
||||
}
|
||||
|
||||
private void setUpVehicles() {
|
||||
vehicleService.addVehicleIfNotExists("ford", "Ford");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package eu.csc.ODPAppVehOwnServer.web.clients;
|
|||
import com.mysql.cj.xdevapi.Client;
|
||||
import eu.csc.ODPAppVehOwnServer.ODPAppVehOwnServerApplication;
|
||||
import eu.csc.ODPAppVehOwnServer.client.ClientFactory;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.DataClientService;
|
||||
import eu.csc.ODPAppVehOwnServer.models.UserRegistrationDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.regist.UserVehicleRegistrationDto;
|
||||
import lombok.var;
|
||||
|
|
@ -33,11 +34,24 @@ public class CustomerClientTester extends AbstractClientTester{
|
|||
this.token = ClientFactory.authenticate(url, this.user, this.password).body().getToken();
|
||||
client = ClientFactory.createVehOwnAppClient(this.url, this.token);
|
||||
|
||||
|
||||
this.dataClientService = ClientFactory.createService(this.url, DataClientService.class);
|
||||
this.initTestData();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testLanguages(){
|
||||
Assertions.assertNotNull(this.client);
|
||||
|
||||
var result = Assertions.assertDoesNotThrow(
|
||||
() -> dataClientService.listLanguages().execute());
|
||||
|
||||
|
||||
Assertions.assertNotNull(result.body());
|
||||
Assertions.assertTrue(result.isSuccessful());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLogging(){
|
||||
Assertions.assertNotNull(this.client);
|
||||
|
|
|
|||
|
|
@ -28,4 +28,12 @@ public interface DataClientService {
|
|||
@GET("/api/devices/")
|
||||
Call<List<DeviceDto>> listDevices();
|
||||
|
||||
|
||||
//region Languages
|
||||
|
||||
@GET("/api/languages")
|
||||
Call<List<LanguageDto>> listLanguages();
|
||||
|
||||
//endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,4 @@ import lombok.NoArgsConstructor;
|
|||
public class LanguageDto {
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue