Skip to content

Commit

Permalink
YEL-163 [feat] 대학생, 고등학생 구분
Browse files Browse the repository at this point in the history
YEL-163 [feat] 대학생, 고등학생 구분
  • Loading branch information
hyeonjeongs authored Sep 18, 2023
2 parents a6cb48a + 8f8d2f8 commit 41e6556
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.authorization.controller;

import static com.yello.server.global.common.SuccessCode.CLASS_NAME_SEARCH_BY_SCHOOL_NAME_SCHOOL_SUCCESS;
import static com.yello.server.global.common.SuccessCode.DEPARTMENT_NAME_SEARCH_BY_SCHOOL_NAME_SCHOOL_SUCCESS;
import static com.yello.server.global.common.SuccessCode.LOGIN_SUCCESS;
import static com.yello.server.global.common.SuccessCode.ONBOARDING_FRIENDS_SUCCESS;
Expand All @@ -13,6 +14,7 @@
import com.yello.server.domain.authorization.dto.request.OAuthRequest;
import com.yello.server.domain.authorization.dto.request.OnBoardingFriendRequest;
import com.yello.server.domain.authorization.dto.request.SignUpRequest;
import com.yello.server.domain.authorization.dto.response.ClassNameSearchResponse;
import com.yello.server.domain.authorization.dto.response.DepartmentSearchResponse;
import com.yello.server.domain.authorization.dto.response.GroupNameSearchResponse;
import com.yello.server.domain.authorization.dto.response.OAuthResponse;
Expand Down Expand Up @@ -54,7 +56,8 @@ public BaseResponse<Boolean> getYelloIdValidation(@RequestParam("yelloId") Strin

@PostMapping("/signup")
@SlackSignUpNotification
public BaseResponse<SignUpResponse> postSignUp(@Valid @RequestBody SignUpRequest signUpRequest) {
public BaseResponse<SignUpResponse> postSignUp(
@Valid @RequestBody SignUpRequest signUpRequest) {
val data = authService.signUp(signUpRequest);
return BaseResponse.success(SIGN_UP_SUCCESS, data);
}
Expand All @@ -68,7 +71,7 @@ public BaseResponse<OnBoardingFriendResponse> postFriendList(
return BaseResponse.success(ONBOARDING_FRIENDS_SUCCESS, data);
}

@GetMapping("/school")
@GetMapping("/group/univ/name")
public BaseResponse<GroupNameSearchResponse> getSchoolList(
@NotNull @RequestParam("keyword") String keyword,
@NotNull @RequestParam("page") Integer page
Expand All @@ -77,9 +80,9 @@ public BaseResponse<GroupNameSearchResponse> getSchoolList(
return BaseResponse.success(SCHOOL_NAME_SEARCH_SCHOOL_SUCCESS, data);
}

@GetMapping("/school/department")
@GetMapping("/group/univ/department")
public BaseResponse<DepartmentSearchResponse> getDepartmentList(
@NotNull @RequestParam("school") String schoolName,
@NotNull @RequestParam("name") String schoolName,
@NotNull @RequestParam("keyword") String keyword,
@NotNull @RequestParam("page") Integer page
) {
Expand All @@ -92,4 +95,23 @@ public BaseResponse<ServiceTokenVO> postReIssueToken(@ServiceToken ServiceTokenV
val data = authService.reIssueToken(tokens);
return BaseResponse.success(RE_ISSUE_TOKEN_AUTH_SUCCESS, data);
}

@GetMapping("/group/high/name")
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);
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.yello.server.domain.authorization.dto.response;

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

@Builder
public record ClassNameSearchResponse(
Long groupId
) {

public static ClassNameSearchResponse of(School school) {
return ClassNameSearchResponse.builder()
.groupId(school.getId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.yello.server.domain.authorization.dto.request.OAuthRequest;
import com.yello.server.domain.authorization.dto.request.OnBoardingFriendRequest;
import com.yello.server.domain.authorization.dto.request.SignUpRequest;
import com.yello.server.domain.authorization.dto.response.ClassNameSearchResponse;
import com.yello.server.domain.authorization.dto.response.DepartmentSearchResponse;
import com.yello.server.domain.authorization.dto.response.GroupNameSearchResponse;
import com.yello.server.domain.authorization.dto.response.OAuthResponse;
Expand Down Expand Up @@ -103,7 +104,7 @@ 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);

Expand All @@ -129,7 +130,7 @@ public void makeFriend(User user, List<Long> friendIds) {
Friend savedFriend =
friendRepository.save(Friend.createFriend(user, friend.get()));
friendRepository.save(Friend.createFriend(friend.get(), user));

notificationService.sendFriendNotification(savedFriend);
}
});
Expand Down Expand Up @@ -179,4 +180,17 @@ 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.friend.dto.response;

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

Expand All @@ -15,7 +16,8 @@ public static FriendResponse of(User user) {
return FriendResponse.builder()
.id(user.getId())
.name(user.getName())
.group(user.groupString())
.group(user.getGroup().getSchoolType()==SchoolType.UNIVERSITY ? user.groupString()
: user.highSchoolString())
.profileImage(user.getProfileImage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.friend.dto.response;

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

Expand All @@ -17,7 +18,8 @@ public static SearchFriendVO of(User user, Boolean isFriend) {
return SearchFriendVO.builder()
.id(user.getId())
.name(user.getName())
.group(user.groupString())
.group(user.getGroup().getSchoolType()==SchoolType.UNIVERSITY ? user.groupString()
: user.highSchoolString())
.profileImage(user.getProfileImage())
.yelloId(user.getYelloId())
.isFriend(isFriend)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yello.server.domain.group.entity;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -13,6 +14,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Getter
@Entity
Expand Down Expand Up @@ -42,6 +44,11 @@ public class School {
@Column(nullable = false)
private String departmentName;

@Column(nullable = false)
@Convert(converter = SchoolTypeConverter.class)
@ColumnDefault("UNIVERSITY")
private SchoolType schoolType;

public static School of(String schoolName, String departmentName) {
return School.builder()
.schoolName(schoolName)
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/yello/server/domain/group/entity/SchoolType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yello.server.domain.group.entity;

import java.text.MessageFormat;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SchoolType {
UNIVERSITY("UNIVERSITY"),
HIGHSCHOOL("HIGH_SCHOOL");

private final String intial;

public static SchoolType fromCode(String dbData) {
return Arrays.stream(SchoolType.values())
.filter(v -> v.getIntial().equals(dbData))
.findAny()
.orElseThrow(() -> new IllegalArgumentException(
MessageFormat.format("존재하지 않는 학교타입 입니다. {0}", dbData)));
}

public String intial() {
return intial;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.yello.server.domain.group.entity;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import lombok.extern.log4j.Log4j2;

@Converter
@Log4j2
public class SchoolTypeConverter implements AttributeConverter<SchoolType, String> {

@Override
public String convertToDatabaseColumn(SchoolType schoolType) {
if (schoolType==null) {
return null;
}
return schoolType.getIntial();
}

@Override
public SchoolType convertToEntityAttribute(String dbData) {
if (dbData==null) {
return null;
}
try {
return SchoolType.fromCode(dbData);
} catch (IllegalArgumentException exception) {
log.error("failure to convert cause unexpected code" + dbData + exception);
throw exception;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.yello.server.domain.group.entity.School;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -11,12 +12,14 @@ public interface SchoolJpaRepository extends JpaRepository<School, Long> {

@Query("select count (DISTINCT s.schoolName)from School s " +
"where s.schoolName " +
"like CONCAT('%',:schoolName,'%')")
"like CONCAT('%',:schoolName,'%') " +
"and s.schoolType = 'UNIVERSITY'")
Integer countDistinctSchoolNameContaining(@Param("schoolName") String schoolName);

@Query("select distinct(s.schoolName) from School s " +
"where s.schoolName " +
"like CONCAT('%',:schoolName,'%')")
"like CONCAT('%',:schoolName,'%' )" +
"and s.schoolType = 'UNIVERSITY'")
List<String> findDistinctSchoolNameContaining(@Param("schoolName") String schoolName,
Pageable pageable);

Expand All @@ -32,5 +35,25 @@ Integer countAllBySchoolNameContaining(@Param("schoolName") String schoolName,
List<School> findAllBySchoolNameContaining(@Param("schoolName") String schoolName,
@Param("departmentName") String departmentName, Pageable pageable);

@Query("select count (DISTINCT s.schoolName)from School s " +
"where s.schoolName " +
"like CONCAT('%',:schoolName,'%') " +
"and s.schoolType = 'HIGH_SCHOOL'")
Integer countDistinctHighSchoolNameContaining(@Param("schoolName") String schoolName);

@Query("select distinct(s.schoolName) from School s " +
"where s.schoolName " +
"like CONCAT('%',:schoolName,'%' )" +
"and s.schoolType = 'HIGH_SCHOOL'")
List<String> findDistinctHighSchoolNameContaining(@Param("schoolName") String schoolName,
Pageable pageable);

@Query("select s from School s " +
"where s.schoolName = :schoolName " +
"and s.departmentName = :className " +
"and s.schoolType = 'HIGH_SCHOOL'")
Optional<School> findHighSchoolIdBySchoolNameAndClassName(
@Param("schoolName") String schoolName, @Param("className") String className);


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public interface SchoolRepository {

List<School> findAllBySchoolNameContaining(String schoolName, String departmentName,
Pageable pageable);

Integer countDistinctHighSchoolNameContaining(String schoolName);

List<String> findDistinctHighSchoolNameContaining(String schoolName, Pageable pageable);

School findHighSchoolIdBySchoolNameAndClassName(String schoolName, String className);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ public Integer countAllBySchoolNameContaining(String schoolName, String departme
@Override
public List<School> findAllBySchoolNameContaining(String schoolName, String departmentName,
Pageable pageable) {
return schoolJpaRepository.findAllBySchoolNameContaining(schoolName, departmentName, pageable);
return schoolJpaRepository.findAllBySchoolNameContaining(schoolName, departmentName,
pageable);
}

@Override
public Integer countDistinctHighSchoolNameContaining(String schoolName) {
return schoolJpaRepository.countDistinctHighSchoolNameContaining(schoolName);
}

@Override
public List<String> findDistinctHighSchoolNameContaining(String schoolName, Pageable pageable) {
return schoolJpaRepository.findDistinctHighSchoolNameContaining(schoolName, pageable);
}

@Override
public School findHighSchoolIdBySchoolNameAndClassName(String schoolName,
String className) {
return schoolJpaRepository.findHighSchoolIdBySchoolNameAndClassName(schoolName, className)
.orElseThrow(() -> new GroupNotFoundException(GROUPID_NOT_FOUND_GROUP_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.user.dto.response;

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

Expand All @@ -19,7 +20,8 @@ public static UserDetailResponse of(User user, Integer yelloCount, Integer frien
return UserDetailResponse.builder()
.userId(user.getId())
.name(user.getName())
.group(user.groupString())
.group(user.getGroup().getSchoolType()==SchoolType.UNIVERSITY ? user.groupString()
: user.highSchoolString())
.profileImageUrl(user.getProfileImage())
.yelloId(user.getYelloId())
.yelloCount(yelloCount)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.user.dto.response;

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

Expand All @@ -18,7 +19,8 @@ public static UserResponse of(User user, Integer yelloCount, Integer friendCount
return UserResponse.builder()
.userId(user.getId())
.name(user.getName())
.group(user.groupString())
.group(user.getGroup().getSchoolType()==SchoolType.UNIVERSITY ? user.groupString()
: user.highSchoolString())
.profileImageUrl(user.getProfileImage())
.yelloId(user.getYelloId())
.yelloCount(yelloCount)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/yello/server/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public String groupString() {
return this.group.toString() + " " + this.getGroupAdmissionYear() + "학번";
}

public String highSchoolString() {
return this.group.getSchoolName() + " " + this.getGroupAdmissionYear() + "학년 "
+ this.group.getDepartmentName() + "반";
}

public void increaseRecommendCount() {
this.recommendCount += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum SuccessCode {
READ_QUESTION_ADMIN_SUCCESS(OK, "어드민 페이지 질문 조회에 성공하였습니다."),
READ_QUESTION_DETAIL_ADMIN_SUCCESS(OK, "어드민 페이지 질문 상세 조회에 성공하였습니다."),
DELETE_QUESTION_ADMIN_SUCCESS(OK, "어드민 권환으로 질문지 삭제에 성공하였습니다."),
CLASS_NAME_SEARCH_BY_SCHOOL_NAME_SCHOOL_SUCCESS(OK, "학반 검색에 성공했습니다."),

/**
* 201 CREATED
Expand Down
Loading

0 comments on commit 41e6556

Please sign in to comment.