commit 0a969776dd3b8abe38fc5ac746d44bb7aea97975 Author: andrewlalis Date: Fri Sep 5 11:47:45 2025 -0400 Added stuff. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa8aad6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +.dub +docs.json +__dummy.html +docs/ +/party-signup-api +party-signup-api.so +party-signup-api.dylib +party-signup-api.dll +party-signup-api.a +party-signup-api.lib +party-signup-api-test-* +*.exe +*.pdb +*.o +*.obj +*.lst diff --git a/api/data/grace-birthday.json b/api/data/grace-birthday.json new file mode 100644 index 0000000..8005720 --- /dev/null +++ b/api/data/grace-birthday.json @@ -0,0 +1,16 @@ +{ + "entries": [ + { + "comment": "Potatoes", + "name": "Andrew" + }, + { + "comment": "Soup!", + "name": "Andrew" + }, + { + "comment": "Cakes", + "name": "Grace" + } + ] +} \ No newline at end of file diff --git a/api/dub.json b/api/dub.json new file mode 100644 index 0000000..deaac5c --- /dev/null +++ b/api/dub.json @@ -0,0 +1,12 @@ +{ + "authors": [ + "Andrew Lalis" + ], + "copyright": "Copyright © 2025, Andrew Lalis", + "dependencies": { + "handy-http-starter": "~>1.6.0" + }, + "description": "A minimal D application.", + "license": "MIT", + "name": "party-signup-api" +} \ No newline at end of file diff --git a/api/dub.selections.json b/api/dub.selections.json new file mode 100644 index 0000000..4e40794 --- /dev/null +++ b/api/dub.selections.json @@ -0,0 +1,19 @@ +{ + "fileVersion": 1, + "versions": { + "asdf": "0.7.17+commit.5.g7f77a30", + "dxml": "0.4.5", + "handy-http-data": "1.3.0", + "handy-http-handlers": "1.1.0", + "handy-http-primitives": "1.8.1", + "handy-http-starter": "1.6.0", + "handy-http-transport": "1.8.0", + "handy-http-websockets": "1.2.0", + "mir-algorithm": "3.22.4", + "mir-core": "1.7.3", + "path-matcher": "1.2.0", + "silly": "1.1.1", + "slf4d": "4.1.1", + "streams": "3.6.0" + } +} diff --git a/api/party-signup-api b/api/party-signup-api new file mode 100755 index 0000000..385ecce Binary files /dev/null and b/api/party-signup-api differ diff --git a/api/source/app.d b/api/source/app.d new file mode 100644 index 0000000..8f7e7a6 --- /dev/null +++ b/api/source/app.d @@ -0,0 +1,60 @@ +import slf4d; +import handy_http_starter; + +void main() { + Http1TransportConfig transportConfig = defaultConfig(); + transportConfig.port = 8080; + HttpTransport transport = new TaskPoolHttp1Transport(new AppHandler(), transportConfig); + transport.start(); +} + +struct Entry { + string partyName; + string name; + string comment; +} + +class AppHandler : HttpRequestHandler { + void handle(ref ServerHttpRequest request, ref ServerHttpResponse response) { + response.headers.add("Access-Control-Allow-Origin", "*"); + response.headers.add("Access-Control-Allow-Methods", "*"); + response.headers.add("Access-Control-Allow-Headers", "Content-Type"); + + if (request.method == HttpMethod.GET) { + getEntries(request.getParamAs!string("party"), response); + } else if (request.method == HttpMethod.POST) { + auto payload = readJsonBodyAs!Entry(request); + addEntry(payload); + } + } +} + +void getEntries(string partyName, ref ServerHttpResponse response) { + import std.file; + import std.path; + import std.json; + if (!exists("data")) return; + const filename = buildPath("data", partyName ~ ".json"); + JSONValue root = parseJSON(readText(filename)); + response.writeBodyString(root.object["entries"].toJSON(), ContentTypes.APPLICATION_JSON); +} + +void addEntry(in Entry payload) { + import std.file; + import std.path; + import std.json; + if (!exists("data")) mkdir("data"); + const filename = buildPath("data", payload.partyName ~ ".json"); + if (!exists(filename)) { + JSONValue obj = JSONValue.emptyObject; + obj.object["entries"] = JSONValue.emptyArray; + write(filename, obj.toPrettyString()); + } + JSONValue root = parseJSON(readText(filename)); + JSONValue node = JSONValue.emptyObject; + node.object["name"] = JSONValue(payload.name); + node.object["comment"] = JSONValue(payload.comment); + root.object["entries"].array ~= node; + write(filename, root.toPrettyString()); + info("Added entry."); +} diff --git a/app.html b/app.html new file mode 100644 index 0000000..a1c8a8f --- /dev/null +++ b/app.html @@ -0,0 +1,116 @@ + + + + Party Signup 🎉 + + + + +

Party Signup 🎉

+

A simple list of people and what they're bringing!

+ + + + + + + + + + +
NameBringing
+ +

Register below!

+
+ + +
+
+ + +
+
+ +
+ + + + \ No newline at end of file