Class: WordleDictionariesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- WordleDictionariesController
- Defined in:
- app/controllers/wordle_dictionaries_controller.rb
Overview
Handles modifications to the WordleDictionary by a Puzzle Setter
Instance Method Summary collapse
-
#amend_dict ⇒ Object
PATCH /wordle_dictionaries/amend_dict or /wordle_dictionaries/amend_dict.json.
-
#index ⇒ Object
GET /wordle_dictionaries or /wordle_dictionaries.json Returns both HTML content and JSON content, the request must specify required response format.
-
#reset_dict ⇒ Object
PATCH /wordle_dictionaries/reset_dict or /wordle_dictionaries/reset_dict.json.
Instance Method Details
#amend_dict ⇒ Object
PATCH /wordle_dictionaries/amend_dict or /wordle_dictionaries/amend_dict.json
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/wordle_dictionaries_controller.rb', line 31 def amend_dict errors = [] if validate_amend_dict_params new_words = parse_words_from_str delete_opt = params[:update_opt] == "replace" add_opt = delete_opt || params[:update_opt] == "add" errors = update_db(new_words, delete_opt, add_opt) else errors << "Please provide a list of valid words and select an update option" end if errors.empty? render json: { success: true }, status: 200 else render json: { success: false, errors: errors }, status: 500 end end |
#index ⇒ Object
GET /wordle_dictionaries or /wordle_dictionaries.json Returns both HTML content and JSON content, the request must specify required response format
For JSON requests, the following parameters can be specified (all the parameters can be requested together):
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/wordle_dictionaries_controller.rb', line 12 def index if request.format.json? query = WordleDictionary .where("word LIKE ?", "#{params[:word_part]}%") .order(word: sort_order) @wordle_dictionaries = filter_only_solutions(query) render json: { success: true, words: @wordle_dictionaries }, status: 200 else @wordle_dictionaries = WordleDictionary.order(:word) render :index end end |
#reset_dict ⇒ Object
PATCH /wordle_dictionaries/reset_dict or /wordle_dictionaries/reset_dict.json
Resets the active WordleDictionary to the default original copy (WordleDictionaryBackup)
52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/wordle_dictionaries_controller.rb', line 52 def reset_dict new_words = WordleDictionaryBackup.all.map { |record| { word: record.word, is_valid_solution: record.is_valid_solution } } errors = update_db(new_words, true, true) if errors.empty? render json: { success: true }, status: 200 else render json: { success: false, errors: errors }, status: 500 end end |