diff --git a/src/MarcSync/MarcSyncv1.0.lua b/src/MarcSync/MarcSyncv1.1.lua similarity index 95% rename from src/MarcSync/MarcSyncv1.0.lua rename to src/MarcSync/MarcSyncv1.1.lua index ef8a2b5..bbecde5 100644 --- a/src/MarcSync/MarcSyncv1.0.lua +++ b/src/MarcSync/MarcSyncv1.1.lua @@ -52,8 +52,7 @@ return { self._checkInstallation = function() if not self then error("Please Setup MarcSync before using MarcSync.") end if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end - --print(HttpService.HttpEnabled) - --if not HttpService.HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end + if not HttpService.HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end end self = setmetatable(self, { @@ -62,4 +61,4 @@ return { return self end -} \ No newline at end of file +} diff --git a/src/MarcSync/Objects/Collection.lua b/src/MarcSync/Objects/Collection.lua index 73c0d79..1a8cc9b 100644 --- a/src/MarcSync/Objects/Collection.lua +++ b/src/MarcSync/Objects/Collection.lua @@ -2,7 +2,8 @@ local Utils = require(script.Parent.Parent.Utils) local Entry = require(script.Parent.Entry) local types = { - EntryData = require(script.Parent.Parent.Types.EntryData).getType() + EntryData = require(script.Parent.Parent.Types.EntryData).getType(), + FilterData = require(script.Parent.Parent.Types.FilterData).getType() } local Collection = {} @@ -21,18 +22,24 @@ Collection.createEntry = function(self:typeof(Collection), data:typeof(types.Ent return result end -Collection.updateEntries = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number +Collection.updateEntries = function(self:typeof(Collection), filters:typeof(types.FilterData), data:typeof(types.EntryData)):number if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end - local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken); + if not filters then filters = {} end + if not filters._startsWith then filters._startsWith = {} end + if not filters._ignoreCases then filters._ignoreCases = {} end + local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v1/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken); if not result["success"] then error(result["errorMessage"]) end return result["modifiedEntries"] end -Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[number]:typeof(Entry.new())} +Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.FilterData), limit: number):{[number]:typeof(Entry.new())} if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not filters then filters = {} end - local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken); + if not filters._startsWith then filters._startsWith = {} end + if not filters._ignoreCases then filters._ignoreCases = {} end + if not limit then limit = 0 end + local result = Utils.makeHTTPRequest("entry", "PATCH", "https://api.marcsync.dev/v1/entries/"..self._collectionName.."?methodOverwrite=GET", {["filters"]=filters, ["limit"] = limit}, self._accessToken); if result["success"] and result["entries"] then local _result = {} for index,entry in pairs(result["entries"]) do @@ -46,9 +53,12 @@ Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.E return result end -Collection.deleteEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):number +Collection.deleteEntries = function(self:typeof(Collection), filters:typeof(types.FilterData)):number if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end - local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken); + if not filters then filters = {} end + if not filters._startsWith then filters._startsWith = {} end + if not filters._ignoreCases then filters._ignoreCases = {} end + local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v1/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken); if not result["success"] then error(result["errorMessage"]) end return result["deletedEntries"] diff --git a/src/MarcSync/Objects/Entry.lua b/src/MarcSync/Objects/Entry.lua index d28907e..3a9c130 100644 --- a/src/MarcSync/Objects/Entry.lua +++ b/src/MarcSync/Objects/Entry.lua @@ -16,7 +16,7 @@ Entry.getValues = function(self:typeof(Entry)):typeof(types.EntryData) end Entry.updateValues = function(self:typeof(Entry), data:typeof(types.EntryData)):number - local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken); + local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v1/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken); if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then for i,v in pairs(data) do @@ -31,7 +31,7 @@ end Entry.delete = function(self:typeof(Entry)) if typeof(self) ~= "table" then error("Please use : instead of .") end - local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken); + local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v1/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken); if not result["success"] then error(result["errorMessage"]) end self = nil diff --git a/src/MarcSync/Types/FilterData.lua b/src/MarcSync/Types/FilterData.lua new file mode 100644 index 0000000..c2980c4 --- /dev/null +++ b/src/MarcSync/Types/FilterData.lua @@ -0,0 +1,11 @@ +type FilterData = { + ["_startsWith"]: {string}, + ["_ignoreCases"]: {string}, + [string]: any +} + +return { + getType = function(): FilterData + return {} + end, +}