refactor post query into post factory