This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
421 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Api::LogosController < ApiController | ||
skip_before_action :authenticate, only: [:security] | ||
Check failure on line 2 in app/controllers/api/logos_controller.rb GitHub Actions / lint
|
||
|
||
def search | ||
kind = params[:kind] || "security" | ||
query = params[:q] || "" | ||
end | ||
|
||
def security | ||
symbol = params[:symbol] | ||
security = Security.find_by("lower(symbol) = ?", symbol.downcase) | ||
|
||
unless security | ||
render json: { error: 'Not Found' }, status: :not_found | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class SecuritiesController < ApplicationController | ||
before_action :set_security, only: %i[ show edit update destroy ] | ||
|
||
# GET /securities or /securities.json | ||
def index | ||
@securities = Security.limit(10).order(:name) | ||
end | ||
|
||
# GET /securities/1 or /securities/1.json | ||
def show | ||
end | ||
|
||
# GET /securities/1/edit | ||
def edit | ||
end | ||
|
||
# POST /securities or /securities.json | ||
def create | ||
@security = Security.new(security_params) | ||
|
||
respond_to do |format| | ||
if @security.save | ||
format.html { redirect_to security_url(@security), notice: "Security was successfully created." } | ||
format.json { render :show, status: :created, location: @security } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @security.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /securities/1 or /securities/1.json | ||
def update | ||
respond_to do |format| | ||
if @security.update(security_params) | ||
format.html { redirect_to security_url(@security), notice: "Security was successfully updated." } | ||
format.json { render :show, status: :ok, location: @security } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @security.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /securities/1 or /securities/1.json | ||
def destroy | ||
@security.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to securities_url, notice: "Security was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_security | ||
@security = Security.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def security_params | ||
params.require(:security).permit(:logos, :exchange_id, :name, :symbol, :legal_name, :links, :color, :description) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Api::LogosHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SecuritiesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Security < ApplicationRecord | ||
belongs_to :exchange | ||
|
||
has_many_attached :logos | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.meta do | ||
json.credits_used 1 | ||
json.credits_remaining @api_key.user.balance | ||
end | ||
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<%= form_with(model: security, class: "contents") do |form| %> | ||
<% if security.errors.any? %> | ||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3"> | ||
<h2><%= pluralize(security.errors.count, "error") %> prohibited this security from being saved:</h2> | ||
|
||
<ul> | ||
<% security.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="my-5"> | ||
<%= form.label :logos %> | ||
<%= form.file_field :logos, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :exchange_id %> | ||
<%= form.text_field :exchange_id, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :name %> | ||
<%= form.text_field :name, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :symbol %> | ||
<%= form.text_field :symbol, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :legal_name %> | ||
<%= form.text_field :legal_name, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :links %> | ||
<%= form.text_field :links, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :color %> | ||
<%= form.text_field :color, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="my-5"> | ||
<%= form.label :description %> | ||
<%= form.text_area :description, rows: 4, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> | ||
</div> | ||
|
||
<div class="inline"> | ||
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<div id="<%= dom_id security %>"> | ||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Logos:</strong> | ||
<%= link_to security.logos.filename, security.logos if security.logos.attached? %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Exchange:</strong> | ||
<%= security.exchange.name %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Name:</strong> | ||
<%= security.name %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Symbol:</strong> | ||
<%= security.symbol %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Legal name:</strong> | ||
<%= security.legal_name %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Links:</strong> | ||
<%= security.links %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Color:</strong> | ||
<%= security.color %> | ||
</p> | ||
|
||
<p class="my-5"> | ||
<strong class="block mb-1 font-medium">Description:</strong> | ||
<%= security.description %> | ||
</p> | ||
|
||
<% if action_name != "show" %> | ||
<%= link_to "Show this security", security, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to "Edit this security", edit_security_path(security), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> | ||
<hr class="mt-6"> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.extract! security, :id, :logos, :exchange_id, :name, :symbol, :legal_name, :links, :color, :description, :created_at, :updated_at | ||
json.url security_url(security, format: :json) | ||
json.logos url_for(security.logos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">Editing security</h1> | ||
|
||
<%= render "form", security: @security %> | ||
|
||
<%= link_to "Show this security", @security, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to "Back to securities", securities_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="w-full"> | ||
<% if notice.present? %> | ||
<p class="inline-block px-3 py-2 mb-5 font-medium text-green-500 rounded-lg bg-green-50" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<div class="flex items-center justify-between"> | ||
<h1 class="text-4xl font-bold">Securities</h1> | ||
</div> | ||
|
||
<div id="securities" class="min-w-full"> | ||
<%= render @securities %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @securities, partial: "securities/security", as: :security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="mx-auto md:w-2/3 w-full flex"> | ||
<div class="mx-auto"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<%= render @security %> | ||
|
||
<%= link_to "Edit this security", edit_security_path(@security), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<div class="inline-block ml-2"> | ||
<%= button_to "Destroy this security", security_path(@security), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> | ||
</div> | ||
<%= link_to "Back to securities", securities_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "securities/security", security: @security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateSecurities < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :securities, id: :uuid do |t| | ||
t.references :exchange, null: false, foreign_key: true, type: :uuid | ||
t.string :name | ||
t.string :symbol | ||
t.string :legal_name | ||
t.jsonb :links, default: {} | ||
t.string :color | ||
t.text :description | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class Api::LogosControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
Oops, something went wrong.