Skip to content

Commit

Permalink
Merge pull request #68 from TaetaetaE01/main
Browse files Browse the repository at this point in the history
affiliation 단과대 리스트 조회
  • Loading branch information
TaetaetaE01 authored Aug 14, 2024
2 parents c932832 + b635463 commit b709298
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HELP.md
.gradle

build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
Expand Down Expand Up @@ -35,3 +36,6 @@ out/

### VS Code ###
.vscode/

### yml file ###
/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.bigbrotherbe.domain.event.controller;

import com.example.bigbrotherbe.domain.event.dto.request.EventRegisterRequest;
import com.example.bigbrotherbe.domain.event.dto.request.EventUpdateRequest;

import com.example.bigbrotherbe.domain.event.dto.response.EventResponse;
import com.example.bigbrotherbe.domain.event.entity.Event;
import com.example.bigbrotherbe.domain.event.service.EventService;
Expand All @@ -13,9 +12,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.example.bigbrotherbe.global.constant.Constant.GetContent.PAGE_DEFAULT_VALUE;
import static com.example.bigbrotherbe.global.constant.Constant.GetContent.SIZE_DEFAULT_VALUE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.bigbrotherbe.domain.meetings.controller;

import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest;
import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest;
import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse;
import com.example.bigbrotherbe.domain.meetings.entity.Meetings;
import com.example.bigbrotherbe.domain.meetings.service.MeetingsService;
Expand All @@ -16,11 +14,8 @@
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.util.List;

import static com.example.bigbrotherbe.global.constant.Constant.GetContent.PAGE_DEFAULT_VALUE;
import static com.example.bigbrotherbe.global.constant.Constant.GetContent.SIZE_DEFAULT_VALUE;
import static com.example.bigbrotherbe.global.exception.enums.SuccessCode.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.example.bigbrotherbe.domain.member.dto.request.ChangePasswordRequest;
import com.example.bigbrotherbe.domain.member.dto.request.MemberRequest;
import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.global.email.EmailRequest;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
Expand All @@ -23,8 +25,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@RequestMapping("/api/big-brother/members")

@RequestMapping("/api/v1/members")
@Tag(name = "멤버", description = "회원가입,로그인 API")
public interface MemberController {

Expand All @@ -39,7 +43,7 @@ public interface MemberController {

@Operation(summary = "로그인")
@PostMapping("/sign-in")
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<JwtToken>>signIn(@RequestBody MemberRequest memberRequest);
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<JwtToken>> signIn(@RequestBody MemberRequest memberRequest);

@PostMapping("/test")
@Operation(summary = "test용", description = "현재는 로그인 멤버의 AffiliationRoleLost를 가져오는 값")
Expand All @@ -64,4 +68,8 @@ public interface MemberController {
@PatchMapping()
@Operation(summary = "비밀번호 변경")
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<Void>> changePassword(@RequestBody ChangePasswordRequest changePasswordRequest);

@GetMapping("/colleges")
@Operation(summary = "단과대학 리스트 조회")
ResponseEntity<com.example.bigbrotherbe.global.exception.response.ApiResponse<List<AffiliationCollegeResponse>>> getCollegesList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.example.bigbrotherbe.domain.member.dto.request.ChangePasswordRequest;
import com.example.bigbrotherbe.domain.member.dto.request.MemberRequest;
import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.global.email.EmailRequest;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
Expand All @@ -19,6 +21,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.example.bigbrotherbe.global.exception.enums.SuccessCode.SUCCESS;

@Slf4j
Expand All @@ -30,7 +34,7 @@ public class MemberControllerImpl implements MemberController {
private final AuthUtil authUtil;
private final JwtTokenProvider jwtTokenProvider;

public ResponseEntity<ApiResponse<MemberResponse>> signUp( SignUpDto signUpDto) {
public ResponseEntity<ApiResponse<MemberResponse>> signUp(SignUpDto signUpDto) {
MemberResponse memberResponse = memberService.userSignUp(signUpDto);

return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberResponse));
Expand All @@ -44,36 +48,41 @@ public ResponseEntity<ApiResponse<JwtToken>> signIn(MemberRequest memberRequest)
log.info("request memberEmail = {}, password = {}", memberEmail, password);
log.info("jwtToken accessToken = {}, refreshToken = {}", jwtToken.getAccessToken(),
jwtToken.getRefreshToken());
return ResponseEntity.ok(ApiResponse.success(SUCCESS, jwtToken)) ;
return ResponseEntity.ok(ApiResponse.success(SUCCESS, jwtToken));
}


public ResponseEntity<ApiResponse<AffiliationListDto>> test() {
return ResponseEntity.ok(ApiResponse.success(SUCCESS,memberService.getMemberAffiliationRoleList()));
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.getMemberAffiliationRoleList()));

}

public ResponseEntity<ApiResponse<MemberInfoResponse>> inquireMemberInfo() {
return ResponseEntity.ok(ApiResponse.success(SUCCESS,memberService.inquireMemberInfo()));
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.inquireMemberInfo()));
}

public ResponseEntity<ApiResponse<EmailVerificationResult>> verificateEmail(String email) {
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verificateEmail(email))) ;
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verificateEmail(email)));
}

public ResponseEntity<ApiResponse<EmailVerificationResult>> sendMessage(EmailRequest emailRequest) {
memberService.sendCodeToEmail(emailRequest.getEmail());
return ResponseEntity.ok(ApiResponse.success(SUCCESS,EmailVerificationResult.builder().authResult(true).build()));
return ResponseEntity.ok(ApiResponse.success(SUCCESS, EmailVerificationResult.builder().authResult(true).build()));
}


public ResponseEntity<ApiResponse<EmailVerificationResult>> verificationEmail(String email, String code) {
return ResponseEntity.ok(ApiResponse.success(SUCCESS,memberService.verifiedCode(email, code)));
return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verifiedCode(email, code)));
}


public ResponseEntity<ApiResponse<Void>> changePassword( ChangePasswordRequest changePasswordRequest) {
public ResponseEntity<ApiResponse<Void>> changePassword(ChangePasswordRequest changePasswordRequest) {
memberService.changePasswrd(changePasswordRequest.password());
return ResponseEntity.ok(ApiResponse.success(SUCCESS));
}

public ResponseEntity<ApiResponse<List<AffiliationCollegeResponse>>> getCollegesList() {
List<AffiliationCollegeResponse> collegesList = memberService.getColleges();
return ResponseEntity.ok(ApiResponse.success(SUCCESS, collegesList));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.bigbrotherbe.domain.member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class AffiliationCollegeResponse {
private int val;
private String councilName;

public static AffiliationCollegeResponse fromAffiliationCollegeResponse(int val, String councilName) {
return AffiliationCollegeResponse.builder()
.val(val)
.councilName(councilName)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum AffiliationCode {
Expand All @@ -12,7 +16,7 @@ public enum AffiliationCode {
STUDENT_COUNCIL(1, "총학", "총학생회"),

// 인문대
HUMANITIES(2, "단과대", "인문대"),
HUMANITIES(2, "단과대", "인문대학"),
KOREAN_LANGUAGE_AND_LITERATURE(3, "학과", "국어국문학과"),
CREATIVE_WRITING(4, "학과", "문예창작학과"),
ENGLISH_LANGUAGE_AND_LITERATURE(5, "학과", "영어영문학과"),
Expand All @@ -25,7 +29,7 @@ public enum AffiliationCode {
PHILOSOPHY(12, "학과", "철학과"),

// 사회과학대
SOCIAL_SCIENCE(13, "단과대", "사회과학대"),
SOCIAL_SCIENCE(13, "단과대", "사회과학대학"),
PUBLIC_ADMINISTRATION(14, "학과", "행정학과"),
ECONOMICS(15, "학과", "경제학과"),
POLITICAL_SCIENCE_AND_DIPLOMACY(16, "학과", "정치외교학과"),
Expand All @@ -34,29 +38,27 @@ public enum AffiliationCode {
YOUTH_GUIDANCE(19, "학과", "청소년지도학과"),

// 경영대
BUSINESS(20, "단과대", "경영대"),
BUSINESS(20, "단과대", "경영대학"),
BUSINESS_ADMINISTRATION(21, "학과", "경영학과"),
MANAGEMENT_INFORMATION_SYSTEMS(22, "학과", "경영정보학과"),
INTERNATIONAL_TRADE(23, "학과", "국제통상학과"),

// 법대
LAW(24, "단과대", "법대"),
LAW(24, "단과대", "법학대학"),
DEPARTMENT_OF_LAW(25, "학과", "법학과"),

// ICT융합대
ICT(26, "단과대", "ICT융합대"),
ICT(26, "단과대", "ICT융합대학"),
DIGITAL_CONTENTS_DESIGN(27, "학과", "디지털콘텐츠디자인학과"),
SOFTWARE_APPLICATIONS(28, "학과", "응용소프트웨어전공"),
DATA_TECHNOLOGY(29, "학과", "데이터테크놀로지전공");

private final int val;
private final String councilType;
private final String councilName;
@JsonValue
public String getCouncilName(){
return councilName;
}
public static AffiliationCode fromcouncilName(String councilName) {


public static AffiliationCode fromCouncilName(String councilName) {
for (AffiliationCode affiliationCodeIns : AffiliationCode.values()) {
if (affiliationCodeIns.councilName.equals(councilName)) {
return affiliationCodeIns;
Expand All @@ -65,4 +67,26 @@ public static AffiliationCode fromcouncilName(String councilName) {
throw new IllegalArgumentException("없는 단체 명입니다." + councilName);
}

public static List<AffiliationCode> getDepartmentsByCollege(AffiliationCode college) {
return Arrays.stream(AffiliationCode.values())
.filter(code -> code.getCouncilType().equals("학과") && code.getVal() > college.getVal() && code.getVal() <= getMaxValForCollege(college))
.collect(Collectors.toList());
}

private static int getMaxValForCollege(AffiliationCode college) {
switch (college) {
case HUMANITIES:
return 12; // 인문대 마지막 학과 val
case SOCIAL_SCIENCE:
return 19; // 사회과학대 마지막 학과 val
case BUSINESS:
return 23; // 경영대 마지막 학과 val
case LAW:
return 25; // 법대 마지막 학과 val
case ICT:
return 29; // ICT융합대 마지막 학과 val
default:
throw new IllegalArgumentException("해당 단과대는 존재하지 않습니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.enums.CouncilType;
import com.example.bigbrotherbe.domain.member.entity.enums.Role;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -24,7 +24,7 @@ public void addAffiliation(String councilType,String affiliation, String role) {
affiliationTypeList.add(AffiliationType
.builder()
.councilType(CouncilType.fromcouncilType(councilType))
.affiliationCode(AffiliationCode.fromcouncilName(affiliation))
.affiliationCode(AffiliationCode.fromCouncilName(affiliation))
.role(Role.fromRole(role)).build());
} catch (IllegalArgumentException e) {
System.err.println("Error: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.bigbrotherbe.domain.member.service;

import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.global.email.EmailVerificationResult;
import com.example.bigbrotherbe.global.jwt.JwtToken;

import java.util.List;

public interface MemberService {
JwtToken userSignIN(String username, String password);

Expand All @@ -27,4 +30,6 @@ public interface MemberService {
void makeAffiliation();

AffiliationListDto getMemberAffiliationRoleList();

List<AffiliationCollegeResponse> getColleges();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationCollegeResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import com.example.bigbrotherbe.domain.member.entity.role.Affiliation;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto;
import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember;
Expand All @@ -24,8 +26,10 @@
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -78,7 +82,7 @@ public MemberResponse userSignUp(SignUpDto signUpDto) {

savedMember = memberLoader.getMember(savedMember.getId());

return MemberResponse.form(savedMember.getId(), savedMember.getUsername(), savedMember.getEmail(), savedMember.getCreateAt(), affiliation.getCouncilType(),affiliation.getAffiliationName());
return MemberResponse.form(savedMember.getId(), savedMember.getUsername(), savedMember.getEmail(), savedMember.getCreateAt(), affiliation.getCouncilType(), affiliation.getAffiliationName());
}

@Transactional
Expand Down Expand Up @@ -144,7 +148,7 @@ public EmailVerificationResult verifiedCode(String email, String authCode) {
memberChecker.checkDuplicatedEmail(email);
String redisAuthCode = mailService.getAuthCode(email);
boolean authResult = redisAuthCode.equals(authCode);
if(!authResult){
if (!authResult) {
throw new BusinessException(ErrorCode.MISMATCH_VERIFIED_CODE);
}
return EmailVerificationResult.of(authResult);
Expand Down Expand Up @@ -182,19 +186,31 @@ public void makeAffiliation() {
affiliationRepository.save(Affiliation.builder().affiliation_id(1L).affiliationName("총학").build());
}

public List<AffiliationCollegeResponse> getColleges() {
return Arrays.stream(AffiliationCode.values())
.filter(code -> code.getCouncilType().equals("단과대"))
.map(code -> AffiliationCollegeResponse.fromAffiliationCollegeResponse(code.getVal(), code.getCouncilName()))
.collect(Collectors.toList());
}

public List<AffiliationCode> getDepartmentsByFaculty(AffiliationCode faculty) {
return AffiliationCode.getDepartmentsByCollege(faculty);
}

@Override
public AffiliationListDto getMemberAffiliationRoleList() {
Member member = authUtil.getLoginMember();
List<AffiliationMember> affiliationMemberList = affiliationMemberRepository.findAllByMemberId(member.getId());
return affiliationListToEntity(member.getUsername(), affiliationMemberList);
}


private AffiliationListDto affiliationListToEntity(String userName, List<AffiliationMember> affiliationMemberList) {
AffiliationListDto affiliationListDto = new AffiliationListDto(userName);

for (AffiliationMember affiliationMember : affiliationMemberList) {
Affiliation affiliation = affiliationMember.getAffiliation();
affiliationListDto.addAffiliation(affiliation.getCouncilType(),affiliation.getAffiliationName(), affiliationMember.getRole());
System.out.println(affiliationListDto.getAffiliationTypeList().toString());
affiliationListDto.addAffiliation(affiliation.getCouncilType(), affiliation.getAffiliationName(), affiliationMember.getRole());
}
return affiliationListDto;
}
Expand Down
Loading

0 comments on commit b709298

Please sign in to comment.