From 21fc85db2dae2ee3ef7b3d7ee9be2e0703ca0186 Mon Sep 17 00:00:00 2001 From: Marcel Lorbeer Date: Sat, 18 Nov 2023 01:01:52 +0100 Subject: [PATCH] Revert "yes." --- LICENSE | 21 ----- README.md | Bin 1518 -> 48 bytes 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 +++ .../{Dienstprogramme.lua => Utils.lua} | 18 ++--- 16 files changed, 193 insertions(+), 214 deletions(-) delete mode 100644 LICENSE create mode 100644 src/MarcSync/Errors/Authorization.lua delete mode 100644 src/MarcSync/Errors/Autorisierung.lua create mode 100644 src/MarcSync/Errors/Collection.lua delete mode 100644 src/MarcSync/Errors/Eintrag.lua create mode 100644 src/MarcSync/Errors/Entry.lua delete mode 100644 src/MarcSync/Errors/Sammlung.lua create mode 100644 src/MarcSync/Objects/Collection.lua delete mode 100644 src/MarcSync/Objects/Eintrag.lua create mode 100644 src/MarcSync/Objects/Entry.lua delete mode 100644 src/MarcSync/Objects/Sammlung.lua delete mode 100644 src/MarcSync/Types/EintragsDaten.lua create mode 100644 src/MarcSync/Types/EntryData.lua rename src/MarcSync/{Dienstprogramme.lua => Utils.lua} (68%) diff --git a/LICENSE b/LICENSE deleted file mode 100644 index a04e554..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -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 c17e94bd2633d5b2ddc40a0efe93e3566a5a2e10..411c66cc4010da1ecf6c13eb021bae55d7a13d96 100644 GIT binary patch literal 48 ycmezWPnki1A(tVMp@<=wp_rkPArDCF0(nUc6+k+fA%`K8Ar&ZE!obVG#Q*>x842A0 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%yn9V 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 new file mode 100644 index 0000000..d28907e --- /dev/null +++ b/src/MarcSync/Objects/Entry.lua @@ -0,0 +1,56 @@ +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 deleted file mode 100644 index 51a515a..0000000 --- a/src/MarcSync/Objects/Sammlung.lua +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index 5b0dc0a..0000000 --- a/src/MarcSync/Types/EintragsDaten.lua +++ /dev/null @@ -1,9 +0,0 @@ -type EntryData = { - [string]: any -} - -return { - bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar = function(): EntryData - return {} - end, -} diff --git a/src/MarcSync/Types/EntryData.lua b/src/MarcSync/Types/EntryData.lua new file mode 100644 index 0000000..c9f8aa1 --- /dev/null +++ b/src/MarcSync/Types/EntryData.lua @@ -0,0 +1,9 @@ +type EntryData = { + [string]: any +} + +return { + getType = function(): EntryData + return {} + end, +} \ No newline at end of file diff --git a/src/MarcSync/Dienstprogramme.lua b/src/MarcSync/Utils.lua similarity index 68% rename from src/MarcSync/Dienstprogramme.lua rename to src/MarcSync/Utils.lua index b6ae53f..194e2b2 100644 --- a/src/MarcSync/Dienstprogramme.lua +++ b/src/MarcSync/Utils.lua @@ -1,17 +1,17 @@ -local AuthorizationError = require(script.Parent.Errors.Autorisierung) -local CollectionError = require(script.Parent.Errors.Sammlung) -local EntryError = require(script.Parent.Errors.Eintrag) +local AuthorizationError = require(script.Parent.Errors.Authorization) +local CollectionError = require(script.Parent.Errors.Collection) +local EntryError = require(script.Parent.Errors.Entry) local HttpService = game:GetService("HttpService") -function fehlerMisshandlung(type: string, resultBody: any, resultObject: {}) +function errorHandler(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 = "Es ist ein unerwarteter Fehler aufgetreten." + Error = "An Unexpected Error occoured." end if type == "collection" then @@ -37,7 +37,7 @@ end local utils = {} -function utils.macheHypertexttransferprotokollAnfrage(type: string, method: string, url: string, body: {}, authorization: string):{["success"]: boolean, ["message"]: string} +function utils.makeHTTPRequest(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.macheHypertexttransferprotokollAnfrage(type: string, method: stri end end) if success and resultBody and resultBody["success"] then - 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 + if resultBody["warning"] then warn('[MarcSync HTTPRequest Handler] MarcSync HTTP Request returned warning for URL "'..url..'" with body: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end return resultBody end - return fehlerMisshandlung(type, resultBody, resultObj) + return errorHandler(type, resultBody, resultObj) end -return utils +return utils \ No newline at end of file