@@ -13,7 +13,7 @@ import (
1313
1414/* converts project session struct into PostgreSQL supported format */
1515func ConvertSessionToStoreParams (session * Session ) (* postgresql.StoreSessionPQParams , error ) {
16- // Validate status
16+ /* validate status */
1717 status := string (session .Status )
1818 if status != string (StatusActive ) && status != string (StatusExpired ) && status != string (StatusPending ) {
1919 return nil , fmt .Errorf ("invalid session status: %q, must be one of: %q, %q, %q" ,
@@ -53,17 +53,17 @@ func ConvertSessionToStoreParams(session *Session) (*postgresql.StoreSessionPQPa
5353}
5454
5555/* converts project transaction struct into PostgreSQL supported format */
56- func ConvertTransactiontoStoreParams (tx types.Transaction ) (postgresql.CreateTransactionPQParams , error ) {
56+ func ConvertTransactionPendingtoStoreParams (tx types.Transaction ) (postgresql.CreatePendingTransactionPQParams , error ) {
5757 /* marshal ACL entries to JSON bytes */
5858 entriesJSON , err := json .Marshal (tx .Entries )
5959 if err != nil {
60- return postgresql.CreateTransactionPQParams {}, fmt .Errorf ("failed to marshal ACL entries: %w" , err )
60+ return postgresql.CreatePendingTransactionPQParams {}, fmt .Errorf ("failed to marshal ACL entries: %w" , err )
6161 }
6262
6363 /* convert timestamp to pgtype.Timestamptz */
6464 var timestamp pgtype.Timestamptz
6565 if err := timestamp .Scan (tx .Timestamp ); err != nil {
66- return postgresql.CreateTransactionPQParams {}, fmt .Errorf ("failed to convert timestamp: %w" , err )
66+ return postgresql.CreatePendingTransactionPQParams {}, fmt .Errorf ("failed to convert timestamp: %w" , err )
6767 }
6868
6969 /* handle optional error message */
@@ -84,7 +84,54 @@ func ConvertTransactiontoStoreParams(tx types.Transaction) (postgresql.CreateTra
8484 durationMs = pgtype.Int8 {Int64 : tx .DurationMs , Valid : true }
8585 }
8686
87- return postgresql.CreateTransactionPQParams {
87+ return postgresql.CreatePendingTransactionPQParams {
88+ ID : tx .ID ,
89+ SessionID : tx .SessionID ,
90+ Timestamp : timestamp ,
91+ Operation : string (tx .Operation ),
92+ TargetPath : tx .TargetPath ,
93+ Entries : entriesJSON ,
94+ Status : string (tx .Status ),
95+ ErrorMsg : errorMsg ,
96+ Output : output ,
97+ ExecutedBy : tx .ExecutedBy ,
98+ DurationMs : durationMs ,
99+ }, nil
100+ }
101+
102+ /* converts project transaction struct into PostgreSQL supported format */
103+ func ConvertTransactionResulttoStoreParams (tx types.Transaction ) (postgresql.CreateResultsTransactionPQParams , error ) {
104+ /* marshal ACL entries to JSON bytes */
105+ entriesJSON , err := json .Marshal (tx .Entries )
106+ if err != nil {
107+ return postgresql.CreateResultsTransactionPQParams {}, fmt .Errorf ("failed to marshal ACL entries: %w" , err )
108+ }
109+
110+ /* convert timestamp to pgtype.Timestamptz */
111+ var timestamp pgtype.Timestamptz
112+ if err := timestamp .Scan (tx .Timestamp ); err != nil {
113+ return postgresql.CreateResultsTransactionPQParams {}, fmt .Errorf ("failed to convert timestamp: %w" , err )
114+ }
115+
116+ /* handle optional error message */
117+ var errorMsg pgtype.Text
118+ if tx .ErrorMsg != "" {
119+ errorMsg = pgtype.Text {String : tx .ErrorMsg , Valid : true }
120+ }
121+
122+ /* handle optional output */
123+ var output pgtype.Text
124+ if tx .Output != "" {
125+ output = pgtype.Text {String : tx .Output , Valid : true }
126+ }
127+
128+ /* Handle optional duration */
129+ var durationMs pgtype.Int8
130+ if tx .DurationMs > 0 {
131+ durationMs = pgtype.Int8 {Int64 : tx .DurationMs , Valid : true }
132+ }
133+
134+ return postgresql.CreateResultsTransactionPQParams {
88135 ID : tx .ID ,
89136 SessionID : tx .SessionID ,
90137 Timestamp : timestamp ,
0 commit comments