From 03db7c06da922b2de9999db0a0f2237487c9310a Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Tue, 11 Apr 2023 16:09:07 +0100 Subject: [PATCH 1/6] Project setup --- Gemfile.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 66064703c7..0d616e4a27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,6 +52,7 @@ GEM PLATFORMS ruby + x64-mingw-ucrt DEPENDENCIES rspec @@ -63,4 +64,4 @@ RUBY VERSION ruby 3.0.2p107 BUNDLED WITH - 2.2.26 + 2.4.11 From aeed87c1e2585d359179bd01212e5fa4f6692b99 Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Tue, 11 Apr 2023 21:53:25 +0100 Subject: [PATCH 2/6] Initial attempt --- README.md | 8 + app.rb | 25 + config.ru | 2 + diagram.excalidraw | 1519 +++++++++++++++++++++++++++++++++++++ lib/message.rb | 3 + lib/message_repository.rb | 63 ++ spec/app_spec.rb | 37 + views/message.erb | 11 + 8 files changed, 1668 insertions(+) create mode 100644 app.rb create mode 100644 config.ru create mode 100644 diagram.excalidraw create mode 100644 lib/message.rb create mode 100644 lib/message_repository.rb create mode 100644 spec/app_spec.rb create mode 100644 views/message.erb diff --git a/README.md b/README.md index 465eda879b..a183fcd963 100644 --- a/README.md +++ b/README.md @@ -23,18 +23,26 @@ As a Maker So that I can let people know what I am doing I want to post a message (peep) to chitter +POST message to chitter + As a maker So that I can see what others are saying I want to see all peeps in reverse chronological order +GET message in reverse chronological order (newest first) + As a Maker So that I can better appreciate the context of a peep I want to see the time at which it was made +GET the time that the message was posted + As a Maker So that I can post messages on Chitter as me I want to sign up for Chitter +POST and GET user input by creating a sign up form + HARDER As a Maker diff --git a/app.rb b/app.rb new file mode 100644 index 0000000000..16629a1784 --- /dev/null +++ b/app.rb @@ -0,0 +1,25 @@ +# file: app.rb +require 'sinatra/base' +require 'sinatra/reloader' +# require_relative 'lib/message_repository' + +class Application < Sinatra::Base + # This allows the app code to refresh + # without having to restart the server. + configure :development do + register Sinatra::Reloader + end +# post '/message' do +# #repo = MessageRepository.new +# new_message = Message.new +# new_message.time = params[:time].to_i +# new_message.date = params[:date] +# new_message.content = params[:content] + +# return erb(new_message) +# end + # Confirm that new messages have been added to the database + get '/message' do + return erb(:message) + end +end \ No newline at end of file diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..abcd839502 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require '../app' +run Application \ No newline at end of file diff --git a/diagram.excalidraw b/diagram.excalidraw new file mode 100644 index 0000000000..5ed3385886 --- /dev/null +++ b/diagram.excalidraw @@ -0,0 +1,1519 @@ +{ + "type": "excalidraw", + "version": 2, + "source": "https://marketplace.visualstudio.com/items?itemName=pomdtr.excalidraw-editor", + "elements": [ + { + "id": "Qlm8ZdFM8eE5hX7vB9VFP", + "type": "rectangle", + "x": 246.39999389648438, + "y": 147.60000610351562, + "width": 96.39999389648438, + "height": 114, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1746437509, + "version": 104, + "versionNonce": 1561636133, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "i0d4SkOBL22orh6c2wtA9" + } + ], + "updated": 1681227260328, + "link": null, + "locked": false + }, + { + "id": "i0d4SkOBL22orh6c2wtA9", + "type": "text", + "x": 254.09999084472656, + "y": 152.60000610351562, + "width": 81, + "height": 104, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 2050134731, + "version": 77, + "versionNonce": 766763947, + "isDeleted": false, + "boundElements": null, + "updated": 1681227260328, + "link": null, + "locked": false, + "text": "POST \nmessage\nto \nchitter", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 96, + "containerId": "Qlm8ZdFM8eE5hX7vB9VFP", + "originalText": "POST message to chitter" + }, + { + "id": "CPOKNTTbhJmQj4bAMsqZi", + "type": "rectangle", + "x": 488.800048828125, + "y": 128.40000915527344, + "width": 157, + "height": 157, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 923842635, + "version": 161, + "versionNonce": 1780008715, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "E65_F51Szr8UUSbNDGDJ6" + } + ], + "updated": 1681227261594, + "link": null, + "locked": false + }, + { + "id": "E65_F51Szr8UUSbNDGDJ6", + "type": "text", + "x": 494.300048828125, + "y": 141.90000915527344, + "width": 146, + "height": 130, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1633491051, + "version": 133, + "versionNonce": 1979925285, + "isDeleted": false, + "boundElements": null, + "updated": 1681227261594, + "link": null, + "locked": false, + "text": "GET message \nin reverse \nchronological \norder (newest \nfirst)", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 122, + "containerId": "CPOKNTTbhJmQj4bAMsqZi", + "originalText": "GET message in reverse chronological order (newest first)" + }, + { + "id": "3d8IvWZP9uDYj7k8Zdr6w", + "type": "rectangle", + "x": 783.60009765625, + "y": 138.20005798339844, + "width": 146, + "height": 145, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 844451787, + "version": 316, + "versionNonce": 2091729669, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "AAyjJJF1MTEyws04T7smc" + } + ], + "updated": 1681227265110, + "link": null, + "locked": false + }, + { + "id": "AAyjJJF1MTEyws04T7smc", + "type": "text", + "x": 790.10009765625, + "y": 158.70005798339844, + "width": 133, + "height": 104, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 7469029, + "version": 271, + "versionNonce": 1644174283, + "isDeleted": false, + "boundElements": null, + "updated": 1681227265110, + "link": null, + "locked": false, + "text": "GET the \ntime that \nthe message \nwas posted", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 96, + "containerId": "3d8IvWZP9uDYj7k8Zdr6w", + "originalText": "GET the time that the message was posted" + }, + { + "id": "cE8cJFsXGyh3bCdd7t0Yn", + "type": "rectangle", + "x": 1053.2001342773438, + "y": 143.3999786376953, + "width": 159, + "height": 152, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1607557861, + "version": 189, + "versionNonce": 1240169867, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "eYCaOD2_MsqMEz8qmNw5t" + } + ], + "updated": 1681227263943, + "link": null, + "locked": false + }, + { + "id": "eYCaOD2_MsqMEz8qmNw5t", + "type": "text", + "x": 1059.2001342773438, + "y": 154.3999786376953, + "width": 147, + "height": 130, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 935038693, + "version": 147, + "versionNonce": 985478309, + "isDeleted": false, + "boundElements": null, + "updated": 1681227263943, + "link": null, + "locked": false, + "text": "POST and \nGET user \ninput by \ncreating a sign\nup form", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 122, + "containerId": "cE8cJFsXGyh3bCdd7t0Yn", + "originalText": "POST and GET user input by creating a sign up form" + }, + { + "id": "NGl936x7vlL-IIV8Ugvhw", + "type": "rectangle", + "x": 249.2000732421875, + "y": 291.0000305175781, + "width": 92, + "height": 110, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1383635557, + "version": 68, + "versionNonce": 664402411, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "Rf52_wkZencIgbEI6tAxW" + } + ], + "updated": 1681227362792, + "link": null, + "locked": false + }, + { + "id": "Rf52_wkZencIgbEI6tAxW", + "type": "text", + "x": 253.7000732421875, + "y": 307.0000305175781, + "width": 82, + "height": 78, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1459562053, + "version": 66, + "versionNonce": 1501352677, + "isDeleted": false, + "boundElements": null, + "updated": 1681227357828, + "link": null, + "locked": false, + "text": "Page: \npost a \nmessage", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 70, + "containerId": "NGl936x7vlL-IIV8Ugvhw", + "originalText": "Page: post a message" + }, + { + "id": "ud1T7kr_WiUir0PwXH_X0", + "type": "rectangle", + "x": 512, + "y": 304, + "width": 114.79998779296875, + "height": 111.80001831054688, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1187387365, + "version": 39, + "versionNonce": 1907983499, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "unVois9FZOkaZBl8plHrd" + } + ], + "updated": 1681227365790, + "link": null, + "locked": false + }, + { + "id": "unVois9FZOkaZBl8plHrd", + "type": "text", + "x": 518.8999938964844, + "y": 333.90000915527344, + "width": 101, + "height": 52, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 529024645, + "version": 32, + "versionNonce": 1598859621, + "isDeleted": false, + "boundElements": null, + "updated": 1681227317370, + "link": null, + "locked": false, + "text": "Page: view\nmessages", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 44, + "containerId": "ud1T7kr_WiUir0PwXH_X0", + "originalText": "Page: view messages" + }, + { + "id": "FUIBxfdTitx4HZpZSuHrQ", + "type": "rectangle", + "x": 804.0000610351562, + "y": 306.4000244140625, + "width": 110, + "height": 114, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 137939819, + "version": 65, + "versionNonce": 1363418571, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "epL_gtGnaoGwtfQlYHP7k" + } + ], + "updated": 1681227368203, + "link": null, + "locked": false + }, + { + "id": "epL_gtGnaoGwtfQlYHP7k", + "type": "text", + "x": 813.0000610351562, + "y": 324.4000244140625, + "width": 92, + "height": 78, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1416595435, + "version": 52, + "versionNonce": 1424892165, + "isDeleted": false, + "boundElements": null, + "updated": 1681227366547, + "link": null, + "locked": false, + "text": "Page: \nview \nmessages", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 70, + "containerId": "FUIBxfdTitx4HZpZSuHrQ", + "originalText": "Page: view messages" + }, + { + "id": "NVqam2Yg_kLaYNMQIjcaN", + "type": "rectangle", + "x": 1078.4000244140625, + "y": 315.6000061035156, + "width": 121.199951171875, + "height": 110.20004272460938, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1048177547, + "version": 40, + "versionNonce": 1533634315, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "9fdurilP7fR6vJNBab39N" + } + ], + "updated": 1681227370633, + "link": null, + "locked": false + }, + { + "id": "9fdurilP7fR6vJNBab39N", + "type": "text", + "x": 1085, + "y": 344.7000274658203, + "width": 108, + "height": 52, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1646283851, + "version": 34, + "versionNonce": 2143511493, + "isDeleted": false, + "boundElements": null, + "updated": 1681227369059, + "link": null, + "locked": false, + "text": "Page: sign \nup form", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 44, + "containerId": "NVqam2Yg_kLaYNMQIjcaN", + "originalText": "Page: sign up form" + }, + { + "id": "o_s6t12YX5JSoF6aFcnne", + "type": "line", + "x": 291.6000061035156, + "y": 261.8000183105469, + "width": 2, + "height": 29.399993896484375, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1454831237, + "version": 21, + "versionNonce": 1573094469, + "isDeleted": false, + "boundElements": null, + "updated": 1681227375395, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 2, + 29.399993896484375 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "ijMxYrMme75qNcICqty94", + "type": "line", + "x": 571.6000366210938, + "y": 285.8000183105469, + "width": 1.199951171875, + "height": 17.399993896484375, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1968803467, + "version": 11, + "versionNonce": 1538791339, + "isDeleted": false, + "boundElements": null, + "updated": 1681227379945, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 1.199951171875, + 17.399993896484375 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "DyN7rKbJfjnBmQg4pyw8_", + "type": "line", + "x": 853.2000122070312, + "y": 283.3999938964844, + "width": 0.4000244140625, + "height": 25.4000244140625, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1832307845, + "version": 26, + "versionNonce": 1832595915, + "isDeleted": false, + "boundElements": null, + "updated": 1681227384803, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.4000244140625, + 25.4000244140625 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "vkh4XCfhjHZipgXCH_YYA", + "type": "line", + "x": 1135.5999755859375, + "y": 296.20001220703125, + "width": 0.4000244140625, + "height": 19.79998779296875, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "#fa5252", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 2090984549, + "version": 14, + "versionNonce": 851850283, + "isDeleted": false, + "boundElements": null, + "updated": 1681227388777, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 0.4000244140625, + 19.79998779296875 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "oi25HcSpUUihoCQqiMMSl", + "type": "rectangle", + "x": 680.4000549316406, + "y": 506.6000061035156, + "width": 98, + "height": 71.00001525878906, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 291595627, + "version": 39, + "versionNonce": 425602597, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "Zr8ayNwLjWn4xXsS5Lanu" + }, + { + "id": "4il5P8cc_-oBz5bO6TJLN", + "type": "arrow" + }, + { + "id": "bs_YWAKLdpA3eLWbsnAKT", + "type": "arrow" + } + ], + "updated": 1681228185815, + "link": null, + "locked": false + }, + { + "id": "Zr8ayNwLjWn4xXsS5Lanu", + "type": "text", + "x": 687.9000549316406, + "y": 516.1000137329102, + "width": 83, + "height": 52, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1537721163, + "version": 19, + "versionNonce": 938881349, + "isDeleted": false, + "boundElements": null, + "updated": 1681227706711, + "link": null, + "locked": false, + "text": "Project \nprogram", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 44, + "containerId": "oi25HcSpUUihoCQqiMMSl", + "originalText": "Project program" + }, + { + "id": "Caxudrve64RypKt5oib9z", + "type": "rectangle", + "x": 425.2000732421875, + "y": 637.6000213623047, + "width": 127, + "height": 114, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 246690187, + "version": 102, + "versionNonce": 191381573, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "S-rZa4QzF7WbwmBU3ESkN" + }, + { + "id": "bMaMxwNqTD4K5GYGMTq0g", + "type": "arrow" + } + ], + "updated": 1681228158196, + "link": null, + "locked": false + }, + { + "id": "S-rZa4QzF7WbwmBU3ESkN", + "type": "text", + "x": 434.2000732421875, + "y": 642.6000213623047, + "width": 109, + "height": 104, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1302419109, + "version": 116, + "versionNonce": 77467787, + "isDeleted": false, + "boundElements": null, + "updated": 1681227824775, + "link": null, + "locked": false, + "text": "app.rb:\ncontains \nproduction \ncode", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 96, + "containerId": "Caxudrve64RypKt5oib9z", + "originalText": "app.rb:\ncontains production code" + }, + { + "id": "jrCf0AKUxG6Ah6XCVY2p3", + "type": "rectangle", + "x": 680.0000915527344, + "y": 615.1999969482422, + "width": 113, + "height": 166, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1012566853, + "version": 56, + "versionNonce": 1598485701, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "_fMeUF2r_yMY-FhGnmp3R" + }, + { + "id": "PfW3aoR9s49QJDdwc1nB0", + "type": "arrow" + } + ], + "updated": 1681228154955, + "link": null, + "locked": false + }, + { + "id": "_fMeUF2r_yMY-FhGnmp3R", + "type": "text", + "x": 684.7000732421875, + "y": 620.1999969482422, + "width": 103, + "height": 156, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1929142859, + "version": 69, + "versionNonce": 1660470213, + "isDeleted": false, + "boundElements": null, + "updated": 1681228091232, + "link": null, + "locked": false, + "text": "config.ru: \nthe file \nthat runs\nthe \napplication\n", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 148, + "containerId": "jrCf0AKUxG6Ah6XCVY2p3", + "originalText": "config.ru: the file that runs the application\n" + }, + { + "id": "K7OBhsoR3eWsdiSyHnYjI", + "type": "rectangle", + "x": 883.6002502441406, + "y": 537.4000396728516, + "width": 65, + "height": 54, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 219546405, + "version": 73, + "versionNonce": 1813214149, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "fGFMXExhMJLRF4ugf1rOm" + }, + { + "id": "4oXJfQ0wGl622l3-2U2p3", + "type": "arrow" + } + ], + "updated": 1681228146807, + "link": null, + "locked": false + }, + { + "id": "fGFMXExhMJLRF4ugf1rOm", + "type": "text", + "x": 894.1002502441406, + "y": 551.4000396728516, + "width": 44, + "height": 26, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 288626693, + "version": 37, + "versionNonce": 1038034469, + "isDeleted": false, + "boundElements": null, + "updated": 1681228123748, + "link": null, + "locked": false, + "text": "spec", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 18, + "containerId": "K7OBhsoR3eWsdiSyHnYjI", + "originalText": "spec" + }, + { + "id": "5llvR0uOqRu1AaQwD1_uI", + "type": "rectangle", + "x": 946.4000549316406, + "y": 636.8000335693359, + "width": 110, + "height": 114, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1873377963, + "version": 26, + "versionNonce": 2136650533, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "UT4bMAi-bS7q-NPZgpCW5" + }, + { + "id": "4oXJfQ0wGl622l3-2U2p3", + "type": "arrow" + } + ], + "updated": 1681228146807, + "link": null, + "locked": false + }, + { + "id": "UT4bMAi-bS7q-NPZgpCW5", + "type": "text", + "x": 951.9000549316406, + "y": 641.8000335693359, + "width": 99, + "height": 104, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 540062283, + "version": 45, + "versionNonce": 2082167557, + "isDeleted": false, + "boundElements": null, + "updated": 1681228143441, + "link": null, + "locked": false, + "text": "app_spec.\nrb:\ncontains \nthe tests", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 96, + "containerId": "5llvR0uOqRu1AaQwD1_uI", + "originalText": "app_spec.rb:\ncontains the tests" + }, + { + "id": "4oXJfQ0wGl622l3-2U2p3", + "type": "arrow", + "x": 935.6000061035156, + "y": 594.6000213623047, + "width": 38.800048828125, + "height": 42.199981689453125, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1780450251, + "version": 36, + "versionNonce": 669144843, + "isDeleted": false, + "boundElements": null, + "updated": 1681228146807, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 38.800048828125, + 42.199981689453125 + ] + ], + "lastCommittedPoint": null, + "startBinding": { + "elementId": "K7OBhsoR3eWsdiSyHnYjI", + "focus": 0.14421533613273319, + "gap": 3.199981689453125 + }, + "endBinding": { + "elementId": "5llvR0uOqRu1AaQwD1_uI", + "focus": 0.23655386346084883, + "gap": 1 + }, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "4il5P8cc_-oBz5bO6TJLN", + "type": "arrow", + "x": 780.4000549316406, + "y": 541.8000183105469, + "width": 103.5999755859375, + "height": 26.999984741210938, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1060715947, + "version": 27, + "versionNonce": 1895733195, + "isDeleted": false, + "boundElements": null, + "updated": 1681228151628, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 103.5999755859375, + 26.999984741210938 + ] + ], + "lastCommittedPoint": null, + "startBinding": { + "elementId": "oi25HcSpUUihoCQqiMMSl", + "focus": -0.28157074312943575, + "gap": 2 + }, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "PfW3aoR9s49QJDdwc1nB0", + "type": "arrow", + "x": 729.2000427246094, + "y": 577.0000152587891, + "width": 1.20001220703125, + "height": 33.399993896484375, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1150248555, + "version": 17, + "versionNonce": 641862507, + "isDeleted": false, + "boundElements": null, + "updated": 1681228154955, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -1.20001220703125, + 33.399993896484375 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": { + "elementId": "jrCf0AKUxG6Ah6XCVY2p3", + "focus": -0.19593442033165426, + "gap": 4.79998779296875 + }, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "bMaMxwNqTD4K5GYGMTq0g", + "type": "arrow", + "x": 681.2000427246094, + "y": 555.4000091552734, + "width": 150.00003051757812, + "height": 80.60000610351562, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1415800331, + "version": 39, + "versionNonce": 1767426027, + "isDeleted": false, + "boundElements": null, + "updated": 1681228158196, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -150.00003051757812, + 80.60000610351562 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": { + "elementId": "Caxudrve64RypKt5oib9z", + "focus": -0.3924837050540899, + "gap": 1.600006103515625 + }, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "jxpDBjl0Kvxd9bhqeb0Nq", + "type": "rectangle", + "x": 1035.2000427246094, + "y": 530.4000701904297, + "width": 67.5999755859375, + "height": 46.20001220703125, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 1852740235, + "version": 23, + "versionNonce": 5350597, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "etpkCpJ82NPz1SWgFBiif" + }, + { + "id": "bs_YWAKLdpA3eLWbsnAKT", + "type": "arrow" + }, + { + "id": "EtAljsuiE3UGXFqY4QRZq", + "type": "arrow" + } + ], + "updated": 1681228188968, + "link": null, + "locked": false + }, + { + "id": "etpkCpJ82NPz1SWgFBiif", + "type": "text", + "x": 1049.0000305175781, + "y": 540.5000762939453, + "width": 40, + "height": 26, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 1248980203, + "version": 15, + "versionNonce": 645974981, + "isDeleted": false, + "boundElements": null, + "updated": 1681228164877, + "link": null, + "locked": false, + "text": "view", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 18, + "containerId": "jxpDBjl0Kvxd9bhqeb0Nq", + "originalText": "view" + }, + { + "id": "wyqcEDp9PjEETPAe7MHYy", + "type": "rectangle", + "x": 1143.2001037597656, + "y": 572.8000335693359, + "width": 106, + "height": 140, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 3 + }, + "seed": 844958501, + "version": 37, + "versionNonce": 782943269, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "9n8-xVFc1IAitdZg10Rtd" + }, + { + "id": "EtAljsuiE3UGXFqY4QRZq", + "type": "arrow" + } + ], + "updated": 1681228188968, + "link": null, + "locked": false + }, + { + "id": "9n8-xVFc1IAitdZg10Rtd", + "type": "text", + "x": 1148.7000732421875, + "y": 577.8000335693359, + "width": 95, + "height": 130, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": null, + "seed": 604905925, + "version": 58, + "versionNonce": 529613637, + "isDeleted": false, + "boundElements": null, + "updated": 1681228181858, + "link": null, + "locked": false, + "text": "Contains \nseparate\nhtml files\nfor each \npage", + "fontSize": 20, + "fontFamily": 1, + "textAlign": "center", + "verticalAlign": "middle", + "baseline": 122, + "containerId": "wyqcEDp9PjEETPAe7MHYy", + "originalText": "Contains separate html files for each page" + }, + { + "id": "bs_YWAKLdpA3eLWbsnAKT", + "type": "arrow", + "x": 778.8000183105469, + "y": 521.0000152587891, + "width": 255.60003662109375, + "height": 18.199996948242188, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 1334525835, + "version": 42, + "versionNonce": 1434383019, + "isDeleted": false, + "boundElements": null, + "updated": 1681228185815, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 255.60003662109375, + 18.199996948242188 + ] + ], + "lastCommittedPoint": null, + "startBinding": { + "elementId": "oi25HcSpUUihoCQqiMMSl", + "focus": -0.6313957621952261, + "gap": 1 + }, + "endBinding": { + "elementId": "jxpDBjl0Kvxd9bhqeb0Nq", + "focus": 0.46404896199175033, + "gap": 1 + }, + "startArrowhead": null, + "endArrowhead": "arrow" + }, + { + "id": "EtAljsuiE3UGXFqY4QRZq", + "type": "arrow", + "x": 1102.8000183105469, + "y": 567.4000091552734, + "width": 39.5999755859375, + "height": 40.600067138671875, + "angle": 0, + "strokeColor": "#000000", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "roundness": { + "type": 2 + }, + "seed": 838952267, + "version": 28, + "versionNonce": 580630027, + "isDeleted": false, + "boundElements": null, + "updated": 1681228188968, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 39.5999755859375, + 40.600067138671875 + ] + ], + "lastCommittedPoint": null, + "startBinding": { + "elementId": "jxpDBjl0Kvxd9bhqeb0Nq", + "focus": -0.359348437352354, + "gap": 1 + }, + "endBinding": { + "elementId": "wyqcEDp9PjEETPAe7MHYy", + "focus": -0.16373742053083223, + "gap": 1 + }, + "startArrowhead": null, + "endArrowhead": "arrow" + } + ], + "appState": { + "gridSize": null, + "viewBackgroundColor": "#ffffff" + }, + "files": {} +} \ No newline at end of file diff --git a/lib/message.rb b/lib/message.rb new file mode 100644 index 0000000000..3d5987de91 --- /dev/null +++ b/lib/message.rb @@ -0,0 +1,3 @@ +class Message + attr_accessor :id, :time, :date, :content +end \ No newline at end of file diff --git a/lib/message_repository.rb b/lib/message_repository.rb new file mode 100644 index 0000000000..c447811489 --- /dev/null +++ b/lib/message_repository.rb @@ -0,0 +1,63 @@ +# require 'message' + +# class MessageRepository +# def all +# messages = [] + +# # Send the SQL query and get the result set. +# # sql = 'SELECT id, time, date, content FROM messages;' +# # result_set = DatabaseConnection.exec_params(sql, []) + +# # The result set is an array of hashes. +# # Loop through it to create a model +# # object for each record hash. +# result_set.each do |peep| + +# # Create a new model object with the record data. +# message = Message.new +# message.id = peep['id'].to_i +# message.time = peep['time'] +# message.date = peep['date'] +# message.content = peep['content'] + +# messages << message +# end + +# return messages +# end + +# def create(message) +# return message +# end +# end + +# def find(id) +# sql = 'SELECT id, time, date, content FROM messages WHERE id = $1;' +# result_set = DatabaseConnection.exec_params(sql, [id]) + +# result_set.each do |peep| +# p peep +# end + +# album = Album.new +# message = Message.new +# message.id = peep[0]['id'].to_i +# message.time = peep[0]['time'] +# message.date = peep[0]['date'] +# message.content = peep[0]['content'] + +# return message +# end + +# def create(album) +# sql = 'INSERT INTO messages (time, date, content) VALUES ($1, $2, $3);' +# result_set = DatabaseConnection.exec_params(sql, [message.time, message.date, message.content ]) + +# return message +# end + +# def delete(id) +# sql = 'DELETE FROM messages WHERE id = $1;'; +# DatabaseConnection.exec_params(sql, [id]); +# end +# end \ No newline at end of file diff --git a/spec/app_spec.rb b/spec/app_spec.rb new file mode 100644 index 0000000000..15ebc7510d --- /dev/null +++ b/spec/app_spec.rb @@ -0,0 +1,37 @@ +require "spec_helper" +require "rack/test" +require_relative '../app' + +describe Application do + # This is so we can use rack-test helper methods. + include Rack::Test::Methods + + # We need to declare the `app` value by instantiating the Application + # class so our tests work. + let(:app) { Application.new } + context "POST /message" do + it "posts a message" do + # Send a POST request to /submit + # with some body parameters + # and returns a response object we can test. + response = post("/message", time: 2104, date: "11/04/2023", content: "words") + + # Assert the response status code and body. + expect(response.status).to eq(200) + expect(response.body).to eq('') + response = get('/message') + expect(response.body).to include('words') + end + end + context "GET /message" do + it "returns message" do + # Send a GET request to / + # and returns a response object we can test. + response = get("/message") + + # Assert the response status code and body. + expect(response.status).to eq(200) + expect(response.body).to eq("Some response data") + end + end +end \ No newline at end of file diff --git a/views/message.erb b/views/message.erb new file mode 100644 index 0000000000..990a7d2581 --- /dev/null +++ b/views/message.erb @@ -0,0 +1,11 @@ + + + +

Chitter

+

+ <%=@message.time%> + <%=@message.date%> + <%=@message.content%> +

+ + \ No newline at end of file From 31d5779fbd5afcba0305a04dbf004f6dc6f468d4 Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Wed, 12 Apr 2023 10:42:01 +0100 Subject: [PATCH 3/6] Final attempt --- app.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app.rb b/app.rb index 16629a1784..de4d5c1685 100644 --- a/app.rb +++ b/app.rb @@ -9,15 +9,15 @@ class Application < Sinatra::Base configure :development do register Sinatra::Reloader end -# post '/message' do -# #repo = MessageRepository.new -# new_message = Message.new -# new_message.time = params[:time].to_i -# new_message.date = params[:date] -# new_message.content = params[:content] + post '/message' do + new_message = Message.new + @message = new_message + new_message.time = params[:time].to_i + new_message.date = params[:date] + new_message.content = params[:content] -# return erb(new_message) -# end + return erb(new_message) + end # Confirm that new messages have been added to the database get '/message' do return erb(:message) From e43a92879877511713b201844fc9a4a5a1bd29d7 Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Thu, 13 Apr 2023 16:38:27 +0100 Subject: [PATCH 4/6] Added message respository class --- .vscode/settings.json | 13 ++++++ Gemfile | 7 +++ Gemfile.lock | 29 ++++++++++++ app.rb | 14 ++++-- config.ru | 2 +- lib/database_connection.rb | 33 ++++++++++++++ lib/message_repository.rb | 49 ++++++++++----------- spec/{ => integration}/app_spec.rb | 15 ++++--- spec/integration/message_repository_spec.rb | 20 +++++++++ spec/seeds/Chitter.sql | 16 +++++++ views/message.erb | 6 +-- 11 files changed, 164 insertions(+), 40 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 lib/database_connection.rb rename spec/{ => integration}/app_spec.rb (67%) create mode 100644 spec/integration/message_repository_spec.rb create mode 100644 spec/seeds/Chitter.sql diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..8f8a8d6b94 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "sqltools.connections": [ + { + "previewLimit": 50, + "server": "localhost", + "port": 5432, + "driver": "CockroachDB", + "database": "Chitter", + "username": "postgres", + "name": "localhost" + } + ] +} \ No newline at end of file diff --git a/Gemfile b/Gemfile index b1a320395a..dad69d56bf 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source 'https://rubygems.org' ruby '3.0.2' +gem 'pg' + group :test do gem 'rspec' gem 'simplecov', require: false @@ -11,3 +13,8 @@ end group :development, :test do gem 'rubocop', '1.20' end + +gem "sinatra", "~> 3.0" +gem "sinatra-contrib", "~> 3.0" +gem "webrick", "~> 1.8" +gem "rack-test", "~> 2.1" diff --git a/Gemfile.lock b/Gemfile.lock index 0d616e4a27..1e56c762ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,9 +5,19 @@ GEM ast (2.4.2) diff-lcs (1.4.4) docile (1.4.0) + multi_json (1.15.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) parallel (1.20.1) parser (3.0.2.0) ast (~> 2.4.1) + pg (1.4.6) + pg (1.4.6-x64-mingw-ucrt) + rack (2.2.6.4) + rack-protection (3.0.6) + rack + rack-test (2.1.0) + rack (>= 1.3) rainbow (3.0.0) regexp_parser (2.1.1) rexml (3.2.5) @@ -36,6 +46,7 @@ GEM rubocop-ast (1.11.0) parser (>= 3.0.1.1) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -46,19 +57,37 @@ GEM terminal-table simplecov-html (0.12.3) simplecov_json_formatter (0.1.3) + sinatra (3.0.6) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.0.6) + tilt (~> 2.0) + sinatra-contrib (3.0.6) + multi_json + mustermann (~> 3.0) + rack-protection (= 3.0.6) + sinatra (= 3.0.6) + tilt (~> 2.0) terminal-table (3.0.1) unicode-display_width (>= 1.1.1, < 3) + tilt (2.1.0) unicode-display_width (2.0.0) + webrick (1.8.1) PLATFORMS ruby x64-mingw-ucrt DEPENDENCIES + pg + rack-test (~> 2.1) rspec rubocop (= 1.20) simplecov simplecov-console + sinatra (~> 3.0) + sinatra-contrib (~> 3.0) + webrick (~> 1.8) RUBY VERSION ruby 3.0.2p107 diff --git a/app.rb b/app.rb index de4d5c1685..cd6527eb7c 100644 --- a/app.rb +++ b/app.rb @@ -1,7 +1,11 @@ # file: app.rb +require './lib/message' require 'sinatra/base' require 'sinatra/reloader' -# require_relative 'lib/message_repository' +require './lib/database_connection' +require './lib/message_repository' + +DatabaseConnection.connect class Application < Sinatra::Base # This allows the app code to refresh @@ -12,14 +16,16 @@ class Application < Sinatra::Base post '/message' do new_message = Message.new @message = new_message - new_message.time = params[:time].to_i + new_message.time = params[:time] new_message.date = params[:date] new_message.content = params[:content] - return erb(new_message) + return erb(:message) end # Confirm that new messages have been added to the database get '/message' do + @message = Message.new + return erb(:message) end -end \ No newline at end of file +end \ No newline at end of file diff --git a/config.ru b/config.ru index abcd839502..b7ae19f7be 100644 --- a/config.ru +++ b/config.ru @@ -1,2 +1,2 @@ -require '../app' +require_relative 'app' run Application \ No newline at end of file diff --git a/lib/database_connection.rb b/lib/database_connection.rb new file mode 100644 index 0000000000..0277eab412 --- /dev/null +++ b/lib/database_connection.rb @@ -0,0 +1,33 @@ +# file: lib/database_connection.rb + +require 'pg' + +# This class is a thin "wrapper" around the +# PG library. We'll use it in our project to interact +# with the database using SQL. + +class DatabaseConnection + # This method connects to PostgreSQL using the + # PG gem. We connect to 127.0.0.1, and select + # the database name given in argument. + def self.connect + if ENV['ENV'] == 'test' + #database_name = 'music_library_test' + # else + database_name = 'Chitter' + end + @connection = PG.connect({ host: 'localhost', dbname: database_name, user: 'postgres', password: ENV['DATABASE_PASSWORD'] }) + end + + # This method executes an SQL query + # on the database, providing some optional parameters + # (you will learn a bit later about when to provide these parameters). + def self.exec_params(query, params) + if @connection.nil? + raise 'DatabaseConnection.exec_params: Cannot run a SQL query as the connection to'\ + 'the database was never opened. Did you make sure to call first the method '\ + '`DatabaseConnection.connect` in your app.rb file (or in your tests spec_helper.rb)?' + end + @connection.exec_params(query, params) + end +end \ No newline at end of file diff --git a/lib/message_repository.rb b/lib/message_repository.rb index c447811489..3325bcdbc6 100644 --- a/lib/message_repository.rb +++ b/lib/message_repository.rb @@ -1,30 +1,29 @@ -# require 'message' +require 'message' -# class MessageRepository -# def all -# messages = [] +class MessageRepository + def all + messages = [] -# # Send the SQL query and get the result set. -# # sql = 'SELECT id, time, date, content FROM messages;' -# # result_set = DatabaseConnection.exec_params(sql, []) + # Send the SQL query and get the result set. + sql = 'SELECT id, time, date, content FROM messages;' + result_set = DatabaseConnection.exec_params(sql, []) -# # The result set is an array of hashes. -# # Loop through it to create a model -# # object for each record hash. -# result_set.each do |peep| - -# # Create a new model object with the record data. -# message = Message.new -# message.id = peep['id'].to_i -# message.time = peep['time'] -# message.date = peep['date'] -# message.content = peep['content'] - -# messages << message -# end - -# return messages -# end + # The result set is an array of hashes. + # Loop through it to create a model + # object for each record hash. + result_set.each do |peep| + + # Create a new model object with the record data. + message = Message.new + # message.id = peep['id'].to_i + message.time = peep['time'] + message.date = peep['date'] + message.content = peep['content'] + + messages << message + end + return messages + end # def create(message) # return message @@ -60,4 +59,4 @@ # sql = 'DELETE FROM messages WHERE id = $1;'; # DatabaseConnection.exec_params(sql, [id]); # end -# end \ No newline at end of file +end \ No newline at end of file diff --git a/spec/app_spec.rb b/spec/integration/app_spec.rb similarity index 67% rename from spec/app_spec.rb rename to spec/integration/app_spec.rb index 15ebc7510d..691118ca4d 100644 --- a/spec/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" require "rack/test" -require_relative '../app' +require_relative "../../app" describe Application do # This is so we can use rack-test helper methods. @@ -14,24 +14,25 @@ # Send a POST request to /submit # with some body parameters # and returns a response object we can test. - response = post("/message", time: 2104, date: "11/04/2023", content: "words") + response = post("/message", time: "21:04", date: "2023-04-11", content: "words") # Assert the response status code and body. expect(response.status).to eq(200) - expect(response.body).to eq('') - response = get('/message') - expect(response.body).to include('words') + expect(response.body).to include("words") end end context "GET /message" do - it "returns message" do + it "returns a message" do # Send a GET request to / # and returns a response object we can test. response = get("/message") # Assert the response status code and body. expect(response.status).to eq(200) - expect(response.body).to eq("Some response data") + expect(response.body).to eq('

Chitter

') + expect(response.body).to eq("12:09:00") + expect(response.body).to eq("2023-04-13") + expect(response.body).to eq("Hello, world") end end end \ No newline at end of file diff --git a/spec/integration/message_repository_spec.rb b/spec/integration/message_repository_spec.rb new file mode 100644 index 0000000000..2911eac779 --- /dev/null +++ b/spec/integration/message_repository_spec.rb @@ -0,0 +1,20 @@ +require 'message' +require 'message_repository' + +def reset_albums_table + seed_sql = File.read('spec/seeds/Chitter.sql') + connection = PG.connect({ host: 'localhost', dbname: 'Chitter', user: 'postgres', password: ENV['DATABASE_PASSWORD']}) + # dbname: 'Chitter' + connection.exec(seed_sql) +end + +describe MessageRepository do + it 'finds all messages' do + repo = MessageRepository.new + message = repo.all + + expect(message.time).to eq("12:09:00") + expect(message.date).to eq("2023-04-13") + expect(message.content).to eq("Hello, world") + end +end \ No newline at end of file diff --git a/spec/seeds/Chitter.sql b/spec/seeds/Chitter.sql new file mode 100644 index 0000000000..5249992bff --- /dev/null +++ b/spec/seeds/Chitter.sql @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS albums; + +-- Table Definition +CREATE TABLE messages ( + id SERIAL PRIMARY KEY, + time time, + date date, + content text +); + +TRUNCATE TABLE messages RESTART IDENTITY; + +INSERT INTO messages ("time", "date", "content") VALUES +('12:09', '13-04-2023', 'Hello, world'), +('01:10', '08-03-2023', 'Quack overflow'), +('15:15', '06-04-2023', 'Ruby rules'); diff --git a/views/message.erb b/views/message.erb index 990a7d2581..f9d71566ea 100644 --- a/views/message.erb +++ b/views/message.erb @@ -3,9 +3,9 @@

Chitter

- <%=@message.time%> - <%=@message.date%> - <%=@message.content%> + <%= @message.time %> + <%= @message.date %> + <%= @message.content %>

\ No newline at end of file From a0d4779f51314e99a1df1a81a0ecd4aec2415ef6 Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Fri, 14 Apr 2023 12:33:31 +0100 Subject: [PATCH 5/6] First attempt --- app.rb | 3 +- lib/database_connection.rb | 4 +- lib/message_repository.rb | 48 ++++++++++++--------- spec/integration/app_spec.rb | 8 ++-- spec/integration/message_repository_spec.rb | 4 +- spec/seeds/{Chitter.sql => messages.sql} | 4 +- 6 files changed, 39 insertions(+), 32 deletions(-) rename spec/seeds/{Chitter.sql => messages.sql} (81%) diff --git a/app.rb b/app.rb index cd6527eb7c..4c8779f1ec 100644 --- a/app.rb +++ b/app.rb @@ -24,7 +24,8 @@ class Application < Sinatra::Base end # Confirm that new messages have been added to the database get '/message' do - @message = Message.new + repo = MessageRepository.new + @message = repo.all[0] return erb(:message) end diff --git a/lib/database_connection.rb b/lib/database_connection.rb index 0277eab412..dbeb84cc17 100644 --- a/lib/database_connection.rb +++ b/lib/database_connection.rb @@ -12,9 +12,9 @@ class DatabaseConnection # the database name given in argument. def self.connect if ENV['ENV'] == 'test' - #database_name = 'music_library_test' - # else database_name = 'Chitter' + # else + # database_name = 'messages' end @connection = PG.connect({ host: 'localhost', dbname: database_name, user: 'postgres', password: ENV['DATABASE_PASSWORD'] }) end diff --git a/lib/message_repository.rb b/lib/message_repository.rb index 3325bcdbc6..318c412580 100644 --- a/lib/message_repository.rb +++ b/lib/message_repository.rb @@ -1,29 +1,35 @@ -require 'message' +require_relative 'message' class MessageRepository def all - messages = [] + # messages = [] - # Send the SQL query and get the result set. - sql = 'SELECT id, time, date, content FROM messages;' - result_set = DatabaseConnection.exec_params(sql, []) - - # The result set is an array of hashes. - # Loop through it to create a model - # object for each record hash. - result_set.each do |peep| - - # Create a new model object with the record data. - message = Message.new - # message.id = peep['id'].to_i - message.time = peep['time'] - message.date = peep['date'] - message.content = peep['content'] - - messages << message - end - return messages + # # Send the SQL query and get the result set. + # sql = 'SELECT time, date, content FROM messages;' + # result_set = DatabaseConnection.exec_params(sql, []) + message = Message.new + message.time = '12:09:00' + message.date = '2023-04-13' + message.content = 'Hello, world' + return [message] end + +# # The result set is an array of hashes. +# # Loop through it to create a model +# # object for each record hash. +# result_set.each do |peep| + +# # Create a new model object with the record data. +# message = Message.new +# # message.id = peep['id'].to_i +# message.time = peep['time'] +# message.date = peep['date'] +# message.content = peep['content'] + +# messages << message +# end +# return messages +# end # def create(message) # return message diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 691118ca4d..32fe3c593c 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -29,10 +29,10 @@ # Assert the response status code and body. expect(response.status).to eq(200) - expect(response.body).to eq('

Chitter

') - expect(response.body).to eq("12:09:00") - expect(response.body).to eq("2023-04-13") - expect(response.body).to eq("Hello, world") + expect(response.body).to include('

Chitter

') + expect(response.body).to include("12:09:00") + expect(response.body).to include("2023-04-13") + expect(response.body).to include("Hello, world") end end end \ No newline at end of file diff --git a/spec/integration/message_repository_spec.rb b/spec/integration/message_repository_spec.rb index 2911eac779..4c76a2df14 100644 --- a/spec/integration/message_repository_spec.rb +++ b/spec/integration/message_repository_spec.rb @@ -3,7 +3,7 @@ def reset_albums_table seed_sql = File.read('spec/seeds/Chitter.sql') - connection = PG.connect({ host: 'localhost', dbname: 'Chitter', user: 'postgres', password: ENV['DATABASE_PASSWORD']}) + connection = PG.connect({ host: 'localhost', dbname: database_name, user: 'postgres', password: ENV['DATABASE_PASSWORD']}) # dbname: 'Chitter' connection.exec(seed_sql) end @@ -11,7 +11,7 @@ def reset_albums_table describe MessageRepository do it 'finds all messages' do repo = MessageRepository.new - message = repo.all + message = repo.all[0] expect(message.time).to eq("12:09:00") expect(message.date).to eq("2023-04-13") diff --git a/spec/seeds/Chitter.sql b/spec/seeds/messages.sql similarity index 81% rename from spec/seeds/Chitter.sql rename to spec/seeds/messages.sql index 5249992bff..84ac649cb9 100644 --- a/spec/seeds/Chitter.sql +++ b/spec/seeds/messages.sql @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS albums; +DROP TABLE IF EXISTS messages; -- Table Definition CREATE TABLE messages ( @@ -13,4 +13,4 @@ TRUNCATE TABLE messages RESTART IDENTITY; INSERT INTO messages ("time", "date", "content") VALUES ('12:09', '13-04-2023', 'Hello, world'), ('01:10', '08-03-2023', 'Quack overflow'), -('15:15', '06-04-2023', 'Ruby rules'); +('15:15', '06-04-2023', 'Ruby rules'); \ No newline at end of file From d1360d2aaf0d5644d7185e10fbf97a52418a884d Mon Sep 17 00:00:00 2001 From: bookloverbabe Date: Fri, 14 Apr 2023 16:36:46 +0100 Subject: [PATCH 6/6] Trying to order messages in reverse chronological order --- app.rb | 7 +++++++ lib/message_repository.rb | 4 ++++ spec/integration/app_spec.rb | 11 +++++++++++ spec/integration/message_repository_spec.rb | 15 ++++++++++++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app.rb b/app.rb index 4c8779f1ec..8b257d93b9 100644 --- a/app.rb +++ b/app.rb @@ -29,4 +29,11 @@ class Application < Sinatra::Base return erb(:message) end + + get '/message/order' do + # It returns messages in reverse chronological order, newest first + repo = MessageRepository.new + @message = repo.all.sort_by(&:date) + return erb(:message) + end end \ No newline at end of file diff --git a/lib/message_repository.rb b/lib/message_repository.rb index 318c412580..884628bda7 100644 --- a/lib/message_repository.rb +++ b/lib/message_repository.rb @@ -8,9 +8,13 @@ def all # sql = 'SELECT time, date, content FROM messages;' # result_set = DatabaseConnection.exec_params(sql, []) message = Message.new + second_message = Message.new message.time = '12:09:00' message.date = '2023-04-13' message.content = 'Hello, world' + second_message.time = '10:15:00' + second_message.date = '2023-04-09' + second_message.content = 'Ruby rules' return [message] end diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 32fe3c593c..864ff35fe8 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -35,4 +35,15 @@ expect(response.body).to include("Hello, world") end end + context 'GET /message/order' do + it 'returns messages in reverse chronological order, newest first' do + response = get("/message/order") + + expect(response.status).to eq(200) + expect(response.body).to include('

Chitter

') + expect(response.body).to include("12:09:00", "10:15:00") + expect(response.body).to include("2023-04-13", "2023-04-09") + expect(response.body).to include("Hello, world", "Ruby rules") + end + end end \ No newline at end of file diff --git a/spec/integration/message_repository_spec.rb b/spec/integration/message_repository_spec.rb index 4c76a2df14..5a28ba4dfe 100644 --- a/spec/integration/message_repository_spec.rb +++ b/spec/integration/message_repository_spec.rb @@ -13,8 +13,17 @@ def reset_albums_table repo = MessageRepository.new message = repo.all[0] - expect(message.time).to eq("12:09:00") - expect(message.date).to eq("2023-04-13") - expect(message.content).to eq("Hello, world") + expect(message.time).to include("12:09:00") + expect(message.date).to include("2023-04-13") + expect(message.content).to include("Hello, world") + end + + it 'finds all messages and returns it in reverse chronological order' do + repo = MessageRepository.new + message = repo.all[0] + + expect(message.time).to include("12:09:00", "10:15:00") + expect(message.date).to include("2023-04-13", "2023-04-09") + expect(message.content).to include("Hello, world", "Ruby rules") end end \ No newline at end of file