I'm working right now in a readers social network. The main points are this:
- When an user connects with his account I save his user id in the session variable.
- My MVC is working with DTO's all the way, filling the necessary variables for the presentation in the model.
So, everything was ok, until today that I had to do a function that returns a DTO that has all the information of an user profile page. User profile pages can be accessed by anyone who has an account (Like Facebook user pages).
This profile page, shows a button "Follow" if the profile is not the profile of the current user (to avoid you following yourself). If we are following that user, it will display an unfollow button.
So I was thinking that the UserProfileDTO
must have two boolean:
isTheCurrentUser
and isFollowedByTheCurrentUser
.
public class UserProfileDTO {
private Long id;
private String username;
private Boolean isCurrentUser;
private Boolean isfollowedByCurrentUser;
...
And the Domain Controller
public User getUserProfile(String username, Long currentUserId) throws UserNameDoesntExist {
UserProfileDTO user = dataController.getUserByUsername(username);
if(user != null) {
user.setIsCurrentUser(currentUserId == user.getId());
user.setIsFollowedByCurrentUser(dataController.isFollowed(user.getId(), currentUserId));
...
But I thought, "This DTO will be filled with information at the domain model. So the domain must have information that the presentation had first. That information is the current connected user, thus that will create a dependency between the two layers.
Am I correct? Should the domain model be ignorant about who the current connected user is? Or is what I am doing okay?