Skip to content

Commit

Permalink
chore(shard.lock): bump deps version, refactor storage controller
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Sep 5, 2023
1 parent b3362e5 commit 6abcbcb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shards:

action-controller:
git: https://github.com/spider-gazelle/action-controller.git
version: 7.2.1
version: 7.2.2

active-model:
git: https://github.com/spider-gazelle/active-model.git
Expand Down Expand Up @@ -243,7 +243,7 @@ shards:

placeos-core:
git: https://github.com/placeos/core.git
version: 4.11.9+git.commit.b88c92167056e3d590ad794772948f948d30cf9e
version: 4.11.9+git.commit.e5602779f5c5e6c60578ea7463739a388830ff6c

placeos-core-client: # Overridden
git: https://github.com/placeos/core-client.git
Expand All @@ -263,7 +263,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.17.2
version: 9.17.3

placeos-resource:
git: https://github.com/place-labs/resource.git
Expand All @@ -283,7 +283,7 @@ shards:

raven:
git: https://github.com/sija/raven.cr.git
version: 1.9.3+git.commit.2fa8a119cfa15d6fb98f0d8e3924d8175e974103
version: 1.9.3+git.commit.37ec01251561789304c032b14d8906e8c50eb6b3

redis:
git: https://github.com/stefanwille/crystal-redis.git
Expand Down
9 changes: 8 additions & 1 deletion spec/controllers/storages_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module PlaceOS::Api
describe "CRUD operations", tags: "crud" do
it "create" do
Model::Storage.clear
body = PlaceOS::Model::Generator.storage.to_json
storage = PlaceOS::Model::Generator.storage
storage.mime_filter = ["image/bmp", "image/jpeg", "image/tiff"]
storage.ext_filter = [".bmp", ".jpg", ".tiff"]
body = storage.to_json
result = client.post(
Storages.base_route,
body: body,
Expand All @@ -25,6 +28,8 @@ module PlaceOS::Api
original_name = storage.bucket_name

storage.bucket_name = random_name
storage.mime_filter = ["image/bmp", "image/jpeg", "image/tiff"]
storage.ext_filter = [".bmp", ".jpg", ".tiff"]

id = storage.id.as(String)
path = File.join(Storages.base_route, id)
Expand All @@ -39,6 +44,8 @@ module PlaceOS::Api

updated.id.should eq storage.id
updated.bucket_name.should_not eq original_name
updated.mime_filter.should eq(["image/bmp", "image/jpeg", "image/tiff"])
updated.ext_filter.should eq(["bmp", "jpg", "tiff"])
updated.destroy
end

Expand Down
6 changes: 4 additions & 2 deletions src/placeos-rest-api/controllers/storages.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ module PlaceOS::Api
def update(storage : Model::Storage) : Model::Storage
current = current_storage
current.assign_attributes(storage)
raise Error::ModelValidation.new(current.errors) unless current.save
raise Error::ModelValidation.new(current.errors) unless current.valid?
current.save!
current
end

# adds a new storage
@[AC::Route::POST("/", body: :storage, status_code: HTTP::Status::CREATED)]
def create(storage : Model::Storage) : Model::Storage
raise Error::ModelValidation.new(storage.errors) unless storage.save
raise Error::ModelValidation.new(storage.errors) unless storage.valid?
storage.save!
storage
end

Expand Down

0 comments on commit 6abcbcb

Please sign in to comment.