Compare commits

...

2 commits

Author SHA1 Message Date
0e57a76ce6 Fix NC style series sort order in search dropdown
Oops, I didn't realize that the MySQL function `SUBSTRING_INDEX` always
returns the full string if the split delimiter isn't found.

This meant that, for series names like "Regal", we read the main name as
"Regal" (correct) and the variant name as "Regal" (incorrect).

This caused sort order to be incorrect for some series, e.g.,
- Prismatic Dawn: Regal
- Prismatic Dusk: Regal
- Prismatic Mirage: Regal
- Regal

whereas the main series name is meant to be first, and *does* come first
in cases like "Festive" where the main name sorts before any of the
variant names!

In this change, we update the variant name definition to return an empty
string. That way, when there's no variant name and it's just the main
series, that one sorts to the top of the series variants.
2025-06-22 12:37:28 -07:00
14be40a292 Fix NC Mall Styling Studio import
They made a small change to the API call! Fixed now!

The other NC Mall syncing stuff to get current NC cost is broken, but
that seems like a MUCH bigger change, so I won't bother just yet.
2025-06-22 12:24:27 -07:00
3 changed files with 5 additions and 3 deletions

View file

@ -32,11 +32,13 @@ class AltStyle < ApplicationRecord
}
scope :by_series_main_name, -> {
# The main part of the series name, like "Nostalgic".
# If there's no colon, uses the whole string.
order(Arel.sql("SUBSTRING_INDEX(series_name, ': ', -1)"))
}
scope :by_series_variant_name, -> {
# The variant part of the series name, like "Prismatic Cyan".
order(Arel.sql("SUBSTRING_INDEX(series_name, ': ', 1)"))
# If there's no colon, uses an empty string.
order(Arel.sql("SUBSTRING(series_name, 1, LOCATE(': ', series_name) - 1)"))
}
scope :by_color_name, -> {
joins(:color).order(Color.arel_table[:name])

View file

@ -60,7 +60,7 @@ module Neopets::NCMall
["Cookie", "neologin=#{neologin}"],
["X-Requested-With", "XMLHttpRequest"],
],
{tab:, mode: "getStyles", species: species_id}.to_query,
{tab:, mode: "getAvailable", species: species_id}.to_query,
) do |response|
if response.status != 200
raise ResponseNotOK.new(response.status),

View file

@ -58,7 +58,7 @@ RSpec.describe Neopets::NCMall, type: :model do
"Cookie": "neologin=STUB_NEOLOGIN",
"User-Agent": Rails.configuration.user_agent_for_neopets,
},
body: "mode=getStyles&species=2&tab=#{tab}",
body: "mode=getAvailable&species=2&tab=#{tab}",
)
end