Skip to content

Commit

Permalink
feat: ๐ŸŽธ ๋กœ๊ทธ์ธ๋œ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ž…๋œ ๊ทธ๋ฃน ๋ชฉ๋ก์„ ์กฐํšŒํ•˜๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„
Browse files Browse the repository at this point in the history
โœ… Closes: #226
  • Loading branch information
sallyjellyy committed Nov 30, 2021
1 parent 51d7b5a commit 40e65f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.postsquad.scoup.web.error.controller.response.ErrorResponse;
import com.postsquad.scoup.web.group.controller.request.GroupCreationRequest;
import com.postsquad.scoup.web.group.controller.request.GroupModificationRequest;
import com.postsquad.scoup.web.group.controller.response.GroupReadAllResponses;
import com.postsquad.scoup.web.group.controller.request.GroupValidationRequest;
import com.postsquad.scoup.web.group.controller.response.GroupReadOneResponse;
import com.postsquad.scoup.web.group.controller.response.GroupValidationResponse;
Expand Down Expand Up @@ -71,4 +72,9 @@ public GroupValidationResponse validateGroupName(@Valid GroupValidationRequest g
@ResponseStatus(HttpStatus.NO_CONTENT)
public void leaveGroup(@PathVariable long groupId) {
}

@GetMapping
public GroupReadAllResponses readAll(@LoggedInUser User user) {
return groupService.readAllByUser(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
import com.postsquad.scoup.web.common.DefaultPostResponse;
import com.postsquad.scoup.web.group.controller.request.GroupCreationRequest;
import com.postsquad.scoup.web.group.controller.request.GroupModificationRequest;
import com.postsquad.scoup.web.group.controller.response.GroupReadAllResponses;
import com.postsquad.scoup.web.group.domain.Group;
import com.postsquad.scoup.web.group.exception.GroupNameAlreadyExistException;
import com.postsquad.scoup.web.group.exception.GroupNotFoundException;
import com.postsquad.scoup.web.group.mapper.GroupMapper;
import com.postsquad.scoup.web.group.repository.GroupRepository;
import com.postsquad.scoup.web.signin.exception.UnauthorizedUserException;
import com.postsquad.scoup.web.signin.exception.UserNotFoundException;
import com.postsquad.scoup.web.user.domain.User;
import com.postsquad.scoup.web.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

@RequiredArgsConstructor
@Service
public class GroupService {

private final GroupRepository groupRepository;
private final UserRepository userRepository;

public DefaultPostResponse create(GroupCreationRequest groupCreationRequest, User user) {

Expand All @@ -42,4 +48,15 @@ public Long update(Long groupId, GroupModificationRequest groupModificationReque
}
return groupRepository.save(group.update(groupModificationRequest)).getId();
}

public GroupReadAllResponses readAllByUser(User user) {
User loggedInUser = userRepository.findById(user.getId()).orElseThrow(() -> new UserNotFoundException(user.getId()));
return GroupReadAllResponses
.builder()
.groupReadAllResponse(
loggedInUser.getJoinedGroups().stream()
.map(GroupMapper.INSTANCE::map)
.collect(Collectors.toList()))
.build();
}
}

0 comments on commit 40e65f0

Please sign in to comment.