Skip to content

Conversation

@decentraliser
Copy link
Contributor

@decentraliser decentraliser commented Feb 20, 2020

fixes #456

Copy link
Contributor

@fboucquez fboucquez left a comment

Choose a reason for hiding this comment

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

Unit tests are missing for this class in general. We should add them to this PR now we have the chance.

Now I don't know about having a builder style-setter methods or just go with destructuring object param and make the page request immutable (readonly fields).

I would probably remove the setter methods and make the fields readonly

@fboucquez
Copy link
Contributor

Double-check unit tests and tslint. Travis is complaining about the missing {} as args is mandatory.

@decentraliser
Copy link
Contributor Author

decentraliser commented Feb 20, 2020

I would probably remove the setter methods and make the fields readonly

they could be private as well
I think the setters are fine as is

Copy link
Contributor

@rg911 rg911 left a comment

Choose a reason for hiding this comment

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

Would need to do the same on the TransactionFilter

Also the PR description links to the wrong issue

@fboucquez
Copy link
Contributor

fboucquez commented Feb 20, 2020

I would take it further and change the objects with something like

/**
 * The query params structure describes pagination params for requests.
 *
 * @since 1.0
 */
export class QueryParams {
    /**
     * Page size between 10 and 100, otherwise 10
     */
    public readonly pageSize: number;
    /**
     * Order of transactions.
     * DESC. Newer to older.
     * ASC. Older to newer.
     */
    public readonly order: Order;
    /**
     * Id after which we want objects to be returned
     */
    public readonly id?: string;
    /**
     * Creates an instance of QueryParams.
     * @param {{
     *         pageSize?: number,
     *         order?: Order,
     *         id?: string
     *     }} args arguments
     */
    constructor(args?: {
        pageSize?: number,
        order?: Order,
        id?: string;
    }) {
        this.pageSize = args && args.pageSize || 10;
        this.order = args && args.order || Order.DESC;
        this.id = args && args.id || undefined;
    }
}

Examples:

const params1 = new QueryParams({pageSize: 10});
const params2 = new QueryParams({id: 'someId'});
const params3 = new QueryParams({pageSize: 20, order: Order.ASC});

About args.pageSize, I would probably raise an exception if it's not in the valid 10...100 range. If not the user would expect a page size but the SDK is really asking for another size. The alternative is to send the pageSize as-is and rest will complain or set the default. Rest may change the default and the SDK may miss the new range/default

@decentraliser
Copy link
Contributor Author

I would probably raise an exception if it's not in the valid 10...100 range.
I let a setter for pageSize and made it private in order to handle this exception out of the constructor

Would need to do the same on the TransactionFilter
Also the PR description links to the wrong issue
Fixed both

@fboucquez
Copy link
Contributor

fboucquez commented Feb 21, 2020

I will make the QueryParams fields readonly and add unit tests. This would be a future improvement as we are in the middle of the rebranding

@fboucquez fboucquez requested review from fboucquez and rg911 February 21, 2020 13:45
@rg911 rg911 merged commit 92602c1 into symbol:master Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QueryParams - Allow passing arguments to the constructor

3 participants