Skip to content

Commit

Permalink
[feature/#237] member 추가 기능 및 수정
Browse files Browse the repository at this point in the history
[feature/#237] member 추가 기능 및 수정
  • Loading branch information
skytin1004 authored Feb 21, 2024
2 parents caa32b7 + 16246a8 commit 0f662bc
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public enum MemberType {
UNDERGRADUATE("학부생"),
BACHELOR("학사"),
GRADUATED("대학원생"),
BACHELOR("대학원생"),
GRADUATED("학사"),
PROFESSOR("교수"),
OTHER("기타");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.inhabas.api.auth.domain.oauth2.member.dto;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import org.hibernate.validator.constraints.Length;

@Getter
@NoArgsConstructor
public class ExecutiveMemberDto {

@NotBlank
@Length(max = 50)
private String name;

@NotNull @Positive private Long memberId;

@NotNull private String studentId;

@NotBlank private Role role;

@NotNull private Integer generation;

@NotBlank
@Length(max = 50)
private String major;

private String picture;

@Builder
public ExecutiveMemberDto(
String name,
Long memberId,
String studentId,
Role role,
Integer generation,
String major,
String picture) {
this.name = name;
this.memberId = memberId;
this.studentId = studentId;
this.role = role;
this.generation = generation;
this.major = major;
this.picture = picture;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.inhabas.api.auth.domain.oauth2.member.dto;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Positive;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import io.swagger.v3.oas.annotations.media.Schema;
import org.hibernate.validator.constraints.Length;

@Getter
@NoArgsConstructor
public class HallOfFameDto {

@NotBlank
@Length(max = 50)
private String name;

@NotNull @Positive private Long memberId;

@NotNull private String studentId;

@NotNull private Integer generation;

@NotBlank
@Length(max = 50)
private String major;

private String picture;

@NotNull private String intro;

@NotNull @Email private String email;

@Pattern(regexp = "^(010)-\\d{4}-\\d{4}$")
@Schema(example = "010-0101-0101")
private String phoneNumber;

@Builder
public HallOfFameDto(
String name,
Long memberId,
String studentId,
Integer generation,
String major,
String picture,
String intro,
String email,
String phoneNumber) {
this.name = name;
this.memberId = memberId;
this.studentId = studentId;
this.generation = generation;
this.major = major;
this.picture = picture;
this.intro = intro;
this.email = email;
this.phoneNumber = phoneNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
import com.inhabas.api.auth.domain.oauth2.OAuth2Provider;
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.socialAccount.domain.valueObject.UID;

public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {

List<Member> findAllById(Iterable<Long> memberIdList);

Member getByStudentId(StudentId studentId);

Member findByIbasInformation_Role(Role role);

List<Member> findAllByIbasInformation_IsHOF(boolean IsHOF);

// OAuth
boolean existsByProviderAndUid(OAuth2Provider provider, UID uid);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.inhabas.api.auth.domain.oauth2.member.repository;

import static com.inhabas.api.auth.domain.oauth2.member.domain.entity.QMember.member;
import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.MemberType.*;
import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.*;

import java.util.Collection;
Expand Down Expand Up @@ -50,6 +51,21 @@ public class MemberRepositoryImpl implements MemberRepositoryCustom {
.otherwise(8)
.asc();

private static final OrderSpecifier<Integer> ORDER_BY_TYPE =
new CaseBuilder()
.when(member.schoolInformation.memberType.eq(PROFESSOR))
.then(1)
.when(member.schoolInformation.memberType.eq(BACHELOR))
.then(2)
.when(member.schoolInformation.memberType.eq(UNDERGRADUATE))
.then(3)
.when(member.schoolInformation.memberType.eq(GRADUATED))
.then(4)
.when(member.schoolInformation.memberType.eq(OTHER))
.then(5)
.otherwise(6)
.asc();

@Override
public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id) {
Role role =
Expand Down Expand Up @@ -102,7 +118,7 @@ public List<Member> findAllByRolesInAndStudentIdLike(Collection<Role> roles, Str
.in(roles)
.and(member.studentId.id.like("%" + studentId + "%"))
.and(member.schoolInformation.memberType.ne(MemberType.GRADUATED)))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.orderBy(ORDER_BY_ROLE, ORDER_BY_TYPE, orderByStudentId)
.fetch();
}

Expand All @@ -120,7 +136,7 @@ public List<Member> findAllByRolesInAndNameLike(Collection<Role> roles, String n
.in(roles)
.and(member.name.value.like("%" + name + "%"))
.and(member.schoolInformation.memberType.ne(MemberType.GRADUATED)))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.orderBy(ORDER_BY_ROLE, ORDER_BY_TYPE, orderByStudentId)
.fetch();
}

Expand All @@ -139,7 +155,7 @@ public List<Member> findAllGraduatedByRolesInAndStudentLike(
.in(roles)
.and(member.schoolInformation.memberType.eq(MemberType.GRADUATED))
.and(member.studentId.id.like("%" + studentId + "%")))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.orderBy(ORDER_BY_ROLE, ORDER_BY_TYPE, orderByStudentId)
.fetch();
}

Expand All @@ -157,7 +173,7 @@ public List<Member> findAllGraduatedByRolesInAndNameLike(Collection<Role> roles,
.in(roles)
.and(member.schoolInformation.memberType.eq(MemberType.GRADUATED))
.and(member.name.value.like("%" + name + "%")))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.orderBy(ORDER_BY_ROLE, ORDER_BY_TYPE, orderByStudentId)
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void configure(HttpSecurity http) throws Exception {
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
// API이므로 CORS 활성화, CSRF 비활성화
// API 이므로 CORS 활성화, CSRF 비활성화
.cors()
.and()
.csrf()
Expand All @@ -126,12 +126,16 @@ protected void configure(HttpSecurity http) throws Exception {
// Preflight 방식
.requestMatchers(CorsUtils::isPreFlightRequest)
.permitAll()
.antMatchers("/myInfo/reqeusts")
.antMatchers("/myInfo/requests")
.hasAnyRole(CHIEF.toString(), VICE_CHIEF.toString())
.antMatchers("/myInfo/request/**")
.hasAnyRole(CHIEF.toString(), VICE_CHIEF.toString())

// 회원 관리
.antMatchers("/members/executive")
.hasRole(ANONYMOUS.toString())
.antMatchers("/members/hof")
.hasRole(DEACTIVATED.toString())
.antMatchers("/members/approved/role")
.hasRole(SECRETARY.toString())
.antMatchers("/members/approved/type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.MemberType;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.dto.*;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ContactDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ExecutiveMemberDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.HallOfFameDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.NotApprovedMemberManagementDto;

public interface MemberManageService {

Expand All @@ -14,6 +18,10 @@ public interface MemberManageService {

List<ApprovedMemberManagementDto> getGraduatedMembersBySearch(String search);

List<ExecutiveMemberDto> getExecutiveMembers();

List<HallOfFameDto> getHallOfFame();

void updateUnapprovedMembers(List<Long> memberIdList, String state);

void updateApprovedMembersRole(List<Long> memberIdList, Role role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ContactDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ExecutiveMemberDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.HallOfFameDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.NotApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.auth.domain.oauth2.member.service.SMTPService;
Expand All @@ -32,16 +34,19 @@
public class MemberManageServiceImpl implements MemberManageService {

private static final Role DEFAULT_ROLE_AFTER_FINISH_SIGNUP = NOT_APPROVED;
private static final List<Role> OLD_ROLES =
Arrays.asList(ADMIN, CHIEF, VICE_CHIEF, EXECUTIVES, SECRETARY, BASIC, DEACTIVATED);
private static final Set<Role> OLD_ROLES =
Set.of(ADMIN, CHIEF, VICE_CHIEF, EXECUTIVES, SECRETARY, BASIC, DEACTIVATED);
private static final Set<Role> CHIEF_CHANGEABLE_ROLES =
Set.of(ADMIN, CHIEF, VICE_CHIEF, EXECUTIVES, SECRETARY, BASIC, DEACTIVATED);
private static final Set<Role> SECRETARY_CHANGEABLE_ROLES = Set.of(BASIC, DEACTIVATED);
private static final Set<Role> EXECUTIVE_ROLES =
Set.of(ADMIN, CHIEF, VICE_CHIEF, EXECUTIVES, SECRETARY);
private static final String PASS_STATE = "pass";
private static final String FAIL_STATE = "fail";
private static final String PASS_EMAIL_SUBJECT = "[IBAS] 축하합니다. 동아리에 입부되셨습니다.";
private static final String FAIL_EMAIL_SUBJECT = "[IBAS] 입부 신청 결과를 알립니다.";
private static final String ROLE_PREFIX = "ROLE_";
private static final String BLANK = "";
private final MemberRepository memberRepository;
private final SMTPService amazonSMTPService;
private final AnswerRepository answerRepository;
Expand Down Expand Up @@ -117,6 +122,45 @@ public List<ApprovedMemberManagementDto> getGraduatedMembersBySearch(String sear
.collect(Collectors.toList());
}

@Override
@Transactional(readOnly = true)
public List<ExecutiveMemberDto> getExecutiveMembers() {
final List<Member> members =
memberRepository.findAllByRolesInAndNameLike(EXECUTIVE_ROLES, BLANK);
return members.stream()
.map(
member ->
new ExecutiveMemberDto(
member.getName(),
member.getId(),
member.getStudentId(),
member.getRole(),
member.getSchoolInformation().getGeneration(),
member.getSchoolInformation().getMajor(),
member.getPicture()))
.collect(Collectors.toList());
}

@Override
@Transactional(readOnly = true)
public List<HallOfFameDto> getHallOfFame() {
final List<Member> members = memberRepository.findAllByIbasInformation_IsHOF(true);
return members.stream()
.map(
member ->
new HallOfFameDto(
member.getName(),
member.getId(),
member.getStudentId(),
member.getSchoolInformation().getGeneration(),
member.getSchoolInformation().getMajor(),
member.getPicture(),
member.getIbasInformation().getIntroduce(),
member.getEmail(),
member.getPhone()))
.collect(Collectors.toList());
}

@Override
@Transactional
public void updateUnapprovedMembers(List<Long> memberIdList, String state) {
Expand Down Expand Up @@ -177,7 +221,9 @@ public void updateApprovedMembersType(List<Long> memberIdList, MemberType type)
throw new InvalidInputException();
}

for (Member member : members) member.setMemberType(type);
for (Member member : members) {
member.setMemberType(type);
}

memberRepository.saveAll(members);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ApplicationDetailDto {

@NotNull @Positive private Long memberId;

@NotBlank private String studentId;

@NotBlank private String name;

@NotNull @Positive private Integer grade;
Expand All @@ -39,6 +41,7 @@ public class ApplicationDetailDto {
@Builder
public ApplicationDetailDto(
Long memberId,
String studentId,
String name,
Integer grade,
String major,
Expand All @@ -47,6 +50,7 @@ public ApplicationDetailDto(
LocalDateTime dateJoined,
List<QuestionAnswerDto> answers) {
this.memberId = memberId;
this.studentId = studentId;
this.name = name;
this.grade = grade;
this.major = major;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public ApplicationDetailDto getApplication(Long memberId) {

return ApplicationDetailDto.builder()
.memberId(member.getId())
.studentId(member.getStudentId())
.name(member.getName())
.grade(member.getSchoolInformation().getGrade())
.major(member.getSchoolInformation().getMajor())
Expand Down
Loading

0 comments on commit 0f662bc

Please sign in to comment.