Unrated-Limited-Unlimited / ua-backend

4 stars 0 forks source link

Whiskey filters #36

Closed Veggissss closed 6 months ago

Veggissss commented 6 months ago

This PR includes:

The filters where initially outlined by @Neelzee in the related issue.

This implementation looks like:

getWhiskeys(sort: Sort, filters: [Filter], paging: Paging): [Whiskey]

Where Sort is defined by:

input Sort{
    sortType: SortType!
    reverse: Boolean
}

enum SortType{
    BEST,
    PRICE,
    POPULAR,
    RANDOM,
    DEFAULT,
}

The filtering looks mostly the same as the inital outline with some minor naming and null-able changes:

# Filter whiskey using a comparator and a field value.
input Filter {
    comp: Comparator,
    field: Field!
}

# What to compare against
# Only the first one of these will be used for each given filter
input Field {
    title: String,            # Filter by whiskey name (does not need comparator)
    avgScore: Float,          # Avg whiskey score
    attribute: InputAttribute # Filter by an attribute
}

input InputAttribute{
    id : Int!        # Attribute category ID
    avgScore: Float! # Attribute average score value
}

enum Comparator {
    LT, # Less than
    GT, # Greater than
    LE, # Less than or equal
    GE, # Greater than or equal
    EQ  # Equals
}

An example using the filters to get every whiskey that has malt in title and has an average rating of Greater Than 0.4 (2 stars). The resulting whiskeys are sorted by PRICE in reverse/increasing order:

query{
  getWhiskeys(
    sort: {sortType: PRICE, reverse: true}
    filters: [ {comp: GT, field: {avgScore: 0.4}}, {field: {title: "malt"}} ]
    paging: {page: 0, size: 12}
  ) {
    title
    price
    avgScore
    categories {
      id
      name
      avgScore
    }
  }
}

Paging remains unchanged with default values {page: 0, size: 10}, when not given as input.

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud