Skip to content

Commit

Permalink
modify response data
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyuanzhao000 committed May 3, 2020
1 parent 52a62b5 commit 663d4f5
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AssuranceServiceImpl implements AssuranceService {
public Response findAssuranceById(UUID id, HttpHeaders headers) {
Assurance assurance = assuranceRepository.findById(id);
if (assurance == null) {
return new Response<>(0, "No Conotent by this id", id);
return new Response<>(0, "No Conotent by this id", null);
} else {
return new Response<>(1, "Find Assurace Success", assurance);
}
Expand All @@ -38,7 +38,7 @@ public Response findAssuranceById(UUID id, HttpHeaders headers) {
public Response findAssuranceByOrderId(UUID orderId, HttpHeaders headers) {
Assurance assurance = assuranceRepository.findByOrderId(orderId);
if (assurance == null) {
return new Response<>(0, "No Content by this orderId", orderId);
return new Response<>(0, "No Content by this orderId", null);
} else {
return new Response<>(1, "Find Assurace Success", assurance);
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public Response deleteById(UUID assuranceId, HttpHeaders headers) {
Assurance a = assuranceRepository.findById(assuranceId);
if (a == null) {
AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][DeleteAssurance] Success.");
return new Response<>(1, "Delete Success with Assurance id", a);
return new Response<>(1, "Delete Success with Assurance id", null);
} else {
AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][DeleteAssurance] Fail.Assurance not clear.");
return new Response<>(0, "Fail.Assurance not clear", assuranceId);
Expand All @@ -81,7 +81,7 @@ public Response deleteByOrderId(UUID orderId, HttpHeaders headers) {
Assurance isExistAssurace = assuranceRepository.findByOrderId(orderId);
if (isExistAssurace == null) {
AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][DeleteAssurance] Success.");
return new Response<>(1, "Delete Success with Order Id", isExistAssurace);
return new Response<>(1, "Delete Success with Order Id", null);
} else {
AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][DeleteAssurance] Fail.Assurance not clear.");
return new Response<>(0, "Fail.Assurance not clear", orderId);
Expand All @@ -94,7 +94,7 @@ public Response modify(String assuranceId, String orderId, int typeIndex, HttpHe
Assurance oldAssurance = (Assurance) oldAssuranceResponse.getData();
if (oldAssurance == null) {
AssuranceServiceImpl.LOGGER.info("[Assurance-Modify-Service][ModifyAssurance] Fail.Assurance not found.");
return new Response<>(0, "Fail.Assurance not found.", assuranceId);
return new Response<>(0, "Fail.Assurance not found.", null);
} else {
AssuranceType at = AssuranceType.getTypeByIndex(typeIndex);
if (at != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFindAssuranceById1() {
UUID id = UUID.randomUUID();
Mockito.when(assuranceRepository.findById(id)).thenReturn(null);
Response result = assuranceServiceImpl.findAssuranceById(id, headers);
Assert.assertEquals(new Response<>(0, "No Conotent by this id", id), result);
Assert.assertEquals(new Response<>(0, "No Conotent by this id", null), result);
}

@Test
Expand All @@ -59,7 +59,7 @@ public void testFindAssuranceByOrderId1() {
UUID orderId = UUID.randomUUID();
Mockito.when(assuranceRepository.findByOrderId(orderId)).thenReturn(null);
Response result = assuranceServiceImpl.findAssuranceByOrderId(orderId, headers);
Assert.assertEquals(new Response<>(0, "No Content by this orderId", orderId), result);
Assert.assertEquals(new Response<>(0, "No Content by this orderId", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Response calculateRefund(String orderId, HttpHeaders headers) {
|| order.getStatus() == OrderStatus.PAID.getCode()) {
if (order.getStatus() == OrderStatus.NOTPAID.getCode()) {
CancelServiceImpl.LOGGER.info("[Cancel Order][Refund Price] From Order Service.Not Paid.");
return new Response<>(1, "Success. Refoud 0", 0);
return new Response<>(1, "Success. Refoud 0", "0");
} else {
CancelServiceImpl.LOGGER.info("[Cancel Order][Refund Price] From Order Service.Paid.");
return new Response<>(1, "Success. ", calculateRefund(order));
Expand All @@ -166,7 +166,7 @@ public Response calculateRefund(String orderId, HttpHeaders headers) {
|| order.getStatus() == OrderStatus.PAID.getCode()) {
if (order.getStatus() == OrderStatus.NOTPAID.getCode()) {
CancelServiceImpl.LOGGER.info("[Cancel Order][Refund Price] From Order Other Service.Not Paid.");
return new Response<>(1, "Success, Refound 0", 0);
return new Response<>(1, "Success, Refound 0", "0");
} else {
CancelServiceImpl.LOGGER.info("[Cancel Order][Refund Price] From Order Other Service.Paid.");
return new Response<>(1, "Success", calculateRefund(order));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ConfigServiceImpl implements ConfigService {
public Response create(Config info, HttpHeaders headers) {
if (repository.findByName(info.getName()) != null) {
String result = config0 + info.getName() + " already exists.";
return new Response<>(0, "Already exists.", result);
return new Response<>(0, result, null);
} else {
Config config = new Config(info.getName(), info.getValue(), info.getDescription());
repository.save(config);
Expand All @@ -38,7 +38,7 @@ public Response create(Config info, HttpHeaders headers) {
public Response update(Config info, HttpHeaders headers) {
if (repository.findByName(info.getName()) == null) {
String result = config0 + info.getName() + " doesn't exist.";
return new Response<>(0, "Doesn't exist.", result);
return new Response<>(0, result, null);
} else {
Config config = new Config(info.getName(), info.getValue(), info.getDescription());
repository.save(config);
Expand All @@ -62,7 +62,7 @@ public Response delete(String name, HttpHeaders headers) {
Config config = repository.findByName(name);
if (config == null) {
String result = config0 + name + " doesn't exist.";
return new Response<>(0, "Doesn't exist.", result);
return new Response<>(0, result, null);
} else {
repository.deleteByName(name);
return new Response<>(1, "Delete success", config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testCreate1() {
Config info = new Config();
Mockito.when(repository.findByName(info.getName())).thenReturn(info);
Response result = configServiceImpl.create(info, headers);
Assert.assertEquals(new Response<>(0, "Already exists.", "Config already exists."), result);
Assert.assertEquals(new Response<>(0, "Config already exists.", null), result);
}

@Test
Expand All @@ -55,7 +55,7 @@ public void testUpdate1() {
Config info = new Config();
Mockito.when(repository.findByName(info.getName())).thenReturn(null);
Response result = configServiceImpl.update(info, headers);
Assert.assertEquals(new Response<>(0, "Doesn't exist.", "Config doesn't exist."), result);
Assert.assertEquals(new Response<>(0, "Config doesn't exist.", null), result);
}

@Test
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testQuery2() {
public void testDelete1() {
Mockito.when(repository.findByName("name")).thenReturn(null);
Response result = configServiceImpl.delete("name", headers);
Assert.assertEquals(new Response<>(0, "Doesn't exist.", "Config name doesn't exist."), result);
Assert.assertEquals(new Response<>(0, "Config name doesn't exist.", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Response insertConsignRecord(Consign consignRequest, HttpHeaders headers)
log.info("SAVE consign info : " + consignRecord.toString());
ConsignRecord result = repository.save(consignRecord);
log.info("SAVE consign result : " + result.toString());
return new Response<>(1, "You have consigned successfully! The price is " + result.getPrice(), +result.getPrice());
return new Response<>(1, "You have consigned successfully! The price is " + result.getPrice(), result);
}

@Override
Expand Down Expand Up @@ -111,7 +111,7 @@ public Response queryByAccountId(UUID accountId, HttpHeaders headers) {
if (consignRecords != null && !consignRecords.isEmpty()) {
return new Response<>(1, "Find consign by account id success", consignRecords);
}else {
return new Response<>(0, "No Content according to accountId", accountId);
return new Response<>(0, "No Content according to accountId", null);
}
}

Expand All @@ -121,7 +121,7 @@ public Response queryByOrderId(UUID orderId, HttpHeaders headers) {
if (consignRecords != null ) {
return new Response<>(1, "Find consign by order id success", consignRecords);
}else {
return new Response<>(0, "No Content according to order id", orderId);
return new Response<>(0, "No Content according to order id", null);
}
}

Expand All @@ -131,7 +131,7 @@ public Response queryByConsignee(String consignee, HttpHeaders headers) {
if (consignRecords != null && !consignRecords.isEmpty()) {
return new Response<>(1, "Find consign by consignee success", consignRecords);
}else {
return new Response<>(0, "No Content according to consignee", consignee);
return new Response<>(0, "No Content according to consignee", null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testInsertConsignRecord() {
})).thenReturn(re);
Mockito.when(repository.save(Mockito.any(ConsignRecord.class))).thenReturn(consignRecord);
Response result = consignServiceImpl.insertConsignRecord(consignRequest, headers);
Assert.assertEquals(new Response<>(1, "You have consigned successfully! The price is 3.0", 3.0), result);
Assert.assertEquals(new Response<>(1, "You have consigned successfully! The price is 3.0", consignRecord), result);
}

@Test
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testQueryByAccountId2() {
UUID accountId = UUID.randomUUID();
Mockito.when(repository.findByAccountId(Mockito.any(UUID.class))).thenReturn(null);
Response result = consignServiceImpl.queryByAccountId(accountId, headers);
Assert.assertEquals(new Response<>(0, "No Content according to accountId", accountId), result);
Assert.assertEquals(new Response<>(0, "No Content according to accountId", null), result);
}

@Test
Expand All @@ -120,7 +120,7 @@ public void testQueryByOrderId2() {
UUID orderId = UUID.randomUUID();
Mockito.when(repository.findByOrderId(Mockito.any(UUID.class))).thenReturn(null);
Response result = consignServiceImpl.queryByOrderId(orderId, headers);
Assert.assertEquals(new Response<>(0, "No Content according to order id", orderId), result);
Assert.assertEquals(new Response<>(0, "No Content according to order id", null), result);
}

@Test
Expand All @@ -136,7 +136,7 @@ public void testQueryByConsignee1() {
public void testQueryByConsignee2() {
Mockito.when(repository.findByConsignee(Mockito.anyString())).thenReturn(null);
Response result = consignServiceImpl.queryByConsignee("consignee", headers);
Assert.assertEquals(new Response<>(0, "No Content according to consignee", "consignee"), result);
Assert.assertEquals(new Response<>(0, "No Content according to consignee", null), result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Response createContacts(Contacts contacts, HttpHeaders headers) {
return new Response<>(0, "Already Exists", contactsTemp);
} else {
contactsRepository.save(contacts);
return new Response<>(1, "Create Success", contactsTemp);
return new Response<>(1, "Create Success", null);
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public Response modify(Contacts contacts, HttpHeaders headers) {
Contacts oldContacts = (Contacts) oldContactResponse.getData();
if (oldContacts == null) {
ContactsServiceImpl.LOGGER.info("[Contacts-Modify-Service][ModifyContacts] Fail.Contacts not found.");
return new Response<>(0, "Contacts not found", oldContacts);
return new Response<>(0, "Contacts not found", null);
} else {
oldContacts.setName(contacts.getName());
oldContacts.setDocumentType(contacts.getDocumentType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Response getFoodStoresByStationIds(List<String> stationIds) {
if (foodStoreList != null) {
return new Response<>(1, success, foodStoreList);
} else {
return new Response<>(0, noContent, foodStoreList);
return new Response<>(0, noContent, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Response getSoldTickets(Seat seatRequest, HttpHeaders headers) {
public Response findOrderById(UUID id, HttpHeaders headers) {
Order order = orderOtherRepository.findById(id);
if (order == null) {
return new Response<>(0, "No Content by this id", id);
return new Response<>(0, "No Content by this id", null);
} else {
return new Response<>(1, success, order);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testFindOrderById1() {
UUID id = UUID.randomUUID();
Mockito.when(orderOtherRepository.findById(Mockito.any(UUID.class))).thenReturn(null);
Response result = orderOtherServiceImpl.findOrderById(id, headers);
Assert.assertEquals(new Response<>(0, "No Content by this id", id), result);
Assert.assertEquals(new Response<>(0, "No Content by this id", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Response getSoldTickets(Seat seatRequest, HttpHeaders headers) {
public Response findOrderById(UUID id, HttpHeaders headers) {
Order order = orderRepository.findById(id);
if (order == null) {
return new Response<>(0, "No Content by this id", id);
return new Response<>(0, "No Content by this id", null);
} else {
return new Response<>(1, success, order);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testFindOrderById1() {
UUID id = UUID.randomUUID();
Mockito.when(orderRepository.findById(Mockito.any(UUID.class))).thenReturn(null);
Response result = orderServiceImpl.findOrderById(id, headers);
Assert.assertEquals(new Response<>(0, "No Content by this id", id), result);
Assert.assertEquals(new Response<>(0, "No Content by this id", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Response findByRouteIdAndTrainType(String routeId, String trainType, Http
PriceServiceImpl.LOGGER.info("[Price Service][Find By Route Id And Train Type]");

if (priceConfig == null) {
return new Response<>(0, noThatConfig, routeId + trainType);
return new Response<>(0, noThatConfig, null);
} else {
return new Response<>(1, "Success", priceConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testFindById() {
public void testFindByRouteIdAndTrainType1() {
Mockito.when(priceConfigRepository.findByRouteIdAndTrainType(Mockito.anyString(), Mockito.anyString())).thenReturn(null);
Response result = priceServiceImpl.findByRouteIdAndTrainType("route_id", "train_type", headers);
Assert.assertEquals(new Response<>(0, "No that config", "route_idtrain_type"), result);
Assert.assertEquals(new Response<>(0, "No that config", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Response deleteRoute(String routeId, HttpHeaders headers) {
public Response getRouteById(String routeId, HttpHeaders headers) {
Route route = routeRepository.findById(routeId);
if (route == null) {
return new Response<>(0, "No content with the routeId", routeId);
return new Response<>(0, "No content with the routeId", null);
} else {
return new Response<>(1, success, route);
}
Expand All @@ -109,7 +109,7 @@ public Response getRouteByStartAndTerminal(String startId, String terminalId, Ht
if (!resultList.isEmpty()) {
return new Response<>(1, success, resultList);
} else {
return new Response<>(0, "No routes with the startId and terminalId", startId + " -- " + terminalId);
return new Response<>(0, "No routes with the startId and terminalId", null);
}
}

Expand All @@ -119,7 +119,7 @@ public Response getAllRoutes(HttpHeaders headers) {
if (routes != null && !routes.isEmpty()) {
return new Response<>(1, success, routes);
} else {
return new Response<>(0, "No Content", routes);
return new Response<>(0, "No Content", null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testDeleteRoute2() {
public void testGetRouteById1() {
Mockito.when(routeRepository.findById(Mockito.anyString())).thenReturn(null);
Response result = routeServiceImpl.getRouteById("route_id", headers);
Assert.assertEquals(new Response<>(0, "No content with the routeId", "route_id"), result);
Assert.assertEquals(new Response<>(0, "No content with the routeId", null), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean exist(String stationName, HttpHeaders headers) {
public Response update(Station info, HttpHeaders headers) {

if (repository.findById(info.getId()) == null) {
return new Response<>(0, "Station not exist", info);
return new Response<>(0, "Station not exist", null);
} else {
Station station = new Station(info.getId(), info.getName());
station.setStayTime(info.getStayTime());
Expand All @@ -60,7 +60,7 @@ public Response delete(Station info, HttpHeaders headers) {
repository.delete(station);
return new Response<>(1, "Delete success", station);
}
return new Response<>(0, "Station not exist", info);
return new Response<>(0, "Station not exist", null);
}

@Override
Expand Down Expand Up @@ -100,7 +100,7 @@ public Response queryForIdBatch(List<String> nameList, HttpHeaders headers) {
if (!result.isEmpty()) {
return new Response<>(1, success, result);
} else {
return new Response<>(0, "No content according to name list", nameList);
return new Response<>(0, "No content according to name list", null);
}

}
Expand Down
Loading

0 comments on commit 663d4f5

Please sign in to comment.