6
6
namespace DotNetSampleApp . Controllers ;
7
7
8
8
/// <summary>
9
- /// Customers controller
9
+ /// Customers controller
10
10
/// </summary>
11
11
/// <param name="client">Fauna Client</param>
12
12
[ ApiController ,
@@ -30,10 +30,10 @@ public async Task<IActionResult> GetCustomer([FromRoute] string customerId)
30
30
//
31
31
// Use projection to only return the fields you need.
32
32
var query = Query . FQL ( $ """
33
- let customer: Any = Customer.byId({ customerId } )!
33
+ let customer = Customer.byId({ customerId } )!
34
34
{ QuerySnippets . CustomerResponse ( ) }
35
35
""" ) ;
36
-
36
+
37
37
// Connect to fauna using the client. The query method accepts an FQL query
38
38
// as a parameter and a generic type parameter representing the return type.
39
39
var res = await client . QueryAsync < Customer > ( query ) ;
@@ -52,16 +52,16 @@ public async Task<IActionResult> CreateCustomer(CustomerRequest customer)
52
52
{
53
53
// Create a new Customer document with the provided fields.
54
54
var query = Query . FQL ( $ """
55
- let customer: Any = Customer.create({ customer } )
55
+ let customer = Customer.create({ customer } )
56
56
{ QuerySnippets . CustomerResponse ( ) }
57
57
""" ) ;
58
-
58
+
59
59
// Connect to fauna using the client. The query method accepts an FQL query
60
60
// as a parameter and a generic type parameter representing the return type.
61
61
var res = await client . QueryAsync < Customer > ( query ) ;
62
62
return CreatedAtAction ( nameof ( GetCustomer ) , new { customerId = res . Data . Id } , res . Data ) ;
63
63
}
64
-
64
+
65
65
/// <summary>
66
66
/// Update Customer Details
67
67
/// </summary>
@@ -85,10 +85,10 @@ public async Task<IActionResult> UpdateCustomer(
85
85
//
86
86
// Use projection to only return the fields you need.
87
87
var query = Query . FQL ( $ """
88
- let customer: Any = Customer.byId({ customerId } )!.update({ customer } )
88
+ let customer = Customer.byId({ customerId } )!.update({ customer } )
89
89
{ QuerySnippets . CustomerResponse ( ) }
90
90
""" ) ;
91
-
91
+
92
92
// Connect to fauna using the client. The query method accepts an FQL query
93
93
// as a parameter and a generic type parameter representing the return type.
94
94
var res = await client . QueryAsync < Customer > ( query ) ;
@@ -116,25 +116,23 @@ public async Task<IActionResult> GetOrdersByCustomer(
116
116
// Make sure to URL encode the `afterToken` value to preserve these
117
117
// characters in URLs.
118
118
var query = ! string . IsNullOrEmpty ( afterToken )
119
-
119
+
120
120
// Paginate with the after token if it's present.
121
121
? Query . FQL ( $ "Set.paginate({ afterToken } )")
122
-
122
+
123
123
// Define an FQL query to retrieve a page of orders for a given customer.
124
124
// Get the Customer document by id, using the ! operator to assert that the document exists.
125
125
// If the document does not exist, Fauna will throw a document_not_found error. We then
126
126
// use the Order.byCustomer index to retrieve all orders for that customer and map over
127
127
// the results to return only the fields we care about.
128
128
: Query . FQL ( $$ """
129
- let customer: Any = Customer.byId({{ customerId }} )!
129
+ let customer = Customer.byId({{ customerId }} )!
130
130
Order.byCustomer(customer).pageSize({{ pageSize }} ).map((order) => {
131
- let order: Any = order
132
-
133
131
// Return the order.
134
132
{{ QuerySnippets . OrderResponse ( ) }}
135
133
})
136
134
""" ) ;
137
-
135
+
138
136
// Connect to fauna using the client. The query method accepts an FQL query
139
137
// as a parameter and a generic type parameter representing the return type.
140
138
var result = await client . QueryAsync < Page < Order > > ( query ) ;
@@ -156,12 +154,12 @@ public async Task<IActionResult> CreateCart([FromRoute] string customerId)
156
154
// Call our getOrCreateCart UDF to get the customer's cart. The function
157
155
// definition can be found 'server/schema/functions.fsl'.
158
156
var query = Query . FQL ( $ """
159
- let order: Any = getOrCreateCart({ customerId } )
160
-
157
+ let order = getOrCreateCart({ customerId } )
158
+
161
159
// Return the cart.
162
160
{ QuerySnippets . OrderResponse ( ) }
163
161
""" ) ;
164
-
162
+
165
163
// Connect to fauna using the client. The query method accepts an FQL query
166
164
// as a parameter and a generic type parameter representing the return type.
167
165
var res = await client . QueryAsync < Order > ( query ) ;
@@ -184,12 +182,12 @@ public async Task<IActionResult> AddItemToCart([FromRoute] string customerId, Ad
184
182
// definition can be found 'server/schema/functions.fsl'.
185
183
var query = Query . FQL ( $ """
186
184
let req = { item }
187
- let order: Any = createOrUpdateCartItem({ customerId } , req.productName, req.quantity)
185
+ let order = createOrUpdateCartItem({ customerId } , req.productName, req.quantity)
188
186
189
187
// Return the cart as an OrderResponse object.
190
188
{ QuerySnippets . OrderResponse ( ) }
191
189
""" ) ;
192
-
190
+
193
191
// Connect to fauna using the client. The query method accepts an FQL query
194
192
// as a parameter and a generic type parameter representing the return type.
195
193
var res = await client . QueryAsync < Order > ( query ) ;
@@ -210,12 +208,12 @@ public async Task<IActionResult> GetCart([FromRoute] string customerId)
210
208
// Get the customer's cart by id, using the ! operator to assert that the document exists.
211
209
// If the document does not exist, Fauna will throw a document_not_found error.
212
210
var query = Query . FQL ( $ """
213
- let order: Any = Customer.byId({ customerId } )!.cart
214
-
211
+ let order = Customer.byId({ customerId } )!.cart
212
+
215
213
// Return the cart as an OrderResponse object.
216
214
{ QuerySnippets . OrderResponse ( ) }
217
215
""" ) ;
218
-
216
+
219
217
// Connect to fauna using the client. The query method accepts an FQL query
220
218
// as a parameter and a generic type parameter representing the return type.
221
219
var res = await client . QueryAsync < Order > ( query ) ;
0 commit comments