Update order_handler, fix json_order_converter
This commit is contained in:
@@ -6,73 +6,64 @@
|
||||
|
||||
class
|
||||
JSON_ORDER_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
create object.make ("", "", "")
|
||||
create object.make ("","","")
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
object : ORDER
|
||||
|
||||
object: ORDER
|
||||
|
||||
value: detachable JSON_OBJECT
|
||||
|
||||
value : detachable JSON_OBJECT
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: attached like value): detachable like object
|
||||
from_json (j: attached like value): detachable like object
|
||||
-- Convert from JSON value. Returns Void if unable to convert
|
||||
local
|
||||
s_name, s_key, s_option: detachable STRING_32
|
||||
q: INTEGER_8
|
||||
lstr1, lstr2, lstr3 : detachable STRING_32
|
||||
q: detachable INTEGER_8
|
||||
o: ORDER
|
||||
i : ITEM
|
||||
l_array : detachable LIST [JSON_VALUE]
|
||||
l_val : detachable JSON_ARRAY
|
||||
l_array : detachable ARRAYED_LIST[JSON_VALUE]
|
||||
jv : detachable JSON_OBJECT
|
||||
is_valid_from_json : BOOLEAN
|
||||
do
|
||||
is_valid_from_json := True
|
||||
lstr1 ?= json.object (j.item (id_key), Void)
|
||||
lstr2 ?= json.object (j.item (location_key), Void)
|
||||
lstr3 ?= json.object (j.item (status_key), Void)
|
||||
l_val ?= j.item (items_key)
|
||||
|
||||
s_name ?= json.object (j.item (id_key), Void)
|
||||
s_key ?= json.object (j.item (location_key), Void)
|
||||
s_option ?= json.object (j.item (status_key), Void)
|
||||
create o.make (lstr1, lstr2, lstr3)
|
||||
|
||||
create o.make (s_name, s_key, s_option)
|
||||
|
||||
if attached {JSON_ARRAY} j.item (items_key) as l_val then
|
||||
if l_val /= void then
|
||||
l_array := l_val.array_representation
|
||||
from
|
||||
l_array.start
|
||||
until
|
||||
l_array.after
|
||||
loop
|
||||
if attached {JSON_OBJECT} l_array.item_for_iteration as jv then
|
||||
if attached {INTEGER_8} json.object (jv.item (quantity_key), Void) as l_integer then
|
||||
q := l_integer
|
||||
else
|
||||
q := 0
|
||||
end
|
||||
|
||||
s_name ?= json.object (jv.item (id_key), Void)
|
||||
s_key ?= json.object (jv.item (location_key), Void)
|
||||
s_option ?= json.object (jv.item (status_key), Void)
|
||||
|
||||
if s_name /= Void and s_key /= Void and s_option /= Void then
|
||||
if is_valid_item_customization (s_name, s_key, s_option,q) then
|
||||
create i.make (s_name, s_key, s_option, q)
|
||||
jv ?= l_array.item_for_iteration
|
||||
if jv /= Void then
|
||||
lstr1 ?= json.object (jv.item (name_key), Void)
|
||||
lstr2 ?= json.object (jv.item (size_key), Void)
|
||||
lstr3 ?= json.object (jv.item (option_key), Void)
|
||||
q ?= json.object (jv.item (quantity_key),Void)
|
||||
if lstr1/= Void and then lstr2 /= Void and then lstr3 /= Void then
|
||||
if is_valid_item_customization(lstr1,lstr2,lstr3,q) then
|
||||
create i.make (lstr1, lstr2,lstr3, q)
|
||||
o.add_item (i)
|
||||
else
|
||||
is_valid_from_json := False
|
||||
is_valid_from_json := false
|
||||
end
|
||||
else
|
||||
is_valid_from_json := False
|
||||
is_valid_from_json := false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -84,6 +75,7 @@ feature -- Conversion
|
||||
else
|
||||
Result := o
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
to_json (o: like object): like value
|
||||
@@ -106,7 +98,7 @@ feature -- Conversion
|
||||
i := o.items.item_for_iteration
|
||||
create jv.make
|
||||
jv.put (json.value (i.name), name_key)
|
||||
jv.put (json.value (i.size), size_key)
|
||||
jv.put (json.value (i.size),size_key)
|
||||
jv.put (json.value (i.quantity), quantity_key)
|
||||
jv.put (json.value (i.option), option_key)
|
||||
ja.add (jv)
|
||||
@@ -116,7 +108,6 @@ feature -- Conversion
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
id_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("id")
|
||||
@@ -156,12 +147,12 @@ feature -- Conversion
|
||||
create Result.make_json ("quantity")
|
||||
end
|
||||
|
||||
|
||||
option_key : JSON_STRING
|
||||
|
||||
once
|
||||
create Result.make_json ("option")
|
||||
end
|
||||
|
||||
feature -- Validation
|
||||
|
||||
is_valid_item_customization ( name : STRING_32; size: STRING_32; option : STRING_32; quantity : INTEGER_8 ) : BOOLEAN
|
||||
|
||||
Reference in New Issue
Block a user