Skip to content

Commit

Permalink
[feature/InhaBas#225] 회원관리 API 기능 추가 및 수정
Browse files Browse the repository at this point in the history
[feature/InhaBas#225] 회원관리 API 기능 추가 및 수정
  • Loading branch information
skytin1004 authored Feb 5, 2024
2 parents 47926a7 + 21652eb commit f6587e8
Show file tree
Hide file tree
Showing 43 changed files with 1,050 additions and 400 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ subprojects {
'org.springframework.cloud:spring-cloud-starter-config:3.1.0',
'org.springframework.boot:spring-boot-starter-actuator:2.6.2',
'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.0',

// mail
'org.springframework.boot:spring-boot-starter-mail',
'com.amazonaws:aws-java-sdk-ses:1.12.3',
'org.springframework.boot:spring-boot-starter-thymeleaf'

)
testImplementation 'org.springframework.boot:spring-boot-starter-test'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.inhabas.api.auth;
package com.inhabas.api.auth.config;

import javax.sql.DataSource;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.inhabas.api.auth;
package com.inhabas.api.auth.config;

import java.net.URI;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.inhabas.api.auth;
package com.inhabas.api.auth.config;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.inhabas.api.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;

@Configuration
public class AwsSESConfig {

@Value("${cloud.aws.ses.accessKey}")
private String accessKey;

@Value("${cloud.aws.ses.secretKey}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonSimpleEmailService amazonSimpleEmailService() {

final BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
final AWSStaticCredentialsProvider awsStaticCredentialsProvider =
new AWSStaticCredentialsProvider(basicAWSCredentials);

return AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(awsStaticCredentialsProvider)
.withRegion(region)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.inhabas.api.auth;
package com.inhabas.api.auth.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.inhabas.api.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;

@Configuration
public class TemplateConfig {

@Bean
public SpringResourceTemplateResolver springResourceTemplateResolver() {
SpringResourceTemplateResolver springResourceTemplateResolver =
new SpringResourceTemplateResolver();
springResourceTemplateResolver.setPrefix("classpath:/");
springResourceTemplateResolver.setCharacterEncoding("UTF-8");
springResourceTemplateResolver.setSuffix(".html");
springResourceTemplateResolver.setTemplateMode(TemplateMode.HTML);
springResourceTemplateResolver.setCacheable(false);

return springResourceTemplateResolver;
}

@Bean
public TemplateEngine htmlTemplateEngine(
SpringResourceTemplateResolver springResourceTemplateResolver) {
TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(springResourceTemplateResolver);

return templateEngine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import com.inhabas.api.auth.AuthProperties;
import com.inhabas.api.auth.config.AuthProperties;
import com.inhabas.api.auth.domain.oauth2.cookie.HttpCookieOAuth2AuthorizationRequestRepository;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.web.util.UriComponentsBuilder;

import com.inhabas.api.auth.AuthProperties;
import com.inhabas.api.auth.config.AuthProperties;
import com.inhabas.api.auth.domain.error.authException.UnauthorizedRedirectUrlException;
import com.inhabas.api.auth.domain.oauth2.cookie.CookieUtils;
import com.inhabas.api.auth.domain.oauth2.cookie.HttpCookieOAuth2AuthorizationRequestRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public void setSchoolInformation(SchoolInformation schoolInformation) {
this.schoolInformation = schoolInformation;
}

public void setMemberType(MemberType memberType) {
this.schoolInformation.setMemberType(memberType);
}

public void setRole(Role role) {
this.ibasInformation.setRole(role);
}
Expand All @@ -180,30 +184,6 @@ public boolean isSameMember(Long id) {
return this.id.equals(id);
}

public boolean isUnderGraduate() {
return this.schoolInformation.getMemberType() == MemberType.UNDERGRADUATE;
}

public boolean isGraduated() {
return this.schoolInformation.getMemberType() == MemberType.GRADUATED;
}

public boolean isProfessor() {
return this.schoolInformation.getMemberType() == MemberType.PROFESSOR;
}

public boolean isOther() {
return this.schoolInformation.getMemberType() == MemberType.OTHER;
}

public boolean isBachelor() {
return this.schoolInformation.getMemberType() == MemberType.BACHELOR;
}

public boolean isCompleteToSignUp() {
return this.ibasInformation.isCompleteToSignUp();
}

public void finishSignUp() {
this.ibasInformation.finishSignUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public MemberType getMemberType() {
return this.memberType;
}

public void setMemberType(MemberType memberType) {
this.memberType = memberType;
}

public void setMajor(String major) {
this.major = new Major(major);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

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.security.masking.Masked;
import com.inhabas.api.auth.domain.oauth2.member.security.masking.MaskingType;
Expand All @@ -30,6 +31,8 @@ public class ApprovedMemberManagementDto {
@Masked(type = MaskingType.PHONE)
private String phoneNumber;

@NotNull private MemberType memberType;

@NotBlank private Role role;

@NotNull private Integer generation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import lombok.*;

import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.MemberType;
import com.inhabas.api.auth.domain.oauth2.member.security.masking.Masked;
import com.inhabas.api.auth.domain.oauth2.member.security.masking.MaskingType;
import org.hibernate.validator.constraints.Length;
Expand All @@ -27,6 +28,8 @@ public class NotApprovedMemberManagementDto {

@Email private String email;

@NotNull private MemberType type;

@NotNull @Positive private Integer grade;

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

import java.util.List;

import lombok.*;

import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.MemberType;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class UpdateTypeRequestDto {

private List<Long> memberIdList;

private MemberType type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public interface MemberRepositoryCustom {
List<Member> findAllByRolesInAndStudentIdLike(Collection<Role> roles, String studentId);

List<Member> findAllByRolesInAndNameLike(Collection<Role> roles, String name);

List<Member> findAllGraduatedByRolesInAndStudentLike(Collection<Role> roles, String studentId);

List<Member> findAllGraduatedByRolesInAndNameLike(Collection<Role> roles, String name);
}
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.Role.*;

import java.util.Collection;
import java.util.List;
Expand All @@ -13,12 +14,15 @@

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.MemberType;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.dto.MemberDuplicationQueryCondition;
import com.inhabas.api.auth.domain.oauth2.member.security.MemberAuthorityProvider;
import com.inhabas.api.auth.domain.oauth2.socialAccount.domain.valueObject.UID;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;

@Repository
Expand All @@ -27,6 +31,24 @@
public class MemberRepositoryImpl implements MemberRepositoryCustom {

private final JPAQueryFactory queryFactory;
private static final OrderSpecifier<Integer> ORDER_BY_ROLE =
new CaseBuilder()
.when(member.ibasInformation.role.eq(ADMIN))
.then(1)
.when(member.ibasInformation.role.eq(CHIEF))
.then(2)
.when(member.ibasInformation.role.eq(VICE_CHIEF))
.then(3)
.when(member.ibasInformation.role.eq(EXECUTIVES))
.then(4)
.when(member.ibasInformation.role.eq(SECRETARY))
.then(5)
.when(member.ibasInformation.role.eq(BASIC))
.then(6)
.when(member.ibasInformation.role.eq(DEACTIVATED))
.then(7)
.otherwise(8)
.asc();

@Override
public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id) {
Expand Down Expand Up @@ -69,23 +91,73 @@ public List<Member> findAllByRoleAndNameLike(Role role, String name) {
@Override
public List<Member> findAllByRolesInAndStudentIdLike(Collection<Role> roles, String studentId) {

OrderSpecifier<String> orderByStudentId = member.studentId.id.asc();

return queryFactory
.selectFrom(member)
.where(
member
.ibasInformation
.role
.in(roles)
.and(member.studentId.id.like("%" + studentId + "%")))
.and(member.studentId.id.like("%" + studentId + "%"))
.and(member.schoolInformation.memberType.ne(MemberType.GRADUATED)))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.fetch();
}

@Override
public List<Member> findAllByRolesInAndNameLike(Collection<Role> roles, String name) {

OrderSpecifier<String> orderByStudentId = member.studentId.id.asc();

return queryFactory
.selectFrom(member)
.where(
member
.ibasInformation
.role
.in(roles)
.and(member.name.value.like("%" + name + "%"))
.and(member.schoolInformation.memberType.ne(MemberType.GRADUATED)))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.fetch();
}

@Override
public List<Member> findAllGraduatedByRolesInAndStudentLike(
Collection<Role> roles, String studentId) {

OrderSpecifier<String> orderByStudentId = member.studentId.id.asc();

return queryFactory
.selectFrom(member)
.where(member.ibasInformation.role.in(roles).and(member.name.value.like("%" + name + "%")))
.where(
member
.ibasInformation
.role
.in(roles)
.and(member.schoolInformation.memberType.eq(MemberType.GRADUATED))
.and(member.studentId.id.like("%" + studentId + "%")))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.fetch();
}

@Override
public List<Member> findAllGraduatedByRolesInAndNameLike(Collection<Role> roles, String name) {

OrderSpecifier<String> orderByStudentId = member.studentId.id.asc();

return queryFactory
.selectFrom(member)
.where(
member
.ibasInformation
.role
.in(roles)
.and(member.schoolInformation.memberType.eq(MemberType.GRADUATED))
.and(member.name.value.like("%" + name + "%")))
.orderBy(ORDER_BY_ROLE, orderByStudentId)
.fetch();
}

Expand Down
Loading

0 comments on commit f6587e8

Please sign in to comment.