Skip to content

Commit

Permalink
YEL-167 [deploy] School -> UserGroup 변경
Browse files Browse the repository at this point in the history
YEL-167 [deploy] School -> UserGroup 변경
  • Loading branch information
euije authored Sep 24, 2023
2 parents bfe80c4 + 0d6046d commit 2ab2e9c
Show file tree
Hide file tree
Showing 69 changed files with 9,716 additions and 2,656 deletions.
2 changes: 1 addition & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

* link:find-onboarding-friends.html[가입한 친구 목록 불러오기]

* link:search-school.html[대학교 검색하기]
* link:search-userGroup.html[대학교 검색하기]

* link:search-department.html[대학교 학과 검색하기]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.yello.server.global.common.SuccessCode.READ_USER_DETAIL_ADMIN_SUCCESS;
import static com.yello.server.global.common.SuccessCode.UPDATE_USER_DETAIL_ADMIN_SUCCESS;
import static com.yello.server.global.common.factory.PaginationFactory.createPageable;
import static com.yello.server.global.common.factory.PaginationFactory.createPageableByNameSortDescLimitTen;
import static com.yello.server.global.common.factory.PaginationFactory.createPageableLimitTen;

import com.yello.server.domain.admin.dto.request.AdminLoginRequest;
Expand All @@ -28,6 +29,7 @@
import com.yello.server.global.common.annotation.AccessTokenUser;
import com.yello.server.global.common.dto.BaseResponse;
import com.yello.server.global.common.dto.EmptyObject;
import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import javax.annotation.Nullable;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -56,18 +58,21 @@ public BaseResponse<AdminLoginResponse> postAdminLogin(@RequestBody AdminLoginRe
}

@GetMapping("/user")
public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user, @RequestParam Integer page,
public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String field,
@Nullable @RequestParam String value) {
val data = (field == null && value == null)
? adminService.findUser(user.getId(), createPageableLimitTen(page))
: adminService.findUserContaining(user.getId(), createPageableLimitTen(page),
val data = (field==null && value==null)
? adminService.findUser(user.getId(), createPageableByNameSortDescLimitTen(page))
: adminService.findUserContaining(user.getId(),
createPageableByNameSortDescLimitTen(page),
field, value);
return BaseResponse.success(READ_USER_ADMIN_SUCCESS, data);
}

@GetMapping("/user/{id}")
public BaseResponse<AdminUserDetailResponse> getUserDetailAdmin(@AccessTokenUser User user, @PathVariable Long id) {
public BaseResponse<AdminUserDetailResponse> getUserDetailAdmin(@AccessTokenUser User user,
@PathVariable Long id) {
val data = adminService.findUserDetail(user.getId(), id);
return BaseResponse.success(READ_USER_DETAIL_ADMIN_SUCCESS, data);
}
Expand All @@ -86,9 +91,10 @@ public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam Long us
}

@GetMapping("/cooldown")
public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser User user, @RequestParam Integer page,
public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String yelloId) {
val data = yelloId == null
val data = yelloId==null
? adminService.findCooldown(user.getId(), createPageableLimitTen(page))
: adminService.findCooldownContaining(user.getId(), createPageableLimitTen(page),
yelloId);
Expand All @@ -109,7 +115,8 @@ public BaseResponse<AdminQuestionResponse> getQuestionAdmin(@AccessTokenUser Use
}

@GetMapping("/question/{id}")
public BaseResponse<AdminQuestionDetailResponse> getQuestionDetailAdmin(@AccessTokenUser User user,
public BaseResponse<AdminQuestionDetailResponse> getQuestionDetailAdmin(
@AccessTokenUser User user,
@PathVariable Long id) {
val data = adminService.findQuestionDetail(user.getId(), id);
return BaseResponse.success(READ_QUESTION_DETAIL_ADMIN_SUCCESS, data);
Expand All @@ -129,4 +136,12 @@ public BaseResponse deleteQuestion(@AccessTokenUser User user, @RequestParam Lon
adminService.deleteQuestion(user.getId(), questionId);
return BaseResponse.success(DELETE_QUESTION_ADMIN_SUCCESS);
}

@PostMapping("/notification")
public BaseResponse<EmptyObject> postCustomNotificationSendAdmin(@AccessTokenUser User user,
@RequestBody NotificationCustomMessage request) {
val data = notificationService.adminSendCustomNotification(user.getId(), request);

return BaseResponse.success(CREATE_VOTE_SUCCESS, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.yello.server.global.common.factory.TimeFactory.toDateFormattedString;

import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.entity.UserGroup;
import com.yello.server.domain.user.entity.User;
import lombok.Builder;

Expand All @@ -18,7 +18,7 @@ public record AdminUserContentVO(
) {

public static AdminUserContentVO of(User user) {
final School userGroup = user.getGroup();
final UserGroup userGroup = user.getGroup();

return AdminUserContentVO.builder()
.id(user.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public AdminUserResponse findUser(Long adminId, Pageable page) {
return AdminUserResponse.of(totalCount, list);
}

public AdminUserResponse findUserContaining(Long adminId, Pageable page, String field, String value) {
public AdminUserResponse findUserContaining(Long adminId, Pageable page, String field,
String value) {
// exception
final User admin = userRepository.getById(adminId);
userAdminRepository.getByUser(admin);
Expand Down Expand Up @@ -185,16 +186,18 @@ public AdminCooldownResponse findCooldown(Long adminId, Pageable page) {
return AdminCooldownResponse.of(totalCount, list);
}

public AdminCooldownResponse findCooldownContaining(Long adminId, Pageable page, String yelloId) {
public AdminCooldownResponse findCooldownContaining(Long adminId, Pageable page,
String yelloId) {
// exception
final User admin = userRepository.getById(adminId);
userAdminRepository.getByUser(admin);

// logic
final Long totalCount = cooldownRepository.countAllByYelloIdContaining(yelloId);
final List<AdminCooldownContentVO> list = cooldownRepository.findAllContaining(page, yelloId).stream()
.map(AdminCooldownContentVO::of)
.toList();
final List<AdminCooldownContentVO> list =
cooldownRepository.findAllContaining(page, yelloId).stream()
.map(AdminCooldownContentVO::of)
.toList();

return AdminCooldownResponse.of(totalCount, list);
}
Expand Down Expand Up @@ -245,8 +248,10 @@ public List<Vote> createVote(Long adminId, Long questionId, AdminQuestionVoteReq
// logic
final List<Vote> result = new ArrayList<>();
request.voteContentList().forEach((voteContent -> {
final Optional<User> sender = userRepository.findByIdNotFiltered(voteContent.senderId());
final Optional<User> receiver = userRepository.findByIdNotFiltered(voteContent.receiverId());
final Optional<User> sender =
userRepository.findByIdNotFiltered(voteContent.senderId());
final Optional<User> receiver =
userRepository.findByIdNotFiltered(voteContent.receiverId());

if (sender.isPresent() && receiver.isPresent()) {
final Vote vote = Vote.createVote(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import static com.yello.server.global.common.SuccessCode.LOGIN_SUCCESS;
import static com.yello.server.global.common.SuccessCode.ONBOARDING_FRIENDS_SUCCESS;
import static com.yello.server.global.common.SuccessCode.RE_ISSUE_TOKEN_AUTH_SUCCESS;
import static com.yello.server.global.common.SuccessCode.SCHOOL_NAME_SEARCH_SCHOOL_SUCCESS;
import static com.yello.server.global.common.SuccessCode.SIGN_UP_SUCCESS;
import static com.yello.server.global.common.SuccessCode.UNIVERSITY_NAME_SEARCH_USER_GROUP_SUCCESS;
import static com.yello.server.global.common.SuccessCode.YELLOID_VALIDATION_SUCCESS;
import static com.yello.server.global.common.factory.PaginationFactory.createPageable;

Expand All @@ -21,6 +21,7 @@
import com.yello.server.domain.authorization.dto.response.OnBoardingFriendResponse;
import com.yello.server.domain.authorization.dto.response.SignUpResponse;
import com.yello.server.domain.authorization.service.AuthService;
import com.yello.server.domain.group.entity.UserGroupType;
import com.yello.server.global.common.annotation.ServiceToken;
import com.yello.server.global.common.dto.BaseResponse;
import com.yello.server.infrastructure.slack.annotation.SlackSignUpNotification;
Expand Down Expand Up @@ -72,12 +73,12 @@ public BaseResponse<OnBoardingFriendResponse> postFriendList(
}

@GetMapping("/group/univ/name")
public BaseResponse<GroupNameSearchResponse> getSchoolList(
public BaseResponse<GroupNameSearchResponse> getUniversityList(
@NotNull @RequestParam("keyword") String keyword,
@NotNull @RequestParam("page") Integer page
) {
val data = authService.findSchoolsByKeyword(keyword, createPageable(page));
return BaseResponse.success(SCHOOL_NAME_SEARCH_SCHOOL_SUCCESS, data);
val data = authService.findGroupNameContaining(keyword, UserGroupType.UNIVERSITY, createPageable(page));
return BaseResponse.success(UNIVERSITY_NAME_SEARCH_USER_GROUP_SUCCESS, data);
}

@GetMapping("/group/univ/department")
Expand All @@ -86,7 +87,8 @@ public BaseResponse<DepartmentSearchResponse> getDepartmentList(
@NotNull @RequestParam("keyword") String keyword,
@NotNull @RequestParam("page") Integer page
) {
val data = authService.findDepartmentsByKeyword(schoolName, keyword, createPageable(page));
val data = authService.findGroupDepartmentBySchoolNameContaining(schoolName, keyword, UserGroupType.UNIVERSITY,
createPageable(page));
return BaseResponse.success(DEPARTMENT_NAME_SEARCH_BY_SCHOOL_NAME_SCHOOL_SUCCESS, data);
}

Expand All @@ -101,16 +103,15 @@ public BaseResponse<GroupNameSearchResponse> getHighSchoolList(
@NotNull @RequestParam("keyword") String keyword,
@NotNull @RequestParam("page") Integer page
) {
val data = authService.getHighSchoolList(keyword, createPageable(page));
return BaseResponse.success(SCHOOL_NAME_SEARCH_SCHOOL_SUCCESS, data);
val data = authService.findGroupNameContaining(keyword, UserGroupType.HIGH_SCHOOL, createPageable(page));
return BaseResponse.success(UNIVERSITY_NAME_SEARCH_USER_GROUP_SUCCESS, data);
}

@GetMapping("/group/high/class")
public BaseResponse<ClassNameSearchResponse> getHighSchoolClassName(
@NotNull @RequestParam("name") String schoolName,
@NotNull @RequestParam("keyword") String keyword
) {
System.out.println("sfsdfsdfs");
val data = authService.getHighSchoolClassName(schoolName, keyword);
return BaseResponse.success(CLASS_NAME_SEARCH_BY_SCHOOL_NAME_SCHOOL_SUCCESS, data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.yello.server.domain.authorization.dto.response;

import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.entity.UserGroup;
import lombok.Builder;

@Builder
public record ClassNameSearchResponse(
Long groupId
) {

public static ClassNameSearchResponse of(School school) {
public static ClassNameSearchResponse of(UserGroup userGroup) {
return ClassNameSearchResponse.builder()
.groupId(school.getId())
.groupId(userGroup.getId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.yello.server.domain.authorization.dto.response;

import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.entity.UserGroup;
import lombok.Builder;

@Builder
Expand All @@ -9,10 +9,10 @@ public record DepartmentInfo(
String departmentName
) {

public static DepartmentInfo of(School school) {
public static DepartmentInfo of(UserGroup userGroup) {
return DepartmentInfo.builder()
.groupId(school.getId())
.departmentName(school.getDepartmentName())
.groupId(userGroup.getId())
.departmentName(userGroup.getSubGroupName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.yello.server.domain.authorization.dto.response;

import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.entity.UserGroup;
import java.util.List;
import lombok.Builder;

Expand All @@ -10,8 +10,8 @@ public record DepartmentSearchResponse(
List<DepartmentInfo> groupList
) {

public static DepartmentSearchResponse of(int totalCount, List<School> schoolList) {
List<DepartmentInfo> departmentInfoList = schoolList.stream()
public static DepartmentSearchResponse of(int totalCount, List<UserGroup> userGroupList) {
List<DepartmentInfo> departmentInfoList = userGroupList.stream()
.map(DepartmentInfo::of)
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.yello.server.global.common.ErrorCode.TOKEN_ALL_EXPIRED_AUTH_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.TOKEN_NOT_EXPIRED_AUTH_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.YELLOID_REQUIRED_EXCEPTION;
import static com.yello.server.global.common.util.ConstantUtil.RECOMMEND_POINT;

import com.yello.server.domain.authorization.dto.ServiceTokenVO;
import com.yello.server.domain.authorization.dto.kakao.KakaoTokenInfo;
Expand All @@ -22,8 +23,9 @@
import com.yello.server.domain.friend.entity.Friend;
import com.yello.server.domain.friend.repository.FriendRepository;
import com.yello.server.domain.friend.service.FriendManager;
import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.repository.SchoolRepository;
import com.yello.server.domain.group.entity.UserGroup;
import com.yello.server.domain.group.entity.UserGroupType;
import com.yello.server.domain.group.repository.UserGroupRepository;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.service.VoteManager;
Expand All @@ -50,7 +52,7 @@
public class AuthService {

private final UserRepository userRepository;
private final SchoolRepository schoolRepository;
private final UserGroupRepository userGroupRepository;
private final FriendRepository friendRepository;
private final CooldownRepository cooldownRepository;
private final MessageQueueRepository messageQueueRepository;
Expand Down Expand Up @@ -87,7 +89,7 @@ public Boolean isYelloIdDuplicated(String yelloId) {
@Transactional
public SignUpResponse signUp(SignUpRequest signUpRequest) {
authManager.validateSignupRequest(signUpRequest);
final School group = schoolRepository.getById(signUpRequest.groupId());
final UserGroup group = userGroupRepository.getById(signUpRequest.groupId());

final User newUser = userRepository.save(User.of(signUpRequest, group));
newUser.setDeviceToken(signUpRequest.deviceToken());
Expand All @@ -104,13 +106,13 @@ public SignUpResponse signUp(SignUpRequest signUpRequest) {

@Transactional
public void recommendUser(String recommendYelloId, String userYelloId) {
if (recommendYelloId!=null && !recommendYelloId.isEmpty()) {
if (recommendYelloId != null && !recommendYelloId.isEmpty()) {
User recommendedUser = userRepository.getByYelloId(recommendYelloId);
User user = userRepository.getByYelloId(userYelloId);

recommendedUser.increaseRecommendCount();
recommendedUser.increaseRecommendPoint();
user.increaseRecommendPoint();
recommendedUser.addRecommendCount(1L);
recommendedUser.addPoint(RECOMMEND_POINT);
user.addPoint(RECOMMEND_POINT);

notificationService.sendRecommendNotification(user, recommendedUser);

Expand Down Expand Up @@ -148,19 +150,24 @@ public OnBoardingFriendResponse findOnBoardingFriends(OnBoardingFriendRequest fr
return OnBoardingFriendResponse.of(kakaoFriends.size(), pageList);
}

public GroupNameSearchResponse findSchoolsByKeyword(String keyword, Pageable pageable) {
int totalCount = schoolRepository.countDistinctSchoolNameContaining(keyword);
final List<String> nameList = schoolRepository.findDistinctSchoolNameContaining(keyword,
pageable);
public GroupNameSearchResponse findGroupNameContaining(String keyword, UserGroupType userGroupType,
Pageable pageable) {
int totalCount = userGroupRepository.countDistinctGroupNameContaining(keyword, userGroupType);
final List<String> nameList = userGroupRepository.findDistinctGroupNameContaining(keyword, userGroupType,
pageable)
.stream()
.toList();

return GroupNameSearchResponse.of(totalCount, nameList);
}

public DepartmentSearchResponse findDepartmentsByKeyword(String schoolName, String keyword,
Pageable pageable) {
int totalCount = schoolRepository.countAllBySchoolNameContaining(schoolName, keyword);
final List<School> schoolResult = schoolRepository.findAllBySchoolNameContaining(schoolName,
keyword, pageable);
return DepartmentSearchResponse.of(totalCount, schoolResult);
public DepartmentSearchResponse findGroupDepartmentBySchoolNameContaining(String schoolName, String keyword,
UserGroupType userGroupType, Pageable pageable) {
int totalCount = userGroupRepository.countAllByGroupNameContaining(schoolName, keyword, userGroupType);
final List<UserGroup> userGroupResult = userGroupRepository.findAllByGroupNameContaining(schoolName, keyword,
userGroupType, pageable);

return DepartmentSearchResponse.of(totalCount, userGroupResult);
}

@Transactional
Expand All @@ -181,16 +188,9 @@ public ServiceTokenVO reIssueToken(@NotNull ServiceTokenVO tokens) {
throw new NotExpiredTokenForbiddenException(TOKEN_NOT_EXPIRED_AUTH_EXCEPTION);
}

public GroupNameSearchResponse getHighSchoolList(String keyword, Pageable pageable) {
int totalCount = schoolRepository.countDistinctHighSchoolNameContaining(keyword);
final List<String> nameList = schoolRepository.findDistinctHighSchoolNameContaining(keyword,
pageable);
return GroupNameSearchResponse.of(totalCount, nameList);
}

public ClassNameSearchResponse getHighSchoolClassName(String schoolName, String keyword) {
School school =
schoolRepository.findHighSchoolIdBySchoolNameAndClassName(schoolName, keyword);
return ClassNameSearchResponse.of(school);
public ClassNameSearchResponse getHighSchoolClassName(String schoolName, String className) {
UserGroup userGroup =
userGroupRepository.getByGroupNameAndSubGroupName(schoolName, className, UserGroupType.HIGH_SCHOOL);
return ClassNameSearchResponse.of(userGroup);
}
}
Loading

0 comments on commit 2ab2e9c

Please sign in to comment.