Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
refactor ad remove coverage folder, see coverage percentage in GitHub…
Browse files Browse the repository at this point in the history
… Actions build_and_test or generate it in your environment
  • Loading branch information
JesusGautamah committed Nov 25, 2022
1 parent 5c1cf94 commit e7286fe
Show file tree
Hide file tree
Showing 8 changed files with 662 additions and 236 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
### Last Update:
#### Added Docker Compose Installation Recognition and Refactored some tests
#### Added lib tasks helper to created rake tasks for blockchain
##### TODO
###### Add more tests
###### Add more features
###### Include pagination
###### Create Queries Folder
###### Test in kubernetes
###### Add more documentation
###### Add NFT Generator
###### Increase the environment variables for autoconfig
###### Add features of autogeneration of blockchain for better configuration




## System dependencies
Expand Down
41 changes: 41 additions & 0 deletions app/controllers/api/v1/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

class Api::V1::ApplicationController < ActionController::API
def unauthorized?
return unauthorized_response unless find_user_by_header
end

def ticket_founded?
@ticket = Ticket.find_by(user_id: @user.id, status: :active)
return ticket_not_found_response unless @ticket.present?
end

private
def find_user_by_header
return unless request.headers["X-API-KEY"].present?
api_key = request.headers["X-API-KEY"]
@user = User.find_by(api_key: api_key)
return unless @user.present?
@user.api_secret == request.headers["X-API-SECRET"]
end

def confirmation_hash_founded?
return confirmation_hash_not_found_response unless confirmation_hash.present?
end

def confirmation_hash
@confirmation_hash ||= block_confirmation_params[:user_confirmation_hash]
end

def confirmation_hash_not_found_response
render json: { error: "Confirmation hash not found" }, status: :not_found
end

def ticket_not_found_response
render json: { error: "Ticket not found" }, status: :not_found
end

def unauthorized_response
render json: { error: "Unauthorized" }, status: :unauthorized
end
end
57 changes: 19 additions & 38 deletions app/controllers/api/v1/block_confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,43 @@
# frozen_string_literal: true

class Api::V1::BlockConfirmationsController < ActionController::API
class Api::V1::BlockConfirmationsController < Api::V1::ApplicationController
before_action :unauthorized?
before_action :ticket_founded?, only: [:confirm_block]
before_action :confirmation_hash_founded?, only: [:confirm_block]

def confirm_block
return unauthorized_response unless find_user_by_header
@ticket = Ticket.find_by(user_id: @user.id, status: :active)
return ticket_not_found_response unless @ticket.present?
confirmation_hash = block_confirmation_params[:user_confirmation_hash]
return confirmation_hash_not_found_response unless confirmation_hash.present?
return not_valid_confirmation_hash_response unless @ticket.user_acceptable_hash == confirmation_hash
return not_valid_confirmation_hash_response unless hash_confirmed?
assign_contract
end

# def transactions_to_mine
# return unauthorized_response unless find_user_by_header
# ticket = Ticket.find_by(user_id: @user.id)
# return ticket_not_found_response unless ticket.present?
# transactions_ids = ticket.transaction_id_list
# transactions = Transaction.where(id: transactions_ids)
# transactions_json = transactions.to_json
# render json: transactions_json, status: :ok
# end

def info_to_mine
return unauthorized_response unless find_user_by_header
words = @user.acceptable_words
number_sequences = @user.acceptable_number_sequences
symbol_sequences = @user.acceptable_symbol_sequences
render json: { words: words, number_sequences: number_sequences, symbol_sequences: symbol_sequences }, status: :ok
end

private
def find_user_by_header
return unless request.headers["X-API-KEY"].present?
api_key = request.headers["X-API-KEY"]
@user = User.find_by(api_key: api_key)
return unless @user.present?
@user.api_secret == request.headers["X-API-SECRET"]
def hash_confirmed?
@ticket.user_acceptable_hash == confirmation_hash
end

def unauthorized_response
render json: { error: "Unauthorized" }, status: :unauthorized
def assign_contract
AssignContractWorker.perform_async(@ticket.id)
render json: { message: "Contract assigned" }, status: :ok
end

def ticket_not_found_response
render json: { error: "Ticket not found" }, status: :not_found
def not_valid_confirmation_hash_response
render json: { error: "Not valid confirmation hash" }, status: :not_found
end

def confirmation_hash_not_found_response
render json: { error: "Confirmation hash not found" }, status: :not_found
def words
@words = @user.acceptable_words
end

def assign_contract
AssignContractWorker.perform_async(@ticket.id)
render json: { message: "Contract assigned" }, status: :ok
def number_sequences
@number_sequences = @user.acceptable_number_sequences
end

def not_valid_confirmation_hash_response
render json: { error: "Not valid confirmation hash" }, status: :not_found
def symbol_sequences
@symbol_sequences = @user.acceptable_symbol_sequences
end

def block_confirmation_params
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"line": 80.9
"line": 81.24
}
}
59 changes: 46 additions & 13 deletions coverage/.resultset.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,55 +763,81 @@
null,
1,
1,
5,
4,
4,
3,
3,
1,
1,
null,
1,
2,
1,
null,
null,
1,
1,
null,
null,
1,
1,
2,
null,
null,
1,
1,
1,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
1,
3,
1,
null,
null,
1,
1,
null,
null,
1,
3,
null,
null
]
},
"/myapp/app/controllers/api/v1/application_controller.rb": {
"lines": [
null,
null,
1,
1,
8,
8,
8,
8,
6,
null,
null,
1,
3,
4,
4,
null,
null,
1,
1,
8,
8,
8,
8,
6,
null,
null,
1,
1,
3,
null,
null,
1,
5,
null,
null,
1,
1,
null,
Expand Down Expand Up @@ -1582,6 +1608,13 @@
null
]
},
"/myapp/app/controllers/api/v1/ticket_manager_controller.rb": {
"lines": [
null
],
"branches": {
}
},
"/myapp/app/models/concerns/sequences_validator.rb": {
"lines": [
null,
Expand Down Expand Up @@ -1741,6 +1774,6 @@
}
}
},
"timestamp": 1669310702
"timestamp": 1669378473
}
}
Loading

0 comments on commit e7286fe

Please sign in to comment.