Skip to content

Commit

Permalink
Removendo código duplicado através da adição de método generazante
Browse files Browse the repository at this point in the history
  • Loading branch information
mucapaz committed Feb 6, 2015
1 parent c6f39e3 commit 4243da8
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions grails-app/controllers/rgms/member/MemberController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ class MemberController {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
def userMemberList = []
def members = Member.list(params)
for (i in members) {
def user = User.findByAuthor(i)
if (user)
userMemberList.add([user: user, member: i])
else
userMemberList.add([member: i])
}
generateMemberList(userMemberList,members)

[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
}
Expand Down Expand Up @@ -99,13 +93,7 @@ class MemberController {
if(params.name){
def members = Member.findAllByName(params.name)

for (i in members) {
def user = User.findByAuthor(i)
if (user)
userMemberList.add([user: user, member: i])
else
userMemberList.add([member: i])
}
generateMemberList(userMemberList,members)
}

[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
Expand Down Expand Up @@ -234,13 +222,7 @@ class MemberController {
def members = Member.findAllByUniversity(params.name)


for (i in members) {
def user = User.findByAuthor(i)
if (user)
userMemberList.add([user: user, member: i])
else
userMemberList.add([member: i])
}
generateMemberList(userMemberList,members)
}
[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
}
Expand Down Expand Up @@ -272,17 +254,20 @@ class MemberController {
if(params.name){
def members = Member.findAllByEmail(params.name)


for (i in members) {
def user = User.findByAuthor(i)
if (user)
userMemberList.add([user: user, member: i])
else
userMemberList.add([member: i])
}
generateMemberList(userMemberList,members)
}
[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
}

private void generateMemberList(userMemberList, members){

This comment has been minimized.

Copy link
@acff

acff Feb 9, 2015

usou extract method

for (i in members) {
def user = User.findByAuthor(i)
if (user)
userMemberList.add([user: user, member: i])
else
userMemberList.add([member: i])
}
}


}

0 comments on commit 4243da8

Please sign in to comment.