Skip to content

Commit

Permalink
Merge pull request #104 from 0702Yoon/main
Browse files Browse the repository at this point in the history
MemberSerive에 있던 mail, jwt, affiliation 기능 분리
  • Loading branch information
0702Yoon authored Aug 16, 2024
2 parents 49a305d + 4a05556 commit 696c0ac
Show file tree
Hide file tree
Showing 34 changed files with 275 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Affiliation findAffiliationByName(String name) {

public AffiliationMember createAfiiliationMember(Member savedMember, String affiliationName, Role role) {
Affiliation affiliation = findAffiliationByName(affiliationName);
AffiliationMember affiliationMember= AffiliationMember.builder()
AffiliationMember affiliationMember = AffiliationMember.builder()
.member(savedMember)
.affiliation(affiliation)
.role(role.getRole())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.bigbrotherbe.domain.affiliation.service;

import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse;
import java.util.List;

public interface AffiliationService {
boolean checkExistAffiliationById(Long affiliationId);

List<AffiliationResponse> getColleges();

List<AffiliationResponse> getDepartments(String councilName);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.bigbrotherbe.domain.affiliation.service;

import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class AffiliationServiceImpl implements AffiliationService{
private final AffiliationManger affiliationManger;
@Override
public boolean checkExistAffiliationById(Long affiliationId) {
return affiliationManger.existsById(affiliationId);
}


@Override
public List<AffiliationResponse> getColleges() {
return Arrays.stream(AffiliationCode.values())
.filter(code -> code.getCouncilType().equals("단과대"))
.map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName()))
.collect(Collectors.toList());
}

@Override
public List<AffiliationResponse> getDepartments(String councilName) {
return AffiliationCode.getDepartmentsByCollegeName(councilName);
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.example.bigbrotherbe.domain.event.service;

import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService;
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.repository.EventRepository;
import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.service.MemberService;
import com.example.bigbrotherbe.global.exception.BusinessException;
import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
import com.example.bigbrotherbe.global.file.enums.FileType;
import com.example.bigbrotherbe.global.file.service.FileService;
import com.example.bigbrotherbe.global.jwt.AuthUtil;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -31,16 +31,14 @@
public class EventServiceImpl implements EventService {

private final EventRepository eventRepository;

private final MemberService memberService;
private final AffiliationService affiliationService;
private final FileService fileService;

private final AuthUtil authUtil;

@Override
@Transactional(rollbackFor = Exception.class)
public void registerEvent(EventRegisterRequest eventRegisterRequest, List<MultipartFile> multipartFiles) {
if (!memberService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) {
if (!affiliationService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) {
throw new BusinessException(NO_EXIST_AFFILIATION);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.example.bigbrotherbe.domain.faq.service;

import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService;
import com.example.bigbrotherbe.domain.faq.dto.request.FAQModifyRequest;
import com.example.bigbrotherbe.domain.faq.dto.request.FAQRegisterRequest;
import com.example.bigbrotherbe.domain.faq.dto.response.FAQResponse;
import com.example.bigbrotherbe.domain.faq.entity.FAQ;
import com.example.bigbrotherbe.domain.faq.repository.FAQRepository;
import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.service.MemberService;
import com.example.bigbrotherbe.global.exception.BusinessException;
import com.example.bigbrotherbe.global.exception.enums.ErrorCode;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
import com.example.bigbrotherbe.global.file.enums.FileType;
import com.example.bigbrotherbe.global.file.service.FileService;
import com.example.bigbrotherbe.global.jwt.AuthUtil;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -32,14 +32,14 @@ public class FAQServiceImpl implements FAQService {
private final FAQRepository faqRepository;

private final FileService fileService;
private final MemberService memberService;
private final AffiliationService affiliationService;

private final AuthUtil authUtil;

@Override
@Transactional(rollbackFor = Exception.class) // 트랜잭션 시작 및 커밋 -> 모든 예외상황 발생시 롤백
public void register(FAQRegisterRequest faqRegisterRequest, List<MultipartFile> multipartFiles) {
if (!memberService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) {
if (!affiliationService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) {
throw new BusinessException(NO_EXIST_AFFILIATION);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.example.bigbrotherbe.domain.meetings.service;

import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService;
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.repository.MeetingsRepository;
import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.service.MemberService;
import com.example.bigbrotherbe.global.exception.BusinessException;
import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO;
import com.example.bigbrotherbe.global.file.dto.FileSaveDTO;
import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO;
import com.example.bigbrotherbe.global.file.entity.File;
import com.example.bigbrotherbe.global.file.enums.FileType;
import com.example.bigbrotherbe.global.file.service.FileService;
import com.example.bigbrotherbe.global.jwt.AuthUtil;
import io.lettuce.core.ScriptOutputType;
import com.example.bigbrotherbe.global.jwt.component.AuthUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -24,8 +23,6 @@
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;

import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.*;

Expand All @@ -34,20 +31,17 @@
public class MeetingsServiceImpl implements MeetingsService {

private final MeetingsRepository meetingsRepository;

private final FileService fileService;
private final MemberService memberService;

private final AffiliationService affiliationService;
private final AuthUtil authUtil;


@Override
@Transactional(rollbackFor = Exception.class)
public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, List<MultipartFile> multipartFiles) {
if (!memberService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) {
if (!affiliationService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) {
throw new BusinessException(NO_EXIST_AFFILIATION);
}

if (authUtil.checkCouncilRole(meetingsRegisterRequest.getAffiliationId())) {
throw new BusinessException(NOT_COUNCIL_MEMBER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberChecker {

private final MemberRepository memberRepository;
Expand All @@ -20,11 +22,4 @@ public void checkExistUserEmail(String email) {
}
}

public void checkDuplicatedEmail(String email) {
Optional<Member> member = memberRepository.findByEmail(email);
if (member.isPresent()) {
throw new BusinessException(ErrorCode.EXIST_EMAIL);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.bigbrotherbe.domain.member.component;

import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.entity.Member;
import com.example.bigbrotherbe.domain.member.repository.MemberRepository;
import com.example.bigbrotherbe.global.exception.BusinessException;
Expand All @@ -16,25 +15,6 @@ public class MemberLoader {
private final MemberRepository memberRepository;


public Member saveMember(Member member) {
return memberRepository.save(member);
}

public Member getMember(Long id) {
return memberRepository.findById(id).orElseThrow(
() -> new BusinessException(ErrorCode.FAIL_LOAD_MEMBER)
);
}

public Member findByUserName(String username) {
return memberRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 이름입니다."));
}

public Member findByMemberId(String memberId) {
return memberRepository.findById(Long.valueOf(memberId)).orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 아이디입니다."));
}

public Member findByMemberEmail(String memberEmail) {
return memberRepository.findByEmail(memberEmail).orElseThrow(() -> new BusinessException(ErrorCode.NO_EXIST_EMAIL));

Expand All @@ -47,7 +27,4 @@ public List<Member> getAllMember() {
return memberRepository.findAll();
}

public Member signUp(SignUpDto signUpDto, String encodePassword) {
return saveMember(signUpDto.toEntity(signUpDto,encodePassword));
}
}
Loading

0 comments on commit 696c0ac

Please sign in to comment.