From 49b3e46c85216d88ed8d76397a5a0ee9a1d22f56 Mon Sep 17 00:00:00 2001 From: IBims2CooleTim <116311836+IBims2CooleTim@users.noreply.github.com> Date: Sat, 18 Nov 2023 01:03:01 +0100 Subject: [PATCH] Revert "Revert "Revert "Revert "yes."""" --- LICENSE | 21 +++++ README.md | Bin 48 -> 1518 bytes .../{Utils.lua => Dienstprogramme.lua} | 18 ++--- src/MarcSync/Errors/Authorization.lua | 5 -- src/MarcSync/Errors/Autorisierung.lua | 5 ++ src/MarcSync/Errors/Collection.lua | 8 -- src/MarcSync/Errors/Eintrag.lua | 8 ++ src/MarcSync/Errors/Entry.lua | 8 -- src/MarcSync/Errors/Sammlung.lua | 8 ++ src/MarcSync/MarcSyncv1.0.lua | 44 +++++----- src/MarcSync/Objects/Collection.lua | 76 ------------------ src/MarcSync/Objects/Eintrag.lua | 56 +++++++++++++ src/MarcSync/Objects/Entry.lua | 56 ------------- src/MarcSync/Objects/Sammlung.lua | 76 ++++++++++++++++++ src/MarcSync/Types/EintragsDaten.lua | 9 +++ src/MarcSync/Types/EntryData.lua | 9 --- 16 files changed, 214 insertions(+), 193 deletions(-) create mode 100644 LICENSE rename src/MarcSync/{Utils.lua => Dienstprogramme.lua} (68%) delete mode 100644 src/MarcSync/Errors/Authorization.lua create mode 100644 src/MarcSync/Errors/Autorisierung.lua delete mode 100644 src/MarcSync/Errors/Collection.lua create mode 100644 src/MarcSync/Errors/Eintrag.lua delete mode 100644 src/MarcSync/Errors/Entry.lua create mode 100644 src/MarcSync/Errors/Sammlung.lua delete mode 100644 src/MarcSync/Objects/Collection.lua create mode 100644 src/MarcSync/Objects/Eintrag.lua delete mode 100644 src/MarcSync/Objects/Entry.lua create mode 100644 src/MarcSync/Objects/Sammlung.lua create mode 100644 src/MarcSync/Types/EintragsDaten.lua delete mode 100644 src/MarcSync/Types/EntryData.lua diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a04e554 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Marcel Lorbeer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 411c66cc4010da1ecf6c13eb021bae55d7a13d96..c17e94bd2633d5b2ddc40a0efe93e3566a5a2e10 100644 GIT binary patch literal 1518 zcmbVMO>f&U480rhf8g9p0yGY~-3s(Dq!|#P-G;8+B`8qErW38Q=;_00HtfHTvh1{L zT43l=67|UU_{bx;@B*%ArRV`>N}_g9kpZ_sxD=-Nw$lZC{JKb!G&wqgFD;r@;x4UK7Ix&p5lHROh{C~Ey3Iiz@K)+|haBFe?rY0o;h-_p$`UOUq+8UnSg#8w zNm~%Q1n;DhPI5>fVNuiyt?hEIjReWZWykHI-grsEmR#X6ONP{DFmIgbz7f;ZH9Ob`bjy|AgDZ z$i~?qELY9hqJGcY2URbVi1G|vZ>(5jn%v#pDKFAwGJ*Mns2eVkLffHOdBy#g}Xx{%{cs%}wM|e?{s;6cn972iSOmvuF6Z#_cE* z`6@5=fS2MPgN?h)Xq_D}O5p?}M5xm>x)~|O`m<9;nd8XEb2bj|bL|ZKYxFx!0G62+ zHD=-g8 zGHJt8;K4oW4SG(6uX#{=hkgpqL?@)elKsTSucOo1>>Jt!Yj_)lJm}GjvwjS00Ks1j zR>-S>I{z)pr)h6T8|NB(I-T;h%>#MMt0FJ49S`Q3QP66|Gf6s4o}PGE+0|QA1=aWt z7FD+#D#;Tp^bVx8EJv8QjcBpEvVOhhZiGQUh6+(ZWspe`P=lI7VA=h8tZU8d!?Opd zo(BI&$s6k&+v!m1#H=1Bu?y3fa2zsPzpAAJ0n5fKHTdOiumQpD<+$J-qb*O{^+wvT s%fg&9S5WbRx0f!1-n?0tmy2uYKfEnBFZ302m3n%yn9Vx842A0 diff --git a/src/MarcSync/Utils.lua b/src/MarcSync/Dienstprogramme.lua similarity index 68% rename from src/MarcSync/Utils.lua rename to src/MarcSync/Dienstprogramme.lua index 194e2b2..b6ae53f 100644 --- a/src/MarcSync/Utils.lua +++ b/src/MarcSync/Dienstprogramme.lua @@ -1,17 +1,17 @@ -local AuthorizationError = require(script.Parent.Errors.Authorization) -local CollectionError = require(script.Parent.Errors.Collection) -local EntryError = require(script.Parent.Errors.Entry) +local AuthorizationError = require(script.Parent.Errors.Autorisierung) +local CollectionError = require(script.Parent.Errors.Sammlung) +local EntryError = require(script.Parent.Errors.Eintrag) local HttpService = game:GetService("HttpService") -function errorHandler(type: string, resultBody: any, resultObject: {}) +function fehlerMisshandlung(type: string, resultBody: any, resultObject: {}) local Error; if typeof(resultBody) == typeof({}) and resultBody["message"] then Error = resultBody["message"] elseif typeof(resultBody) == typeof("") then Error = resultBody else - Error = "An Unexpected Error occoured." + Error = "Es ist ein unerwarteter Fehler aufgetreten." end if type == "collection" then @@ -37,7 +37,7 @@ end local utils = {} -function utils.makeHTTPRequest(type: string, method: string, url: string, body: {}, authorization: string):{["success"]: boolean, ["message"]: string} +function utils.macheHypertexttransferprotokollAnfrage(type: string, method: string, url: string, body: {}, authorization: string):{["success"]: boolean, ["message"]: string} local resultObj; local resultBody; local success = pcall(function() @@ -51,10 +51,10 @@ function utils.makeHTTPRequest(type: string, method: string, url: string, body: end end) if success and resultBody and resultBody["success"] then - if resultBody["warning"] then warn('[MarcSync HTTPRequest Handler] MarcSync HTTP Request returned warning for URL "'..url..'" with body: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end + if resultBody["warning"] then warn('[MarkSynchronisation Hypertexttransferprotokoll Misshandler] Die MarcSync-HTTP-Anfrage hat eine Warnung zurückgegeben für die URL "'..url..'" mit Koerper: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end return resultBody end - return errorHandler(type, resultBody, resultObj) + return fehlerMisshandlung(type, resultBody, resultObj) end -return utils \ No newline at end of file +return utils diff --git a/src/MarcSync/Errors/Authorization.lua b/src/MarcSync/Errors/Authorization.lua deleted file mode 100644 index cfb685d..0000000 --- a/src/MarcSync/Errors/Authorization.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - InvalidAccessToken = function(message: string):string - return ("[MarcSync Exception] InvalidAccessToken: %s"):format(message) - end -} \ No newline at end of file diff --git a/src/MarcSync/Errors/Autorisierung.lua b/src/MarcSync/Errors/Autorisierung.lua new file mode 100644 index 0000000..2535fd3 --- /dev/null +++ b/src/MarcSync/Errors/Autorisierung.lua @@ -0,0 +1,5 @@ +return { + InvalidAccessToken = function(message: string):string + return ("[MarkSynchronisationsausnahme] InvaliederZugriffsToken: %s"):format(message) + end +} diff --git a/src/MarcSync/Errors/Collection.lua b/src/MarcSync/Errors/Collection.lua deleted file mode 100644 index c59ddde..0000000 --- a/src/MarcSync/Errors/Collection.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - CollectionNotFound = function(message: string):string - return ("[MarcSync Exception] CollectionNotFound: %s"):format(message) - end, - CollectionAlreadyExists = function(message: string):string - return ("[MarcSync Exception] CollectionAlreadyExists: %s"):format(message) - end -} \ No newline at end of file diff --git a/src/MarcSync/Errors/Eintrag.lua b/src/MarcSync/Errors/Eintrag.lua new file mode 100644 index 0000000..2098947 --- /dev/null +++ b/src/MarcSync/Errors/Eintrag.lua @@ -0,0 +1,8 @@ +return { + InvalidEntryData = function(message: string):string + return ("[MarkSynchronisationsausnahme] InvaliedeEintragsDaten: %s"):format(message) + end, + EntryNotFound = function(message: string):string + return ("[MarkSynchronisationsausnahme] EintragNichtGefunden: %s"):format(message) + end +} diff --git a/src/MarcSync/Errors/Entry.lua b/src/MarcSync/Errors/Entry.lua deleted file mode 100644 index 5d51edb..0000000 --- a/src/MarcSync/Errors/Entry.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - InvalidEntryData = function(message: string):string - return ("[MarcSync Exception] InvalidEntryData: %s"):format(message) - end, - EntryNotFound = function(message: string):string - return ("[MarcSync Exception] EntryNotFound: %s"):format(message) - end -} \ No newline at end of file diff --git a/src/MarcSync/Errors/Sammlung.lua b/src/MarcSync/Errors/Sammlung.lua new file mode 100644 index 0000000..0690dd3 --- /dev/null +++ b/src/MarcSync/Errors/Sammlung.lua @@ -0,0 +1,8 @@ +return { + CollectionNotFound = function(message: string):string + return ("[MarkSynchronisationsausnahme] SammlungNichtGefunden: %s"):format(message) + end, + CollectionAlreadyExists = function(message: string):string + return ("[MarkSynchronisationsausnahme] SammlungExistiertBereits: %s"):format(message) + end +} diff --git a/src/MarcSync/MarcSyncv1.0.lua b/src/MarcSync/MarcSyncv1.0.lua index ef8a2b5..c8dab92 100644 --- a/src/MarcSync/MarcSyncv1.0.lua +++ b/src/MarcSync/MarcSyncv1.0.lua @@ -5,53 +5,53 @@ local tokens = { -- DO NOT EDIT THE FOLLOWING LINES BELOW, UNLESS YOU KNOW WHAT YOU ARE DOING! -local Utils = require(script.Parent.Utils) +local Utils = require(script.Parent.Dienstprogramme) local MarcSyncClient = {} -MarcSyncClient.getVersion = function(self:typeof(MarcSyncClient), clientId: number?):string +MarcSyncClient.bekommeVersion = function(self:typeof(MarcSyncClient), clientId: number?):string self:_checkInstallation() local url = "" if clientId then url = "/"..clientId end - local result = Utils.makeHTTPRequest("GET", "https://api.marcsync.dev/v0/utils/version"..url); + local result = Utils.macheHypertexttransferprotokollAnfrage("GET", "https://api.marcsync.dev/v0/utils/version"..url); return result["version"] end -MarcSyncClient.createCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new()) - if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end - if not collectionName then error("No CollectionName Provided") end - local result = Utils.makeHTTPRequest("collection", "POST", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken); +MarcSyncClient.erzeugeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new()) + if not self._accessToken then error("[MarkSynchronisation] Bitte legen Sie ein Token fest, bevor Sie MarcSync verwenden.") end + if not collectionName then error("Kein CollectionName angegeben") end + local result = Utils.macheHypertexttransferprotokollAnfrage("collection", "POST", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken); if not result["success"] then error(result["errorMessage"]) end - result = require(script.Parent.Objects.Collection).new(collectionName, self._accessToken) + result = require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken) return result end -MarcSyncClient.fetchCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new()) +MarcSyncClient.bringeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new()) self:_checkInstallation() - if not collectionName then error("No CollectionName Provided") end - local result = Utils.makeHTTPRequest("collection", "GET", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken); + if not collectionName then error("Kein CollectionName angegeben") end + local result = Utils.macheHypertexttransferprotokollAnfrage("collection", "GET", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken); if not result["success"] then error(result["errorMessage"]) end - result = require(script.Parent.Objects.Collection).new(collectionName, self._accessToken) + result = require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken) return result end -MarcSyncClient.getCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new()) - if typeof(self) ~= "table" then error("Please use : instead of .") end +MarcSyncClient.bekommeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new()) + if typeof(self) ~= "table" then error("Bitte verwenden Sie : anstelle von .") end self:_checkInstallation() - if not collectionName then error("No CollectionName Provided") end - return require(script.Parent.Objects.Collection).new(collectionName, self._accessToken) + if not collectionName then error("Kein CollectionName angegeben") end + return require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken) end return { - new = function(accessToken: string):typeof(MarcSyncClient) - if not accessToken then warn("Token not provided while creating a new MarcSync Object.") end - if not tokens[accessToken] then warn("Token provided for creating a new MarcSync Object not Found in Token Table, using it as token instead.") else accessToken = tokens[accessToken] end + neu = function(accessToken: string):typeof(MarcSyncClient) + if not accessToken then warn("Beim Erstellen eines neuen MarcSync-Objekts wurde kein Token bereitgestellt.") end + if not tokens[accessToken] then warn("Token zum Erstellen eines neuen MarcSync-Objekts, das nicht in der Token-Tabelle gefunden wird und stattdessen als Token verwendet wird.") else accessToken = tokens[accessToken] end local self = {} self._accessToken = accessToken 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 + if not self then error("Bitte richten Sie MarcSync ein, bevor Sie MarcSync verwenden.") end + if not self._accessToken then error("[MarkSynchronisation] Bitte legen Sie ein Token fest, bevor Sie MarcSync verwenden.") end --print(HttpService.HttpEnabled) --if not HttpService.HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end end @@ -62,4 +62,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 deleted file mode 100644 index 73c0d79..0000000 --- a/src/MarcSync/Objects/Collection.lua +++ /dev/null @@ -1,76 +0,0 @@ -local Utils = require(script.Parent.Parent.Utils) -local Entry = require(script.Parent.Entry) - -local types = { - EntryData = require(script.Parent.Parent.Types.EntryData).getType() -} - -local Collection = {} - -Collection.createEntry = 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 - local result = Utils.makeHTTPRequest("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken); - - if result["success"] and result["objectId"] then - data["_id"] = result["objectId"] - result = require(script.Parent.Entry).new(self._collectionName, data, self._accessToken) - else - error(result["errorMessage"]) - end - - return result -end - -Collection.updateEntries = 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 - local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/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())} - 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 result["success"] and result["entries"] then - local _result = {} - for index,entry in pairs(result["entries"]) do - _result[index] = require(script.Parent.Entry).new(self._collectionName, entry, self._accessToken) - end - result = _result - else - error(result["errorMessage"]) - end - - return result -end - -Collection.deleteEntries = 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 - local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken); - if not result["success"] then error(result["errorMessage"]) end - - return result["deletedEntries"] -end - -Collection.drop = function(self:typeof(Collection)) - if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end - local result = Utils.makeHTTPRequest("collection", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken); - if not result["success"] then error(result["errorMessage"]) end - self = nil -end - -return { - new = function(collectionName: string, accessToken: string):typeof(Collection) - local self = {} - self._collectionName = collectionName - self._accessToken = accessToken - - self = setmetatable(self, { - __index = Collection - }) - - return self - end -} \ No newline at end of file diff --git a/src/MarcSync/Objects/Eintrag.lua b/src/MarcSync/Objects/Eintrag.lua new file mode 100644 index 0000000..e37307d --- /dev/null +++ b/src/MarcSync/Objects/Eintrag.lua @@ -0,0 +1,56 @@ +local Utils = require(script.Parent.Parent.Dienstprogramme) + +local types = { + EntryData = require(script.Parent.Parent.Types.EntryData).bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar() +} + +local Entry = {} + +Entry.bekommeWert = function(self:typeof(Entry), key:string):any + if not key then return nil end + return self._entryData[key] +end + +Entry.bekommeWerte = function(self:typeof(Entry)):typeof(types.EntryData) + return self._entryData +end + +Entry.aktualisiereWerte = function(self:typeof(Entry), data:typeof(types.EntryData)):number + local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "PUT", "https://api.marcsync.dev/v0/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 + self._entryData[i] = v + end + elseif not result["success"] then + error(result["errorMessage"]) + end + + return result["modifiedEntries"] +end + +Entry.loesche = function(self:typeof(Entry)) + if typeof(self) ~= "table" then error("Bitte verwenden Sie : anstelle von .") end + local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken); + + if not result["success"] then error(result["errorMessage"]) end + self = nil + +end + +return { + neu = function(tableId:string, entryData:typeof(types.EntryData), accessToken:string):typeof(Entry) + if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarkSynchronisation: Eintrag] Es wurde versucht, ein ungültiges Eintragsobjekt zu erstellen.") end + local self = {} + self._tableId = tableId + self._entryData = entryData + self._objectId = entryData["_id"] + self._accessToken = accessToken + + self = setmetatable(self, { + __index = Entry + }) + + return self + end +} diff --git a/src/MarcSync/Objects/Entry.lua b/src/MarcSync/Objects/Entry.lua deleted file mode 100644 index d28907e..0000000 --- a/src/MarcSync/Objects/Entry.lua +++ /dev/null @@ -1,56 +0,0 @@ -local Utils = require(script.Parent.Parent.Utils) - -local types = { - EntryData = require(script.Parent.Parent.Types.EntryData).getType() -} - -local Entry = {} - -Entry.getValue = function(self:typeof(Entry), key:string):any - if not key then return nil end - return self._entryData[key] -end - -Entry.getValues = function(self:typeof(Entry)):typeof(types.EntryData) - return self._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); - - if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then - for i,v in pairs(data) do - self._entryData[i] = v - end - elseif not result["success"] then - error(result["errorMessage"]) - end - - return result["modifiedEntries"] -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); - - if not result["success"] then error(result["errorMessage"]) end - self = nil - -end - -return { - new = function(tableId:string, entryData:typeof(types.EntryData), accessToken:string):typeof(Entry) - if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarcSync: Entry] Tried creating invalid Entry Object.") end - local self = {} - self._tableId = tableId - self._entryData = entryData - self._objectId = entryData["_id"] - self._accessToken = accessToken - - self = setmetatable(self, { - __index = Entry - }) - - return self - end -} \ No newline at end of file diff --git a/src/MarcSync/Objects/Sammlung.lua b/src/MarcSync/Objects/Sammlung.lua new file mode 100644 index 0000000..51a515a --- /dev/null +++ b/src/MarcSync/Objects/Sammlung.lua @@ -0,0 +1,76 @@ +local Utils = require(script.Parent.Parent.Dienstprogramme) +local Entry = require(script.Parent.Eintrag) + +local types = { + EntryData = require(script.Parent.Parent.Types.EintragsDaten).bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar() +} + +local Collection = {} + +Collection.erzeugeEintrag = function(self:typeof(Collection), data:typeof(types.EntryData)):typeof(Entry.new()) + if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end + 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 + data["_id"] = result["objectId"] + result = require(script.Parent.Entry).neu(self._collectionName, data, self._accessToken) + else + error(result["errorMessage"]) + end + + return result +end + +Collection.aktualisiereEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number + if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end + 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 + + return result["modifiedEntries"] +end + +Collection.bekommeEintraege = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[number]:typeof(Entry.new())} + 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 + 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 + local _result = {} + for index,entry in pairs(result["entries"]) do + _result[index] = require(script.Parent.Entry).neu(self._collectionName, entry, self._accessToken) + end + result = _result + else + error(result["errorMessage"]) + end + + return result +end + +Collection.loescheEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData)):number + if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end + 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 + + return result["deletedEntries"] +end + +Collection.fallenlassen = function(self:typeof(Collection)) + if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end + 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 + self = nil +end + +return { + neu = function(collectionName: string, accessToken: string):typeof(Collection) + local self = {} + self._collectionName = collectionName + self._accessToken = accessToken + + self = setmetatable(self, { + __index = Collection + }) + + return self + end +} diff --git a/src/MarcSync/Types/EintragsDaten.lua b/src/MarcSync/Types/EintragsDaten.lua new file mode 100644 index 0000000..5b0dc0a --- /dev/null +++ b/src/MarcSync/Types/EintragsDaten.lua @@ -0,0 +1,9 @@ +type EntryData = { + [string]: any +} + +return { + bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar = function(): EntryData + return {} + end, +} diff --git a/src/MarcSync/Types/EntryData.lua b/src/MarcSync/Types/EntryData.lua deleted file mode 100644 index c9f8aa1..0000000 --- a/src/MarcSync/Types/EntryData.lua +++ /dev/null @@ -1,9 +0,0 @@ -type EntryData = { - [string]: any -} - -return { - getType = function(): EntryData - return {} - end, -} \ No newline at end of file