-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [TNT-83] refactor: 불필요한 log 삭제, isNull()로 수정 * [TNT-83] refactor: 불필요한 log 삭제, isNull()로 수정 * [TNT-83] refactor: isNull()로 수정 * [TNT-83] refactor: conflict 예외 추가 * [TNT-83] refactor: 소셜 이메일, 소셜 타입 추가 * [TNT-83] refactor: 회원 에러 메시지 추가 * [TNT-83] refactor: 회원 필드 유효성 검사 추가 * [TNT-83] refactor: 스키마 내용 수정 * [TNT-83] refactor: 스키마 내용 수정 * [TNT-83] feat: q 클래스 추가 * [TNT-83] feat: 회원가입 api 컨트롤러 구현 * [TNT-83] feat: 회원가입 요청 dto 구현 * [TNT-83] feat: 회원가입 응답 dto 구현 * [TNT-83] feat: 트레이너 엔티티 구현 * [TNT-83] feat: 회원가입 기능 서비스 구현 중 * [TNT-83] refactor: 폴더명 수정 * [TNT-83] refactor: DeletedAtIsNull로 수정 * Update config * [TNT-83] feat: pt 목적 엔티티 구현 * [TNT-83] feat: 트레이니 엔티티 구현 * [TNT-83] feat: q 클래스 생성 * [TNT-83] feat: q 클래스 생성 * [TNT-83] feat: 트레이니, pt 목적 레포지토리 생성 * [TNT-83] feat: cause 추가 * [TNT-84] feat: AWS S3, 이미지 처리 세팅 및 구현 * [TNT-84] feat: AWS S3, 이미지 처리 세팅 및 구현 * [TNT-84] feat: AWS S3, 이미지 처리 세팅 및 구현 * [TNT-84] refactor: pt 목적, 주의사항 필드 순서 수정 * [TNT-84] feat: 세션 ID 추가 * [TNT-84] feat: @repository 제거 * [TNT-84] refactor: 프로필 url, 생일 필드 위치 수정 * [TNT-84] refactor: 불필요한 로그 제거 * [TNT-84] refactor: 불필요한 로그 제거 * [TNT-84] feat: 회원가입 로직 구현 * [TNT-84] feat: 이미지 에러 메시지 추가 * [TNT-84] feat: 트레이너/트레이니 프로필 이미지 분기 처리 * [TNT-84] feat: 이미지 확장자 예외 추가 * [TNT-84] refactor: 불필요한 트랜잭션 제거 * [TNT-84] refactor: 파라미터 개행 수정 * Update submodules * [TNT-84] refactor: 디폴트 이미지 url 수정 * Update submodules * [TNT-84] feat: 회원가입 테스트 구현 * [TNT-84] feat: 테스트 메서드명 수정 * [TNT-84] feat: testcontainer 설정 추가 * [TNT-84] feat: generated 추가 * [TNT-84] refactor: slf4j 제거 * [TNT-84] feat: gitignore에 generated 추가 * [TNT-84] refactor: nullable 추가 / validation 추가 * [TNT-84] refactor: 검증 로직 추가 / static import 추가 * [TNT-84] refactor: static import 추가 * [TNT-84] refactor: static import 추가 * [TNT-84] feat: 회원, 트레이니 에러 메시지 추가 * [TNT-84] refactor: RequestMapping members 로 수정 * [TNT-84] refactor: S3Adapter 추가 / 이미지 업로드 로직 분리 * Delete QPtTrainerTrainee.java * Delete QPtGoal.java * Delete QTrainee.java * Delete QTrainer.java * Delete QBaseTimeEntity.java * Delete QMember.java * [TNT-84] refactor: DB 저장, S3 업로드 트랜잭션 분리 * [TNT-84] refactor: DB 저장, S3 업로드 트랜잭션 분리 * [TNT-84] refactor: S3Adapter 추가 / 이미지 업로드 로직 분리 * [TNT-84] feat: MemberServiceTest 구현 * [TNT-84] feat: 상수 클래스 구현 * [TNT-84] feat: 소셜 로그인 요청 dto 검증 로직 추가 * [TNT-84] refactor: 불필요 임시 페이지 삭제 * [TNT-84] refactor: 불필요 로직 삭제 * [TNT-84] refactor: auto_increment로 수정 * [TNT-84] refactor: 필수 동의 항목 검증 수정 * [TNT-84] refactor: 불필요 validation 어노테이션 제거 * [TNT-84] refactor: 메서드명 및 dto 리팩토링 * [TNT-84] feat: findByIdAndDeletedAtIsNull 생성 * [TNT-84] feat: findByIdAndDeletedAtIsNull 생성 * [TNT-84] feat: redis 설정 제거 * chore: 엘라스틱 캐시 설정 추가
- Loading branch information
Showing
43 changed files
with
1,656 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/java/com/tnt/application/member/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.tnt.application.member; | ||
|
||
import static com.tnt.domain.constant.Constant.TRAINEE; | ||
import static com.tnt.domain.constant.Constant.TRAINEE_DEFAULT_IMAGE; | ||
import static com.tnt.domain.constant.Constant.TRAINER; | ||
import static com.tnt.domain.constant.Constant.TRAINER_DEFAULT_IMAGE; | ||
import static com.tnt.global.error.model.ErrorMessage.MEMBER_CONFLICT; | ||
import static com.tnt.global.error.model.ErrorMessage.MEMBER_NOT_FOUND; | ||
import static com.tnt.global.error.model.ErrorMessage.UNSUPPORTED_MEMBER_TYPE; | ||
import static io.hypersistence.tsid.TSID.Factory.getTsid; | ||
import static io.micrometer.common.util.StringUtils.isNotBlank; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.tnt.application.auth.SessionService; | ||
import com.tnt.domain.member.Member; | ||
import com.tnt.domain.member.SocialType; | ||
import com.tnt.domain.trainee.PtGoal; | ||
import com.tnt.domain.trainee.Trainee; | ||
import com.tnt.domain.trainer.Trainer; | ||
import com.tnt.dto.member.request.SignUpRequest; | ||
import com.tnt.dto.member.response.SignUpResponse; | ||
import com.tnt.global.error.exception.ConflictException; | ||
import com.tnt.global.error.exception.NotFoundException; | ||
import com.tnt.infrastructure.mysql.repository.member.MemberRepository; | ||
import com.tnt.infrastructure.mysql.repository.trainee.PtGoalRepository; | ||
import com.tnt.infrastructure.mysql.repository.trainee.TraineeRepository; | ||
import com.tnt.infrastructure.mysql.repository.trainer.TrainerRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final TrainerRepository trainerRepository; | ||
private final TraineeRepository traineeRepository; | ||
private final PtGoalRepository ptGoalRepository; | ||
private final SessionService sessionService; | ||
|
||
@Transactional | ||
public Long signUp(SignUpRequest request) { | ||
validateMemberNotExists(request.socialId(), request.socialType()); | ||
|
||
return switch (request.memberType()) { | ||
case TRAINER -> createTrainer(request); | ||
case TRAINEE -> createTrainee(request); | ||
default -> throw new IllegalArgumentException(UNSUPPORTED_MEMBER_TYPE.getMessage()); | ||
}; | ||
} | ||
|
||
@Transactional | ||
public SignUpResponse finishSignUpWithImage(String profileImageUrl, Long memberId, String memberType) { | ||
Member member = memberRepository.findByIdAndDeletedAtIsNull(memberId) | ||
.orElseThrow(() -> new NotFoundException(MEMBER_NOT_FOUND)); | ||
|
||
member.updateProfileImageUrl(profileImageUrl); | ||
|
||
String sessionId = String.valueOf(getTsid()); | ||
|
||
sessionService.createOrUpdateSession(sessionId, String.valueOf(member.getId())); | ||
|
||
return new SignUpResponse(memberType, sessionId, member.getName(), member.getProfileImageUrl()); | ||
} | ||
|
||
private void validateMemberNotExists(String socialId, String socialType) { | ||
memberRepository.findBySocialIdAndSocialTypeAndDeletedAtIsNull(socialId, SocialType.valueOf(socialType)) | ||
.ifPresent(member -> { | ||
throw new ConflictException(MEMBER_CONFLICT); | ||
}); | ||
} | ||
|
||
private Member createMember(SignUpRequest request, String defaultImageUrl) { | ||
Member member = Member.builder() | ||
.socialId(request.socialId()) | ||
.fcmToken(request.fcmToken()) | ||
.email(request.socialEmail()) | ||
.name(request.name()) | ||
.profileImageUrl(defaultImageUrl) | ||
.serviceAgreement(request.serviceAgreement()) | ||
.collectionAgreement(request.collectionAgreement()) | ||
.advertisementAgreement(request.advertisementAgreement()) | ||
.pushAgreement(request.pushAgreement()) | ||
.socialType(SocialType.valueOf(request.socialType())) | ||
.build(); | ||
|
||
return memberRepository.save(member); | ||
} | ||
|
||
private Long createTrainer(SignUpRequest request) { | ||
Member member = createMember(request, TRAINER_DEFAULT_IMAGE); | ||
Trainer trainer = Trainer.builder() | ||
.memberId(member.getId()) | ||
.build(); | ||
|
||
trainerRepository.save(trainer); | ||
|
||
return member.getId(); | ||
} | ||
|
||
private Long createTrainee(SignUpRequest request) { | ||
Member member = createMember(request, TRAINEE_DEFAULT_IMAGE); | ||
Trainee trainee = Trainee.builder() | ||
.memberId(member.getId()) | ||
.height(request.height()) | ||
.weight(request.weight()) | ||
.cautionNote(isNotBlank(request.cautionNote()) ? request.cautionNote() : "") | ||
.build(); | ||
|
||
trainee = traineeRepository.save(trainee); | ||
|
||
createPtGoals(trainee, request.goalContents()); | ||
|
||
return member.getId(); | ||
} | ||
|
||
private void createPtGoals(Trainee trainee, List<String> goalContents) { | ||
List<PtGoal> ptGoals = goalContents.stream() | ||
.map(content -> PtGoal.builder() | ||
.traineeId(trainee.getId()) | ||
.content(content) | ||
.build()) | ||
.toList(); | ||
|
||
ptGoalRepository.saveAll(ptGoals); | ||
} | ||
} |
Oops, something went wrong.