public AnnotationBasedResourceDescription(Class<?> type, ResourceDescription fallback) { Description description = AnnotationUtils.findAnnotation(type, Description.class); this.message = description == null ? null : description.value(); this.fallback = fallback; }
/** * 商品限购,这也算一种 [ 库存不足 ] 的异常,还应该让客户知道,什么时候解除限制 * Created by helloztt on 2017/8/23. */ @Getter @Setter public class MainGoodLimitStockException extends MainGoodLowStockException { @Description("限购解除时间") private final Map<MainGood,LocalDateTime> relieveTime; public MainGoodLimitStockException(Map<MainGood,Integer> goodStock,Map<MainGood,LocalDateTime> relieveTime) { super(goodStock); this.relieveTime = relieveTime; } }
@RestResource(rel = "by-name", description = @Description("Find by name")) public Restaurant findFirstByName(@Param("name") String name); }
/** * 商品库存不足提醒,应该让用户知道,是哪个商品库存不够 * Created by helloztt on 2017/8/23. */ @AllArgsConstructor @Getter @Setter public class MainGoodLowStockException extends ServletException { @Description("限购商品") private final Map<MainGood,Integer> usableGoodStock; public JSONArray toData(){ JSONArray jsonArray = new JSONArray(); usableGoodStock.keySet().forEach(mainGood -> { JSONObject jsonObject = new JSONObject(); jsonObject.put("goodId",mainGood.getId()); jsonObject.put("stock",usableGoodStock.get(mainGood)); jsonArray.add(jsonObject); }); return jsonArray; } }
/** * Creates a new {@link AnnotationBasedResourceDescription} for the given {@link Description} and fallback. * * @param description must not be {@literal null}. * @param fallback must not be {@literal null}. */ public AnnotationBasedResourceDescription(Description description, ResourceDescription fallback) { Assert.notNull(description, "Description must not be null!"); Assert.notNull(fallback, "Fallback resource description must not be null!"); this.message = description.value(); this.fallback = fallback; }
@RestResource(rel = "by-id", description = @Description("find payment by id")) Payment findPaymentById(@Param("id") String id); }
@Override public ResourceDescription getItemResourceDescription() { ResourceDescription fallback = SimpleResourceDescription.defaultFor(getItemResourceRel()); if (annotation != null && StringUtils.hasText(annotation.description().value())) { return new AnnotationBasedResourceDescription(annotation.description(), fallback); } if (description != null) { return new AnnotationBasedResourceDescription(description, fallback); } return fallback; }
@RestResource(rel = "by-name", description = @Description("Find by name")) public Restaurant findFirstByName(@Param("name") String name); }
@RestResource(rel = "by-rid", description = @Description("Get all menuitems by restaurant id")) public List<MenuItem> findAllByRestaurantId(String rid);
@RestResource(rel = "find-by-id", description = @Description("Find by id")) public Order findFirstById(@Param("id") String id);
@RestResource(rel = "by-name", description = @Description("Get menuitem by item name")) public MenuItem findByName(@Param("name") String name); }
@RestResource(rel = "save", description = @Description("Save order")) Order save(@Param("order") Order order); }
@RestResource(rel = "by-name", description = @Description("Get menuitem by item name")) public MenuItem findByName(@Param("name") String name); }
@RestResource(rel = "by-rid", description = @Description("Get all menuitems by restaurant id")) public List<MenuItem> findAllByRestaurantId(String rid);
@RestResource(rel = "by-location", description = @Description("Find by location, comma separated, e.g. 'lat,long', and distance, e.g. '50km'") ) SupplyLocation findFirstByLocationNear(@Param("location") Point location);
@RestResource(rel = "save", description = @Description("Save order")) Order save(@Param("order") Order order); }
@RestResource(rel = "by-id", description = @Description("find payment by id")) Payment findPaymentById(@Param("id") String id); }
@RestResource(rel = "delete-by-id", description = @Description("Delete by id")) public void delete(@Param("id") String id);
@RestResource(rel = "by-id", description = @Description("Find order by id")) Order findOrderById(@Param("id") String id);
@RestResource(rel = "find-by-id", description = @Description("Find by id")) public Order findFirstById(@Param("id") String id);