From d407f8656d518544f9f3d859990f9278724219e1 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 6 Jan 2015 17:46:16 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E8=AF=BE=E7=A8=8Bi?= =?UTF-8?q?mg=5Furl=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98=E3=80=822=E3=80=81?= =?UTF-8?q?=E8=A1=A5=E4=B8=8A=E7=94=A8=E6=88=B7=E8=AF=BE=E7=A8=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/users.rb | 12 ++++++++++++ app/api/mobile/entities/course.rb | 3 ++- app/services/users_service.rb | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index e15fdb16b..878748793 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -49,6 +49,18 @@ module Mobile present :status, 0 end + desc '获取用户课程' + params do + + end + + get ':id/courses' do + us = UsersService.new + ue = us.user_courses_list params,current_user.nil? ? User.find(2):current_user + present :data, ue,with: Mobile::Entities::Course + present :status, 0 + end + desc '修改密码' params do diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 0dd0d6aeb..ffae1db1f 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -10,7 +10,8 @@ module Mobile c = f[:course] end if field == :img_url - f.img_url if f.respond_to?(:img_url) + f[field] if f.is_a?(Hash) && f.key?(field) + #f.img_url if f.respond_to?(:img_url) else (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 82b88befb..c1074c1c0 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -146,7 +146,11 @@ class UsersService membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current)) end membership.sort! {|older, newer| newer.created_on <=> older.created_on } - membership + course_list = [] + membership.each do |mp| + course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course)} + end + course_list end #修改密码