Update Collection.lua

This commit is contained in:
IBims2CooleTim 2023-09-30 23:27:10 +02:00 committed by GitHub
parent 571147e39e
commit 227146a518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,18 +2,18 @@ local Utils = require(script.Parent.Parent.Utils)
local Entry = require(script.Parent.Entry) local Entry = require(script.Parent.Entry)
local types = { local types = {
EntryData = require(script.Parent.Parent.Types.EntryData).getType() EntryData = require(script.Parent.Parent.Types.EntryData).bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar()
} }
local Collection = {} local Collection = {}
Collection.createEntry = function(self:typeof(Collection), data:typeof(types.EntryData)):typeof(Entry.new()) Collection.erzeugeEintrag = function(self:typeof(Collection), data:typeof(types.EntryData)):typeof(Entry.new())
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.makeHTTPRequest("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken); local result = Utils.macheHypertexttransferprotokollAnfrage("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken);
if result["success"] and result["objectId"] then if result["success"] and result["objectId"] then
data["_id"] = result["objectId"] data["_id"] = result["objectId"]
result = require(script.Parent.Entry).new(self._collectionName, data, self._accessToken) result = require(script.Parent.Entry).neu(self._collectionName, data, self._accessToken)
else else
error(result["errorMessage"]) error(result["errorMessage"])
end end
@ -21,22 +21,22 @@ Collection.createEntry = function(self:typeof(Collection), data:typeof(types.Ent
return result return result
end end
Collection.updateEntries = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number Collection.aktualisiereEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken); local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end if not result["success"] then error(result["errorMessage"]) end
return result["modifiedEntries"] return result["modifiedEntries"]
end end
Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[number]:typeof(Entry.new())} Collection.bekommeEintraege = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[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 self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
if not filters then filters = {} 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); local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken);
if result["success"] and result["entries"] then if result["success"] and result["entries"] then
local _result = {} local _result = {}
for index,entry in pairs(result["entries"]) do for index,entry in pairs(result["entries"]) do
_result[index] = require(script.Parent.Entry).new(self._collectionName, entry, self._accessToken) _result[index] = require(script.Parent.Entry).neu(self._collectionName, entry, self._accessToken)
end end
result = _result result = _result
else else
@ -46,23 +46,23 @@ Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.E
return result return result
end end
Collection.deleteEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):number Collection.loescheEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData)):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken); local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end if not result["success"] then error(result["errorMessage"]) end
return result["deletedEntries"] return result["deletedEntries"]
end end
Collection.drop = function(self:typeof(Collection)) Collection.fallenlassen = function(self:typeof(Collection))
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.makeHTTPRequest("collection", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken); local result = Utils.macheHypertexttransferprotokollAnfrage("sammlung", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end if not result["success"] then error(result["errorMessage"]) end
self = nil self = nil
end end
return { return {
new = function(collectionName: string, accessToken: string):typeof(Collection) neu = function(collectionName: string, accessToken: string):typeof(Collection)
local self = {} local self = {}
self._collectionName = collectionName self._collectionName = collectionName
self._accessToken = accessToken self._accessToken = accessToken
@ -73,4 +73,4 @@ return {
return self return self
end end
} }