Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Update dv360 query to deal with advertiser-level query #62

Merged
merged 5 commits into from Jul 16, 2020

Conversation

hanj7221
Copy link
Contributor

closes #10


// TODO: update reporting query to deal with multiple IOs.
// Issue: https://github.com/googleinterns/dv360-excel-plugin/issues/61
final insertionOrder = insertionOrders[0];
Copy link
Contributor Author

@hanj7221 hanj7221 Jul 15, 2020

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 {

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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm debug code

Copy link
Contributor Author

@hanj7221 hanj7221 Jul 15, 2020

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.

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

Copy link
Contributor Author

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.

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.

set isAdvertiserQuery(bool checked) =>
checked ? _queryType = QueryType.byAdvertiser : null;

bool get isInsertionOrderQuery => _queryType == QueryType.byInsertionOrder;

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't give much thought to how the UI will look like with different types of queries. But for developing purpose, I think a checkbox is most convenient for me now?

It looks something like this:
Screen Shot 2020-07-15 at 1 18 43 PM

And the bool is to have it work with the checkbox.

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())

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?

Copy link
Contributor Author

@hanj7221 hanj7221 Jul 15, 2020

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice do while loop

Dv360ServiceResponseParser.parseNextPageToken(jsonResponse);

// Executes dv360 query, parses the response and adds results to the list.
var response = await _queryService.execDV3Query(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

'$advertiserId/insertionOrders?$filter&$pageToken',
method: 'GET');
}
break;

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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';

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

///
/// Returns an empty list if [jsonString] is null or empty.
static List<InsertionOrder> parseInsertionOrders(String jsonString) {
if (jsonString == null || jsonString.isEmpty) return [];

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.

Copy link
Contributor Author

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.

Copy link

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

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

Copy link
Contributor Author

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.

Map<String, dynamic> map = json.decode(jsonString);
return _createInsertionOrder(map);
return map.containsKey('insertionOrders')
? List.from(map['insertionOrders'])

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.

@@ -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">

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

String nextPageToken, String advertiserId, String insertionOrderId) {
switch (queryType) {
case QueryType.byAdvertiser:
{

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?

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

Copy link
Contributor Author

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');
Copy link
Contributor Author

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.

String nextPageToken, String advertiserId, String insertionOrderId) {
switch (queryType) {
case QueryType.byAdvertiser:
{

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

@ruben-aghayan ruben-aghayan marked this pull request as draft July 16, 2020 17:40
///
/// Returns an empty list if [jsonString] is null or empty.
static List<InsertionOrder> parseInsertionOrders(String jsonString) {
if (jsonString == null || jsonString.isEmpty) return [];

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

@hanj7221 hanj7221 marked this pull request as ready for review July 16, 2020 18:11
@hanj7221 hanj7221 merged commit 77f1cb1 into master Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use dv360 public api to fetch all IOs under a specific advertiser id [1~2 day]
2 participants