Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 회원가입 API 구현 #36

Merged
merged 34 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7a4fad0
[CHOER] 임시 커밋
paragon0107 Jul 10, 2024
75c0378
[CHORE] 임시커밋
paragon0107 Jul 10, 2024
68dd935
Merge branch 'develop' of https://github.com/Team-Tiki/TIKI_SERVER in…
paragon0107 Jul 10, 2024
34ded94
[FEAT] 회원가입 관련 에러코드 추가
paragon0107 Jul 11, 2024
6e48ca2
[FEAT] 맴버 생성 메서드 추가
paragon0107 Jul 11, 2024
12cb639
[FEAT] getUri 추가
paragon0107 Jul 11, 2024
b728115
[FEAT] 이메일 존재 체크 메서드 추가
paragon0107 Jul 11, 2024
a4de3a6
[CHORE] 아이템 명 변경
paragon0107 Jul 11, 2024
ee0c901
[FEAT] findByEmail 추가
paragon0107 Jul 11, 2024
55e35d5
[CHORE] enum명 변경
paragon0107 Jul 11, 2024
75c185c
[FEAT] 회원가입 조건 메서드 추가
paragon0107 Jul 11, 2024
4cd3cff
[CHORE] University값 삭제
paragon0107 Jul 11, 2024
352f05c
[CHORE] 커밋 반영
paragon0107 Jul 11, 2024
2864c82
[CHORE] getUri Import
paragon0107 Jul 11, 2024
22da79a
[CHORE] 회원가입 Dto birth 데이터 형식 변경
paragon0107 Jul 11, 2024
11832fa
[FEAT] MemberSaver구현
paragon0107 Jul 11, 2024
c2da304
[FEAT] 회원가입 api 구현
paragon0107 Jul 11, 2024
22e5273
[CHORE] 컨벤션 적용
paragon0107 Jul 11, 2024
ceb6273
[CHORE] Univ enum값 변경
paragon0107 Jul 11, 2024
e36f167
[FEAT] @Transactional 추가및 로직수정
paragon0107 Jul 11, 2024
03b2e73
[CHORE] 불필요한 import문 삭제
paragon0107 Jul 11, 2024
2b872fc
[CHORE] 컨벤셕 적용
paragon0107 Jul 11, 2024
5ccf16e
[FEAT] EncoderConfig 추가
paragon0107 Jul 11, 2024
0d13147
[FEAT] 비밀번호 암호화
paragon0107 Jul 11, 2024
f252a23
[CHORE] RequiredArgsConstructor 삭제
paragon0107 Jul 11, 2024
27c271f
[CHORE] 멤버 저장 메서드 분리
paragon0107 Jul 11, 2024
456f890
[CHORE] 비밀번호 확인 변수명 변경
paragon0107 Jul 11, 2024
442f1a8
[CHORE] MemberFinder 메서드명 변경
paragon0107 Jul 11, 2024
cdc3251
[CHORE] 컨벤션 적용
paragon0107 Jul 11, 2024
a05c198
[CHORE] 컨벤션 적용
paragon0107 Jul 11, 2024
05f5870
[REFACTOR] 메서드 분리
paragon0107 Jul 11, 2024
95ae7e3
[CHORE] 변수명 변경
paragon0107 Jul 11, 2024
9ca236e
[CHORE] 컨벤션 반영
paragon0107 Jul 11, 2024
d30730d
[CHORE] 변수명 변경 및 컨벤션 적용
paragon0107 Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/tiki/server/auth/config/EncoderConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tiki.server.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class EncoderConfig {

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
public class AuthController {

private final AuthService authService;


}
11 changes: 11 additions & 0 deletions src/main/java/com/tiki/server/common/entity/University.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tiki.server.common.entity;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
public enum University {
건국대학교;

Chan531 marked this conversation as resolved.
Show resolved Hide resolved
}
19 changes: 11 additions & 8 deletions src/main/java/com/tiki/server/member/adapter/MemberFinder.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.tiki.server.member.adapter;

import static com.tiki.server.member.message.ErrorCode.INVALID_MEMBER;
import static com.tiki.server.team.message.ErrorCode.INVALID_TEAM;

import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.member.entity.Member;
import com.tiki.server.member.exception.MemberException;
import com.tiki.server.member.repository.MemberRepository;
import com.tiki.server.team.entity.Team;
import com.tiki.server.team.exception.TeamException;

import lombok.RequiredArgsConstructor;

import java.util.Optional;

@RepositoryAdapter
@RequiredArgsConstructor
public class MemberFinder {

private final MemberRepository memberRepository;
private final MemberRepository memberRepository;

public Optional<Member> findByEmail(String email) {
return memberRepository.findByEmail(email);
}

public Member findById(long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new MemberException(INVALID_MEMBER));
}
public Member findById(long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new MemberException(INVALID_MEMBER));
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/tiki/server/member/adapter/MemberSaver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tiki.server.member.adapter;

import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.member.entity.Member;
import com.tiki.server.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;

@RepositoryAdapter
@RequiredArgsConstructor
public class MemberSaver {

private final MemberRepository memberRepository;

public void save(Member member) {
memberRepository.save(member);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package com.tiki.server.member.controller;

import com.tiki.server.member.dto.request.MemberProfileCreateRequest;
import com.tiki.server.common.dto.BaseResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tiki.server.member.service.MemberService;

import lombok.RequiredArgsConstructor;

import static com.tiki.server.common.dto.SuccessResponse.success;
import static com.tiki.server.common.support.UriGenerator.getUri;
import static com.tiki.server.member.message.SuccessMessage.SUCCESS_CREATE_MEMBER;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1/members")
public class MemberController {

private final MemberService memberService;
private final MemberService memberService;

@PostMapping
public ResponseEntity<BaseResponse> signUp(@RequestBody MemberProfileCreateRequest request) {
memberService.signUp(request);
return ResponseEntity.created(getUri("/")).body(success(SUCCESS_CREATE_MEMBER.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tiki.server.member.dto.request;

import java.time.LocalDate;

import com.tiki.server.common.entity.University;
import lombok.NonNull;

public record MemberProfileCreateRequest(
@NonNull String name,
@NonNull LocalDate birth,
@NonNull University Univ,
@NonNull String email,
@NonNull String password,
@NonNull String passwordChecker
) {
}
38 changes: 25 additions & 13 deletions src/main/java/com/tiki/server/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,44 @@

import com.tiki.server.common.entity.BaseTime;

import com.tiki.server.common.entity.University;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Entity
@Getter
@NoArgsConstructor
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Member extends BaseTime {

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "member_id")
private Long id;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "member_id")
private Long id;

private String email;
private String email;

private String password;
private String password;

private String name;
private String name;

private LocalDate birth;
private LocalDate birth;

@Enumerated(value = STRING)
private University univ;
@Enumerated(value = STRING)
private University univ;

public static Member of(String email, String password, String name, LocalDate birth, University univ) {
return Member.builder()
.email(email)
.password(password)
.name(name)
.birth(birth)
.univ(univ)
.build();
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/tiki/server/member/entity/University.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class MemberException extends RuntimeException {

private final ErrorCode errorCode;

public MemberException(ErrorCode errorCode) {
super("[MemberException] : " + errorCode.getMessage());
this.errorCode = errorCode;
}
public MemberException(ErrorCode errorCode) {
super("[MemberException] : " + errorCode.getMessage());
this.errorCode = errorCode;
}
}
18 changes: 12 additions & 6 deletions src/main/java/com/tiki/server/member/message/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package com.tiki.server.member.message;

import static org.springframework.http.HttpStatus.NOT_FOUND;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Getter;

import static org.springframework.http.HttpStatus.*;

@Getter
@AllArgsConstructor
public enum ErrorCode {
Chan531 marked this conversation as resolved.
Show resolved Hide resolved

/* 404 NOT_FOUND : 자원을 찾을 수 없음 */
INVALID_MEMBER(NOT_FOUND, "유효하지 않은 회원입니다.");
/* 400 BAD REQUEST: 잘못된 요청*/
UNMATCHED_PASSWORD(BAD_REQUEST, "비밀번호가 일치하지 않습니다."),

/* 404 NOT_FOUND : 자원을 찾을 수 없음 */
INVALID_MEMBER(NOT_FOUND, "유효하지 않은 회원입니다."),

/* 409 CONFLICT : 중복된 데이터 존재*/
CONFLICT_MEMBER(CONFLICT, "존재하는 이메일입니다.");

private final HttpStatus httpStatus;
private final String message;
private final HttpStatus httpStatus;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@RequiredArgsConstructor
public enum SuccessMessage {

TEMP("컴파일 에러 방지용");
SUCCESS_CREATE_MEMBER("회원가입 성공");

private final String message;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@

import com.tiki.server.member.entity.Member;

import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByEmail(String email);

}
49 changes: 49 additions & 0 deletions src/main/java/com/tiki/server/member/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
package com.tiki.server.member.service;

import com.tiki.server.member.adapter.MemberFinder;
import com.tiki.server.member.adapter.MemberSaver;
import com.tiki.server.member.dto.request.MemberProfileCreateRequest;
import com.tiki.server.member.entity.Member;
import com.tiki.server.member.exception.MemberException;
import lombok.NonNull;
import lombok.val;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

import static com.tiki.server.member.message.ErrorCode.CONFLICT_MEMBER;
import static com.tiki.server.member.message.ErrorCode.UNMATCHED_PASSWORD;

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

private final MemberSaver memberSaver;
private final MemberFinder memberFinder;
private final PasswordEncoder passwordEncoder;

@Transactional
public void signUp(MemberProfileCreateRequest request) {
emailCheck(request.email());
passwordCheck(request.password(), request.passwordChecker());
val member = createMember(request);
saveMember(member);
}

private void emailCheck(String email) {
memberFinder.findByEmail(email).ifPresent(member -> {
throw new MemberException(CONFLICT_MEMBER);
});
}

private void passwordCheck(String password, String passwordChecker) {
if (!password.equals(passwordChecker)) {
throw new MemberException(UNMATCHED_PASSWORD);
}
}

private Member createMember(MemberProfileCreateRequest request) {
return Member.of(
request.email(),
passwordEncoder.encode(request.password()),
request.name(),
request.birth(),
request.Univ());
}

private void saveMember(Member member) {
memberSaver.save(member);
}

}
Loading