<commit_before>require_dependency "bookings/application_controller"

module Bookings
  class TimeSlotsController < ApplicationController
    before_action :set_time_slot, only: [:show, :edit, :update, :destroy]
    
    respond_to :json, :html

    def slots
      @time_slots = current_user.time_slots.all
      render json: @time_slots, each_serializer: Bookings::TimeSlotSerializer
    end

    # GET /time_slots
    def index
      @time_slot = current_user.time_slots.new
    end

    # GET /time_slots/1
    def show
    end

    # GET /time_slots/new
    def new
      @time_slot = current_user.time_slots.new
    end

    # GET /time_slots/1/edit
    def edit
    end

    # POST /time_slots
    def create
      #TODO HZ: handle no recurring value.
      @time_slot = current_user.time_slots.new(time_slot_params)
      
      # @slots = []
      if @time_slot.save
        @time_slot.update_attribute(:parent, @time_slot)
        # @slots << @time_slot
        # @slots + @time_slot.create_children
        
        render json: @slot, serializer: Bookings::TimeSlotSerializer
      else
        respond_with(@time_slot) do |format|
          format.html { render :action => :new }
        end
      end

    end

    # PATCH/PUT /time_slots/1
    def update
      if @time_slot.update(time_slot_params)
        @time_slot.update_children
        render json: [@time_slot], each_serializer: Bookings::TimeSlotSerializer
      else
        respond_with(@time_slot) do |format|
          format.html { render :action => :edit }
        end
      end

    end

    # DELETE /time_slots/1
    def destroy
      @time_slot.destroy
      redirect_to time_slots_url, notice: 'Time slot was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_time_slot
        @time_slot = current_user.time_slots.find(params[:id])
      end
      
      # Only allow a trusted parameter "white list" through.
      def time_slot_params
        params.require(:time_slot).permit(:from_time, :to_time, :recurring)
      end
  end
end<commit_msg>fix create children time_slots<commit_after>require_dependency "bookings/application_controller"

module Bookings
  class TimeSlotsController < ApplicationController
    before_action :set_time_slot, only: [:show, :edit, :update, :destroy]
    
    respond_to :json, :html

    def slots
      @time_slots = current_user.time_slots.all
      render json: @time_slots, each_serializer: Bookings::TimeSlotSerializer
    end

    def index
      @time_slot = current_user.time_slots.new
    end

    def show
    end

    def new
      @time_slot = current_user.time_slots.new
    end

    def edit
    end

    def create
      #TODO HZ: handle no recurring value.
      @time_slot = current_user.time_slots.new(time_slot_params)
      
      if @time_slot.save
        @time_slot.update_attribute(:parent, @time_slot)
        @time_slot.create_children
        
        render json: @slot, serializer: Bookings::TimeSlotSerializer
      else
        respond_with(@time_slot) do |format|
          format.html { render :action => :new }
        end
      end

    end

    def update
      if @time_slot.update(time_slot_params)
        @time_slot.update_children
        render json: [@time_slot], each_serializer: Bookings::TimeSlotSerializer
      else
        respond_with(@time_slot) do |format|
          format.html { render :action => :edit }
        end
      end

    end

    def destroy
      @time_slot.destroy
      redirect_to time_slots_url, notice: 'Time slot was successfully destroyed.'
    end

    private
      def set_time_slot
        @time_slot = current_user.time_slots.find(params[:id])
      end

      def time_slot_params
        params.require(:time_slot).permit(:from_time, :to_time, :recurring)
      end
  end
end
{'fraction_non_alphanumeric': 0.07877688520342058, 'fraction_numerical': 0.0010365379632029023, 'mean_word_length': 2.5027223230490017, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146382', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1190, 'n_words': 280}