@@ -2,7 +2,8 @@ use std::str::FromStr;
22
33use actix_web:: { web, HttpResponse } ;
44use serde:: { Deserialize , Serialize } ;
5- use serde_json:: Value ;
5+ use serde_json:: { Map , Value } ;
6+ use ureq:: SerdeMap ;
67use uuid:: Uuid ;
78
89use crate :: { errors:: ServiceError , operators:: webhook_operator:: publish_content} ;
@@ -31,12 +32,55 @@ pub struct ContentValue {
3132 id : String ,
3233 name : String ,
3334 model_id : String ,
34- data : Value ,
35+ data : Map < String , Value > ,
3536}
3637
3738impl Into < ChunkReqPayload > for ContentValue {
3839 fn into ( self ) -> ChunkReqPayload {
39- todo ! ( ) ;
40+ let mut chunk_req_payload = ChunkReqPayload :: default ( ) ;
41+ chunk_req_payload. tracking_id = Some ( self . id ) ;
42+
43+ let mut body = String :: new ( ) ;
44+ body. push_str ( & self . name ) ;
45+
46+ let mut metadata = SerdeMap :: new ( ) ;
47+ let mut tags = Vec :: new ( ) ;
48+
49+ for ( key, value) in self . data . iter ( ) {
50+ match value {
51+ Value :: String ( val) => {
52+ body. push_str ( & format ! ( "\n {}" , val) ) ;
53+ }
54+
55+ Value :: Array ( val) => {
56+ for item in val {
57+ match item {
58+ Value :: String ( val) => {
59+ tags. push ( val. clone ( ) ) ;
60+ }
61+
62+ _ => { }
63+ }
64+ }
65+ }
66+
67+ Value :: Bool ( val) => {
68+ metadata. insert ( key. clone ( ) , serde_json:: Value :: Bool ( * val) ) ;
69+ }
70+
71+ Value :: Number ( val) => {
72+ metadata. insert ( key. clone ( ) , serde_json:: Value :: Number ( val. clone ( ) ) ) ;
73+ }
74+
75+ Value :: Object ( val) => {
76+ metadata. insert ( key. clone ( ) , serde_json:: Value :: Object ( val. clone ( ) ) ) ;
77+ }
78+
79+ _ => { }
80+ } ;
81+ }
82+
83+ return chunk_req_payload;
4084 }
4185}
4286
0 commit comments