Skip to content

Tons of additions - #4

Merged
rjdavis3 merged 46 commits into
ChannelApe:developfrom
brachetti:additions
Jul 27, 2018
Merged

rjdavis3 merged 46 commits into
ChannelApe:developfrom
brachetti:additions

Conversation

@brachetti

Copy link
Copy Markdown
Contributor

Hey there,

This is an introduction of several new endpoints present in the v3 API.
Also some small additions on concepts:

  • Paginated responses are marked with an Interface, because we needed that for ... well, pagination ;-)

More changed incoming :-)

ryankazokas and others added 30 commits February 23, 2018 07:50
GetCategories and getCategoriesAsTree
 Add options for getProducts
Change type of customFieldId to String
rashiq and others added 12 commits May 16, 2018 19:05
… additions

* 'additions' of github.com:brachetti/bigcommerce-sdk:
  Create response for custom field creation
  Change customFieldId to int
  Replace product with product id
  Add create product custom field id method
  Change type of customFieldId to String
Additional metadata for categories
Additional metadata for categories
sortOrder, metaKeywords, searchKeywords and customURL
@rjdavis3

Copy link
Copy Markdown
Contributor

@brachetti thanks for taking the time to open up this pull request. Our developers are a bit swamped at the moment so we will need about 2 weeks to review your code and ensure it plays well with our integrations.

One of our developers will review the request and offer feedback soon.

@ryankazokas ryankazokas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great additions to the SDK!

Here are some changes you'd have to make for functional purposes, as well as to meet code standards that we have.

One thing we are adding that we forgot to mention here is that we use gitflow. This means PR's for new features should be opened for merging within develop, while hotfixes go directly to master. We will be adding this to the contribution.md doc to avoid confusion in the future, but in the meantime if you aren't familar with gitflow, check out this article:
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

.queryParam(PAGE, page);

if (parentId != null) {
webTarget = webTarget.queryParam(PARENT_ID, parentId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nothing to fix here for now, but if we add more filters to this filter we may want to consider making this more scalable such as adding a parameter list that we can build.

private static final String IMAGES = "images";
private static final int MAX_LIMIT = 250;
private static final String PARENT_ID = "parent_id";
public static final int MAX_LIMIT = 250;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This field doesn't need to be public.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see where you are coming from, but when we used the library we put pagination outside and wanted to rely on a number that is more tightly bound to bigcommerce than our application.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand. Can you please describe your use case on code outside of this file needing to know the max limit? If calling code is concerned about the default max size, can't they just use the public methods that allow them to specify the limit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can try. We had in our project something like

public List<Category> getAllCategories(BigcommerceSdk client, Integer parentId) {
        return paginate(
                (page) -> client.getCategories(parentId, page, BigcommerceSdk.MAX_LIMIT),
                START_PAGE
        );
    }

where paginate() was a function that then used the information from the response to, well ... paginate :-)

We felt, that our application should not decide what's the paging limit.

@ryankazokas ryankazokas Jul 20, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see what you mean @brachetti . All i was getting at was to let the sdk do the magic, so your app doesn't need that parameter at all. From the above, it doesn't look like it really needs it.

We do similar things in our apps that use the sdk. See the getProducts method in the sdk. This hides the constant so the calling function just has to pass the page.

public Products getProducts(final int page, String... includes) {
    return getProducts(page, MAX_LIMIT, includes);
}

So using the public method without the limit should work:

public Categories getCategories(final int page) {
    return getCategories(page, MAX_LIMIT);
}

If you did this, your app wouldn't need to know the max limit and we'd be able to keep it private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you are trying to do nod

What do you think about including pagination in the SDK itself, so you rather end up with a getAllProducts() method? I feel this would improve usability a lot

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree. That's a great idea. That'd be a nice abstraction from having to deal with the pagination at all.
I'd just suggest if this is something you wanted to work on, please open up a GitHub enhancement and submit a new PR for the issue. Thanks!

Here is the contributing.md we are working on. It includes the part about suggesting a new enhancement:
https://github.com/ChannelApe/bigcommerce-sdk/blob/feature/Contribution_Doc/CONTRIBUTING.md#suggesting-a-new-feature

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's in #5 , I'll base the new branch off this one, since I need the PaginatedModel<T> interface

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import com.bigcommerce.catalog.models.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please refrain from using wildcard imports and import the specific classes you need. It may need all of the classes from that package now, but as we add more models/packages this may change.

See. 3.3.1 of our style guide:
https://channelape.github.io/styleguide/java/javaguide.html

@XmlAccessorType(XmlAccessType.FIELD)
@JsonInclude(Include.NON_NULL)
public class Brand {
public class Brand implements Serializable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The serializable class Brand does not declare a static final serialVersionUID field of type long

Please add a generated serialVersionUID

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@JsonInclude(NON_NULL)
public class CustomUrl implements Serializable {

@XmlElement(name = "url")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for the annotation here. The marshaler will automatically match fields by name. The only time we use this is when the field in JSON is snake case while we like to keep our fields camelcase.

import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.EqualsBuilder;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this import if you find a way to not use it.

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import com.bigcommerce.catalog.models.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


@XmlAccessorType(XmlAccessType.FIELD)
@JsonInclude(NON_NULL)
public class CustomUrl implements Serializable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add the generated serialVersionUID here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.LinkedList;
import java.util.List;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove these unused imports.

assertEquals(expectedBrands.get(0).getSearchKeywords(), actualBrands.getBrands().get(0).getSearchKeywords());
assertEquals(expectedBrands.get(0).getMetaDescription(), actualBrands.getBrands().get(0).getMetaDescription());
assertEquals(expectedBrands.get(0).getMetaKeywords(), actualBrands.getBrands().get(0).getMetaKeywords());
assertEquals(expectedBrands.get(0).getCustomUrl().getUrl(), actualBrands.getBrands().get(0).getCustomUrl().getUrl());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's good that you added coverage on the fields you added for brands. Can you also add some code coverage for the new public sdk methods.

  • getCategoriesAsTree
  • getCategories
  • updateCategory
  • createCategory
  • createProductCustomField
  • deleteProductCustomField

@brachetti

Copy link
Copy Markdown
Contributor Author

@ryankazokas should I change the PR to go into develop then?

@ryankazokas

Copy link
Copy Markdown
Contributor

Yes @brachetti , please switch this PR to go into develop. Thanks!

@rjdavis3

Copy link
Copy Markdown
Contributor

Hey @brachetti thanks so much for this PR. If you can change the merge branch from master to develop then we can accept this PR. @ryankazokas will then implement some of the code review feedback he has for you.

@rjdavis3 rjdavis3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please change merge branch from master to develop. All other code review feedback can be implemented by @ryankazokas on develop.

We will then add all your changes into our next minor release.

@brachetti
brachetti changed the base branch from master to develop July 20, 2018 10:45
@rjdavis3
rjdavis3 merged commit 967880d into ChannelApe:develop Jul 27, 2018
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.

5 participants