record mood
This commit is contained in:
parent
3502e13c6f
commit
107103f226
11 changed files with 95 additions and 0 deletions
2
Gemfile
2
Gemfile
|
|
@ -9,3 +9,5 @@ gem "sqlite3"
|
||||||
gem "rake"
|
gem "rake"
|
||||||
|
|
||||||
gem "rackup", "~> 2.1"
|
gem "rackup", "~> 2.1"
|
||||||
|
|
||||||
|
gem "sinatra-contrib", "~> 4.0"
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ GEM
|
||||||
i18n (1.14.1)
|
i18n (1.14.1)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
minitest (5.22.2)
|
minitest (5.22.2)
|
||||||
|
multi_json (1.15.0)
|
||||||
mustermann (3.0.0)
|
mustermann (3.0.0)
|
||||||
ruby2_keywords (~> 0.0.1)
|
ruby2_keywords (~> 0.0.1)
|
||||||
mutex_m (0.2.0)
|
mutex_m (0.2.0)
|
||||||
|
|
@ -52,6 +53,12 @@ GEM
|
||||||
sinatra-activerecord (2.0.27)
|
sinatra-activerecord (2.0.27)
|
||||||
activerecord (>= 4.1)
|
activerecord (>= 4.1)
|
||||||
sinatra (>= 1.0)
|
sinatra (>= 1.0)
|
||||||
|
sinatra-contrib (4.0.0)
|
||||||
|
multi_json (>= 0.0.2)
|
||||||
|
mustermann (~> 3.0)
|
||||||
|
rack-protection (= 4.0.0)
|
||||||
|
sinatra (= 4.0.0)
|
||||||
|
tilt (~> 2.0)
|
||||||
sqlite3 (1.7.2-aarch64-linux)
|
sqlite3 (1.7.2-aarch64-linux)
|
||||||
sqlite3 (1.7.2-arm-linux)
|
sqlite3 (1.7.2-arm-linux)
|
||||||
sqlite3 (1.7.2-arm64-darwin)
|
sqlite3 (1.7.2-arm64-darwin)
|
||||||
|
|
@ -78,6 +85,7 @@ DEPENDENCIES
|
||||||
rake
|
rake
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-activerecord
|
sinatra-activerecord
|
||||||
|
sinatra-contrib (~> 4.0)
|
||||||
sqlite3
|
sqlite3
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
|
|
|
||||||
8
Rakefile
Normal file
8
Rakefile
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Rakefile
|
||||||
|
require "sinatra/activerecord/rake"
|
||||||
|
|
||||||
|
namespace :db do
|
||||||
|
task :load_config do
|
||||||
|
require "./mood_app"
|
||||||
|
end
|
||||||
|
end
|
||||||
2
config.ru
Normal file
2
config.ru
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
require './mood_app'
|
||||||
|
run MoodApp
|
||||||
8
db/migrate/20240211182231_create_moods.rb
Normal file
8
db/migrate/20240211182231_create_moods.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
class CreateMoods < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :moods do |t|
|
||||||
|
t.string :mode, null: false
|
||||||
|
t.datetime :recorded_at, precision: nil, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
19
db/schema.rb
Normal file
19
db/schema.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# This file is the source Rails uses to define your schema when running `bin/rails
|
||||||
|
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
||||||
|
# be faster and is potentially less error prone than running all of your
|
||||||
|
# migrations from scratch. Old migrations may fail to apply correctly if those
|
||||||
|
# migrations use external dependencies or application code.
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema[7.1].define(version: 2024_02_11_182231) do
|
||||||
|
create_table "moods", force: :cascade do |t|
|
||||||
|
t.string "mode", null: false
|
||||||
|
t.datetime "recorded_at", precision: nil, null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
34
mood_app.rb
Normal file
34
mood_app.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
require 'sinatra/base'
|
||||||
|
require 'sinatra/namespace'
|
||||||
|
require 'sinatra/activerecord'
|
||||||
|
|
||||||
|
class MoodApp < Sinatra::Base
|
||||||
|
register Sinatra::ActiveRecordExtension
|
||||||
|
register Sinatra::Namespace
|
||||||
|
set :database, { adapter: 'sqlite3', database: 'mood.sqlite3' }
|
||||||
|
|
||||||
|
get '/' do
|
||||||
|
@last_mood = Mood.order(recorded_at: :desc).first
|
||||||
|
erb :index
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace '/api/v1' do
|
||||||
|
before do
|
||||||
|
content_type 'application/json'
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/moods' do
|
||||||
|
json = request.body.read
|
||||||
|
puts json
|
||||||
|
data = JSON.parse json
|
||||||
|
Mood.create(mode: data['mode'], recorded_at: Time.now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
run! if app_file == $0
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mood < ActiveRecord::Base
|
||||||
|
validates_presence_of :mode
|
||||||
|
validates_presence_of :recorded_at
|
||||||
|
end
|
||||||
BIN
public/creatif.png
Normal file
BIN
public/creatif.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 904 KiB |
BIN
public/en-charge.png
Normal file
BIN
public/en-charge.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 836 KiB |
BIN
public/frigo-vide.png
Normal file
BIN
public/frigo-vide.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 947 KiB |
14
views/index.erb
Normal file
14
views/index.erb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<style>
|
||||||
|
.mode {
|
||||||
|
max-width: 80vw;
|
||||||
|
max-height: 80vh;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
width: auto;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="mode">
|
||||||
|
<img src="<%= @last_mood.mode %>.png">
|
||||||
|
</div>
|
||||||
Loading…
Add table
Reference in a new issue