Sha256: 6eeb801b1c0c204cf2fc7e75dc24a74f95db8827a5e184a3f100d60c3c881aec

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true
require_relative '../student/student'
require 'logger'
class AddStudentController

  def initialize(student_list)
    @student_list = student_list
    @logger = Logger.new('controller_add.log') # Указывает путь и имя файла для логов
  end

  #привязка view
  def add_view(view)
    @view = view
  end

  def execute
    @view.execute
    @logger.info('Executing add student operation')
  end

  def save_student(student)
    @logger.info('Saving student')
    @student_list.add_student(student)
  end


  def validate_fields(fields)
    @logger.info('Validating fields')
    required_fields = [:first_name, :middle_name, :surname] # список обязательных полей
    if required_fields.all? { |field| fields.key?(field) }
      student = Student.new(
        first_name: fields[:first_name],
        middle_name: fields[:middle_name],
        surname: fields[:surname],
        id: fields[:id] || nil,
        git: fields[:git] || nil,
        phone_number: fields[:phone_number] || nil,
        mail: fields[:mail] || nil,
        telegram: fields[:telegram] || nil
      )
      puts(student)
      return student
    else
      return nil
    end
  rescue ArgumentError => e
    @logger.error("Error occurred while validating fields: #{e.message}")
    return nil
  end



end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
shanti555890-1.1.4 lib/source/add_controller.rb
shanti555890-1.1.4 lib/source/database/add_controller.rb