Update dv360 query to deal with advertiser-level query #62
Conversation
lib/src/query_component.dart
Outdated
|
||
// TODO: update reporting query to deal with multiple IOs. | ||
// Issue: https://github.com/googleinterns/dv360-excel-plugin/issues/61 | ||
final insertionOrder = insertionOrders[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still querying the spend data for a single IO. Reporting api will be updated in the next pr.
@@ -2,7 +2,7 @@ import 'dart:convert'; | |||
|
|||
import 'proto/insertion_order_query.pb.dart'; | |||
|
|||
class InsertionOrderParser { | |||
class Dv360ServiceResponseParser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: public api parser maybe? service response parser just sounds weird
map = json.decode(jsonString); | ||
} catch (e) { | ||
// [jsonString] is not in valid json format, returns empty list. | ||
print('invalid json format'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm debug code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so sorry, I think I applied the wrong git stash...
try { | ||
map = json.decode(jsonString); | ||
} catch (e) { | ||
// [jsonString] is not in valid json format, returns empty string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has this been happening? do we want to swallow the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In real cases, no. And in component testing with mocks, null will be passed into this function.
I guess sanity check and return empty string will be better then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep throwing. an error may be introduced and we wont notice especially because we dont have a logging framework here. later we can have some top level error handling to fail more gracefully.
lib/src/query_component.dart
Outdated
set isAdvertiserQuery(bool checked) => | ||
checked ? _queryType = QueryType.byAdvertiser : null; | ||
|
||
bool get isInsertionOrderQuery => _queryType == QueryType.byInsertionOrder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why translate your enum to a set of bools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be some way to get radio buttons to work with an enum
return insertionOrders | ||
.where((io) => | ||
io.budget.activeBudgetSegment != | ||
InsertionOrder_Budget_BudgetSegment()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesnt need to check dates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the IO is not in-flight, it will have an empty InsertionOrder_Budget_BudgetSegment() for the activeBudgetSegment field.
Date checking has already been done during parsing.
final insertionOrderList = <InsertionOrder>[]; | ||
var jsonResponse = ''; | ||
|
||
do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice do while loop
lib/src/query_component.dart
Outdated
Dv360ServiceResponseParser.parseNextPageToken(jsonResponse); | ||
|
||
// Executes dv360 query, parses the response and adds results to the list. | ||
var response = await _queryService.execDV3Query( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
lib/src/query_service.dart
Outdated
'$advertiserId/insertionOrders?$filter&$pageToken', | ||
method: 'GET'); | ||
} | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need this break statement? is the return sufficient
}); | ||
group('parses insertion orders from:', () { | ||
// test('null', () { | ||
// final actual = Dv360ServiceResponseParser.parseInsertionOrders(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
‽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh so sorry I think I applied the wrong git stash...
@@ -1,10 +1,10 @@ | |||
import 'package:angular_test/angular_test.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update test file name to reflect class/file under test
lib/src/public_api_parser.dart
Outdated
/// | ||
/// Returns an empty list if [jsonString] is null or empty. | ||
static List<InsertionOrder> parseInsertionOrders(String jsonString) { | ||
if (jsonString == null || jsonString.isEmpty) return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind of concerned about the possibility of null or empty values popping up in any method. If a response was invalid i think we should fail and throw rather than propagate a null or empty string. it'll also make your life easier i think being confident in your inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in real cases that jsonString can never be null or empty, since even if a request fails, it still returns a json object with the error message. I'm thinking that we should add parsing to the error json and display the error to users to let them know that they have entered the wrong id, etc. I guess we should do this for all queries.
i will create an issue and address this at end when all the queries are set.
And the sanity check is actually just for component testing, since mock class will pass in null to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set the mock class to return a default value in setUp. i think it's better to facilitate testing needs in the test code rather than your business code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanted to reply to this as part of a review to draw your attention to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh right. I will just get rid of the sanity checks then. The TODO for adding parsing support to error is at the top of the file.
lib/src/public_api_parser.dart
Outdated
Map<String, dynamic> map = json.decode(jsonString); | ||
return _createInsertionOrder(map); | ||
return map.containsKey('insertionOrders') | ||
? List.from(map['insertionOrders']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta comment this is about as big as a ternary should get from a personal readability preference.
lib/src/query_component.dart
Outdated
@@ -16,9 +17,16 @@ import 'reporting_query_parser.dart'; | |||
<input [(ngModel)]="insertionOrderId" | |||
placeholder="Insertion Order ID: 8127549" debugId="io-id-input"> | |||
<br> | |||
|
|||
<input type="checkbox" [(ngModel)]="isAdvertiserQuery" name="advertiser-query"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the query types are mutually exclusive the affordances should reflect that - typically a radio button
lib/src/query_service.dart
Outdated
String nextPageToken, String advertiserId, String insertionOrderId) { | ||
switch (queryType) { | ||
case QueryType.byAdvertiser: | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the inner brackets arent necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like these are still here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh..I thought i can only get rid of brackets if the statement is one line.
set isAdvertiserQuery(bool checked) => | ||
checked ? _queryType = QueryType.byAdvertiser : null; | ||
// Radio button states with byAdvertiser selected as default. | ||
RadioButtonState advertiserQuery = RadioButtonState(true, 'byAdvertiser'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the radio button can only take string values :(
Saw other people complain about this too.
lib/src/query_service.dart
Outdated
String nextPageToken, String advertiserId, String insertionOrderId) { | ||
switch (queryType) { | ||
case QueryType.byAdvertiser: | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like these are still here
lib/src/public_api_parser.dart
Outdated
/// | ||
/// Returns an empty list if [jsonString] is null or empty. | ||
static List<InsertionOrder> parseInsertionOrders(String jsonString) { | ||
if (jsonString == null || jsonString.isEmpty) return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanted to reply to this as part of a review to draw your attention to it
closes #10