From 03ee9fefec22595651a0d74bfe6f01a432fb2cc4 Mon Sep 17 00:00:00 2001 From: Wild Karl-Heinz Date: Sat, 22 Nov 2025 11:46:40 +0100 Subject: [PATCH] added parties --- app/controllers/parties_controller.rb | 70 +++++++++++++++++++ app/helpers/parties_helper.rb | 2 + app/models/attendent.rb | 4 ++ app/models/party.rb | 2 + app/views/layouts/application.html.erb | 2 + app/views/parties/_form.html.erb | 42 +++++++++++ app/views/parties/_party.html.erb | 22 ++++++ app/views/parties/edit.html.erb | 10 +++ app/views/parties/index.html.erb | 29 ++++++++ app/views/parties/new.html.erb | 9 +++ app/views/parties/show.html.erb | 15 ++++ config/routes.rb | 5 +- db/migrate/20251122103401_create_parties.rb | 12 ++++ .../20251122103750_create_attendents.rb | 10 +++ 14 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 app/controllers/parties_controller.rb create mode 100644 app/helpers/parties_helper.rb create mode 100644 app/models/attendent.rb create mode 100644 app/models/party.rb create mode 100644 app/views/parties/_form.html.erb create mode 100644 app/views/parties/_party.html.erb create mode 100644 app/views/parties/edit.html.erb create mode 100644 app/views/parties/index.html.erb create mode 100644 app/views/parties/new.html.erb create mode 100644 app/views/parties/show.html.erb create mode 100644 db/migrate/20251122103401_create_parties.rb create mode 100644 db/migrate/20251122103750_create_attendents.rb diff --git a/app/controllers/parties_controller.rb b/app/controllers/parties_controller.rb new file mode 100644 index 0000000..fdfb152 --- /dev/null +++ b/app/controllers/parties_controller.rb @@ -0,0 +1,70 @@ +class PartiesController < ApplicationController + before_action :set_party, only: %i[ show edit update destroy ] + + # GET /parties or /parties.json + def index + @parties = Party.all + end + + # GET /parties/1 or /parties/1.json + def show + end + + # GET /parties/new + def new + @party = Party.new + end + + # GET /parties/1/edit + def edit + end + + # POST /parties or /parties.json + def create + @party = Party.new(party_params) + + respond_to do |format| + if @party.save + format.html { redirect_to @party, notice: "Party was successfully created." } + format.json { render :show, status: :created, location: @party } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @party.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /parties/1 or /parties/1.json + def update + respond_to do |format| + if @party.update(party_params) + format.html { redirect_to @party, notice: "Party was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @party } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @party.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /parties/1 or /parties/1.json + def destroy + @party.destroy! + + respond_to do |format| + format.html { redirect_to parties_path, notice: "Party was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_party + @party = Party.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def party_params + params.expect(party: [ :title, :location, :start_date, :start_time, :status ]) + end +end diff --git a/app/helpers/parties_helper.rb b/app/helpers/parties_helper.rb new file mode 100644 index 0000000..d115b62 --- /dev/null +++ b/app/helpers/parties_helper.rb @@ -0,0 +1,2 @@ +module PartiesHelper +end diff --git a/app/models/attendent.rb b/app/models/attendent.rb new file mode 100644 index 0000000..58372a8 --- /dev/null +++ b/app/models/attendent.rb @@ -0,0 +1,4 @@ +class Attendent < ApplicationRecord + belongs_to :parties + belongs_to :friends +end diff --git a/app/models/party.rb b/app/models/party.rb new file mode 100644 index 0000000..bfc74ef --- /dev/null +++ b/app/models/party.rb @@ -0,0 +1,2 @@ +class Party < ApplicationRecord +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d821ff0..885d96c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,7 @@ + <%= csrf_meta_tags %> <%= csp_meta_tag %> @@ -29,6 +30,7 @@
  • <%= link_to "Leistungen", pages_path(:leistungen) %>
  • <%= link_to "Anfahrt", pages_path(:anfahrt) %>
  • <%= link_to "Kontakt", pages_path(:kontakt) %>
  • +
  • <%= link_to "Parties", parties_path %>
  • <%= link_to "Freunde", friends_path %>
  • <%= link_to "Datenschutz", pages_path(:datenschutz) %>
  • <%= link_to "Impressum", pages_path(:impressum) %>
  • diff --git a/app/views/parties/_form.html.erb b/app/views/parties/_form.html.erb new file mode 100644 index 0000000..85bd203 --- /dev/null +++ b/app/views/parties/_form.html.erb @@ -0,0 +1,42 @@ +<%= form_with(model: party, class: "contents") do |form| %> + <% if party.errors.any? %> +
    +

    <%= pluralize(party.errors.count, "error") %> prohibited this party from being saved:

    + + +
    + <% end %> + +
    + <%= form.label :title %> + <%= form.text_field :title, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:title].none?, "border-red-400 focus:outline-red-600": party.errors[:title].any?}] %> +
    + +
    + <%= form.label :location %> + <%= form.text_field :location, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:location].none?, "border-red-400 focus:outline-red-600": party.errors[:location].any?}] %> +
    + +
    + <%= form.label :start_date %> + <%= form.date_field :start_date, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_date].none?, "border-red-400 focus:outline-red-600": party.errors[:start_date].any?}] %> +
    + +
    + <%= form.label :start_time %> + <%= form.time_field :start_time, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_time].none?, "border-red-400 focus:outline-red-600": party.errors[:start_time].any?}] %> +
    + +
    + <%= form.label :status %> + <%= form.text_field :status, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:status].none?, "border-red-400 focus:outline-red-600": party.errors[:status].any?}] %> +
    + +
    + <%= form.submit class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %> +
    +<% end %> diff --git a/app/views/parties/_party.html.erb b/app/views/parties/_party.html.erb new file mode 100644 index 0000000..946fc55 --- /dev/null +++ b/app/views/parties/_party.html.erb @@ -0,0 +1,22 @@ +
    +
    + Title: + <%= party.title %> +
    +
    + Location: + <%= party.location %> +
    +
    + Start date: + <%= party.start_date %> +
    +
    + Start time: + <%= party.start_time %> +
    +
    + Status: + <%= party.status %> +
    +
    diff --git a/app/views/parties/edit.html.erb b/app/views/parties/edit.html.erb new file mode 100644 index 0000000..840fd8d --- /dev/null +++ b/app/views/parties/edit.html.erb @@ -0,0 +1,10 @@ +<% content_for :title, "Editing party" %> + +
    +

    Editing party

    + + <%= render "form", party: @party %> + + <%= link_to "Show this party", @party, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> +
    diff --git a/app/views/parties/index.html.erb b/app/views/parties/index.html.erb new file mode 100644 index 0000000..f1ffe33 --- /dev/null +++ b/app/views/parties/index.html.erb @@ -0,0 +1,29 @@ +<% content_for :title, "Parties" %> + +
    + <% if notice.present? %> +

    <%= notice %>

    + <% end %> + +
    +

    Parties

    + <%= link_to "New party", new_party_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %> +
    + +
    + <% if @parties.any? %> + <% @parties.each do |party| %> +
    + <%= render party %> +
    + <%= link_to "Show", party, class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Edit", edit_party_path(party), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= button_to "Destroy", party, method: :delete, class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %> +
    +
    + <% end %> + <% else %> +

    No parties found.

    + <% end %> +
    +
    diff --git a/app/views/parties/new.html.erb b/app/views/parties/new.html.erb new file mode 100644 index 0000000..0408960 --- /dev/null +++ b/app/views/parties/new.html.erb @@ -0,0 +1,9 @@ +<% content_for :title, "New party" %> + +
    +

    New party

    + + <%= render "form", party: @party %> + + <%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> +
    diff --git a/app/views/parties/show.html.erb b/app/views/parties/show.html.erb new file mode 100644 index 0000000..9cb8304 --- /dev/null +++ b/app/views/parties/show.html.erb @@ -0,0 +1,15 @@ +<% content_for :title, "Showing party" %> + +
    + <% if notice.present? %> +

    <%= notice %>

    + <% end %> + +

    Showing party

    + + <%= render @party %> + + <%= link_to "Edit this party", edit_party_path(@party), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= button_to "Destroy this party", @party, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %> +
    diff --git a/config/routes.rb b/config/routes.rb index bfe15b4..ce8e18e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,9 +5,10 @@ Rails.application.routes.draw do # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker - get "pages/:page" => "welcome#pages", as: :pages - + resources :parties resources :friends + get "pages/:page" => "welcome#pages", as: :pages + root "welcome#index" end diff --git a/db/migrate/20251122103401_create_parties.rb b/db/migrate/20251122103401_create_parties.rb new file mode 100644 index 0000000..6cb49b1 --- /dev/null +++ b/db/migrate/20251122103401_create_parties.rb @@ -0,0 +1,12 @@ +class CreateParties < ActiveRecord::Migration[8.0] + def change + create_table :parties do |t| + t.string :title, null: false + t.string :location, null: false + t.date :start_date, null: false + t.time :start_time, null: false + t.string :status, default: 'undefiniert' + t.timestamps + end + end +end diff --git a/db/migrate/20251122103750_create_attendents.rb b/db/migrate/20251122103750_create_attendents.rb new file mode 100644 index 0000000..7ceeea9 --- /dev/null +++ b/db/migrate/20251122103750_create_attendents.rb @@ -0,0 +1,10 @@ +class CreateAttendents < ActiveRecord::Migration[8.0] + def change + create_table :attendents do |t| + t.references :parties, null: false, foreign_key: true + t.references :friends, null: false, foreign_key: true + t.string :status, default: 'offen' + t.timestamps + end + end +end