-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
293bf2f
commit 411306a
Showing
13 changed files
with
78 additions
and
16 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 |
---|---|---|
@@ -1 +1 @@ | ||
docker-compose exec lucky lucky $1 | ||
docker-compose exec lucky lucky ${@} |
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,6 @@ | ||
class Api::CollectionSettings::Create < ApiAction | ||
post "/api/collection-settings/own-collection-settings" do | ||
collection_setting = SaveCollectionSetting.create!(params, id: UUID.random, user_id: current_user.id) | ||
head HTTP::Status::CREATED | ||
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,11 @@ | ||
class Api::CollectionSettings::Delete < ApiAction | ||
delete "/api/collection-settings/own-collection-settings/:collection_setting_id" do | ||
collection_setting = CollectionSettingQuery.new.find(collection_setting_id) | ||
if collection_setting.user_id == current_user.id | ||
DeleteCollectionSetting.delete!(collection_setting) | ||
head 204 | ||
else | ||
head 403 | ||
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 |
---|---|---|
@@ -1,6 +1,38 @@ | ||
class Api::CollectionSettings::Index < ApiAction | ||
get "/api/collection-settings/own-collection-settings" do | ||
collection_settings = CollectionSettingQuery.new.user_id(current_user.id) | ||
json CollectionSettingSerializer.for_collection(collection_settings) | ||
query = CollectionSettingQuery.new.user_id(current_user.id) | ||
if params.get?(:collection_name) | ||
query = query.collection_name.ilike("%#{params.get(:collection_name)}%") | ||
end | ||
if params.get?(:institution_code) | ||
query = query.institution_code.ilike("%#{params.get(:institution_code)}%") | ||
end | ||
if params.get?(:latest_collection_code_min) | ||
query = query.latest_collection_code.gte(params.get(:latest_collection_code_min)) | ||
end | ||
if params.get?(:latest_collection_code_max) | ||
query = query.latest_collection_code.lte(params.get(:latest_collection_code_max)) | ||
end | ||
if params.get?(:note) | ||
query = query.note.ilike("%#{params.get(:note)}%") | ||
end | ||
if params.get?(:created_at) | ||
query = query.created_at.as_date.eq(params.get(:created_at)) | ||
end | ||
if params.get?(:sort) | ||
sort_column = params.get(:sort) | ||
if sort_column == "collection_name" | ||
query = switch_order(query.collection_name, params) | ||
elsif sort_column == "institution_code" | ||
query = switch_order(query.institution_code, params) | ||
elsif sort_column == "latest_collection_code" | ||
query = switch_order(query.latest_collection_code, params) | ||
else | ||
query = switch_order(query.created_at, params) | ||
end | ||
else | ||
query = switch_order(query.created_at, params) | ||
end | ||
json CollectionSettingSerializer.for_collection(query) | ||
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,11 @@ | ||
class Api::CollectionSettings::Update < ApiAction | ||
put "/api/collection-settings/own-collection-settings/:collection_setting_id" do | ||
collection_setting = CollectionSettingQuery.new.find(collection_setting_id) | ||
if collection_setting.user_id == current_user.id | ||
SaveCollectionSetting.update!(collection_setting, params) | ||
head 204 | ||
else | ||
head 403 | ||
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
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,8 @@ | ||
module Api::Custom::SwitchOrder | ||
def switch_order(query, params) | ||
if params.get?(:order) | ||
return query.desc_order if params.get(:order) == "DESC" | ||
end | ||
query.asc_order | ||
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
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
class DeleteCollectionSetting < CollectionSetting::DeleteOperation | ||
# Read more on deleting records | ||
# https://luckyframework.org/guides/database/deleting-records | ||
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
class SaveCollectionSetting < CollectionSetting::SaveOperation | ||
# To save user provided params to the database, you must permit them | ||
# https://luckyframework.org/guides/database/saving-records#perma-permitting-columns | ||
# | ||
# permit_columns column_1, column_2 | ||
permit_columns( | ||
id, | ||
collection_name, | ||
institution_code, | ||
latest_collection_code, | ||
note | ||
note, | ||
user_id | ||
) | ||
|
||
before_save do | ||
validate_size_of collection_name, max: 174 | ||
validate_size_of institution_code, max: 10 | ||
validate_numeric latest_collection_code, less_than: 999999999999999999i64 | ||
validate_numeric latest_collection_code, no_more_than: 999999999999999999i64 | ||
end | ||
end |