Skip to content

Commit

Permalink
Add update of schooling attributes upon class list refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Oct 16, 2024
1 parent 7d7c1b4 commit 9e334f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/models/student/mappers/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# Service object that leverages pre-defined API mappers to fetch students from classes
# It uses the ClasseMapper, StudentMapper and SchoolingMapper to extract information from
# the aggregate call for all 3 different models
class Student
module Mappers
class Base
Expand Down
14 changes: 12 additions & 2 deletions app/models/student/mappers/sygne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
class Student
module Mappers
class Sygne < Base
def map_schooling!(classe, student, _entry)
schooling = Schooling.find_or_initialize_by(classe: classe, student: student)
def map_schooling!(classe, student, entry)
attributes = map_schooling_attributes(entry)
schooling = Schooling
.find_or_initialize_by(classe: classe, student: student)
.tap { |sc| sc.assign_attributes(attributes) }
.tap(&:save!)

student.close_current_schooling! if schooling != student.current_schooling

Expand All @@ -13,6 +17,12 @@ def map_schooling!(classe, student, _entry)

schooling.save!
end

def map_schooling_attributes(entry)
schooling_mapper.new.call(entry).values_at(:status, :start_date)
rescue StandardError => e
raise SchoolingParsingError.new, "Schooling parsing failure for #{uai}: #{e.message}"
end
end
end
end

0 comments on commit 9e334f8

Please sign in to comment.