Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HER-63-Update-User-Profile-To-Include-Speaker-Specific-Data #62

Merged
merged 3 commits into from
Jan 18, 2025

Conversation

bbcc33
Copy link
Collaborator

@bbcc33 bbcc33 commented Jan 17, 2025

HER-71-Update-Orders-for-Address-Editing

Issue

https://raquelanaroman.atlassian.net/browse/HER-71

Update the UserProfileSerializer to conditionally include speaker-specific information based on the user's role. Ensure that teacher users can view speaker profiles with limited information, while speakers can view their full profile, including bookings. Additionally, ensure teachers can see their own bookings on their profile.

Acceptance Criteria:

Update UserProfileSerializer:

Include the following attributes conditionally based on the user’s profile: bio, profile_image_url, events, availabilities, pending_bookings (for speaker view only), confirmed_bookings (for speaker view only), bookings (for teacher view only)

Conditional Attributes:

Use a Proc to conditionally include attributes based on the user’s role.

Teacher users, when viewing a speaker profile, should see the speaker’s bio, profile_image_url, events, availabilities.

Speaker users should see their full profile, including pending_bookings and confirmed_bookings.

Controller Logic:

Update the profile action in the Api::V1::UsersController to pass the user’s role as a parameter to the serializer.

Determine the role based on whether the current user is a speaker or a teacher.

Write test to ensure the serializer includes the correct attributes based on the user’s role and the endpoint returns the correct data for both roles.

Implementation

Update the UserProfileSerializer:
class UserProfileSerializer
  include JSONAPI::Serializer
  attributes :name, :email, :id, :bio, :profile_image_url

  attribute :events, if: Proc.new { |user| user.role == 'speaker' || user.role == 'teacher' } do |user|
    user.events ? user.events.map { |event| EventSerializer.new(event).serializable_hash } : []
  end
  attribute :availabilities, if: Proc.new { |user| user.role == 'speaker' || user.role == 'teacher' } do |user|
    user.availabilities ? user.availabilities.map { |availability| AvailabilitySerializer.new(availability).serializable_hash } : []
  end
  attribute :pending_bookings, if: Proc.new { |user| user.role == 'speaker' } do |user|
    user.pending_bookings ? user.pending_bookings.map { |booking| BookingSerializer.new(booking).serializable_hash } : []
  end
  attribute :confirmed_bookings, if: Proc.new { |user| user.role == 'speaker' } do |user|
    user.confirmed_bookings ? user.confirmed_bookings.map { |booking| BookingSerializer.new(booking).serializable_hash } : []
  end
  attribute :bookings, if: Proc.new { |user| user.role == 'teacher' } do |user|
    user.bookings ? user.bookings.map { |booking| BookingSerializer.new(booking).serializable_hash } : []
  end

  attribute :donations do |user|
    user.donations ? user.donations.map { |donation| DonationSerializer.new(donation).serializable_hash } : []
  end

  attribute :orders, if: Proc.new { |user| user.role == 'teacher' } do |user|
    user.orders ? user.orders.map { |order| OrderSerializer.new(order).serializable_hash } : []
  end
end

HER-57
HER-62

Changes

Updated the UserProfileSerializer
Updated Users controller
Created booking, event, availability serializers
Created tests for the UserProfileSerializer

Review Checklist

  • I have documented my code with code comments.

@bbcc33 bbcc33 changed the title HER-71-Update-Orders-for-Address-Editing HER-63-Update-User-Profile-To-Include-Speaker-Specific-Data Jan 18, 2025
@bbcc33 bbcc33 merged commit 45104b2 into main Jan 18, 2025
3 checks passed
@bbcc33 bbcc33 deleted the HER-71-Update-Orders-for-Address-Editing branch January 18, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants