-
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.
Merge branch 'main' of https://github.com/TAVE-WEBSITE/TAVE-WEBSITE-BE …
…into feat/#25/정규-세션-비지니스-로직-개발
- Loading branch information
Showing
22 changed files
with
476 additions
and
6 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/tave/tavewebsite/domain/member/controller/ManagerController.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,40 @@ | ||
package com.tave.tavewebsite.domain.member.controller; | ||
|
||
import com.tave.tavewebsite.domain.member.dto.request.RegisterManagerRequestDto; | ||
import com.tave.tavewebsite.domain.member.dto.response.CheckNickNameResponseDto; | ||
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto; | ||
import com.tave.tavewebsite.domain.member.service.MemberService; | ||
import com.tave.tavewebsite.global.mail.dto.MailResponseDto; | ||
import com.tave.tavewebsite.global.success.SuccessResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/manager") | ||
@RequiredArgsConstructor | ||
public class ManagerController { | ||
|
||
private final MemberService memberService; | ||
|
||
@PostMapping | ||
public SuccessResponse<MailResponseDto> registerManager(@RequestBody @Valid RegisterManagerRequestDto requestDto) { | ||
MailResponseDto response = memberService.saveMember(requestDto); | ||
return new SuccessResponse<>(response); | ||
} | ||
|
||
@GetMapping("/unauthorized") | ||
public SuccessResponse<List<UnauthorizedManagerResponseDto>> getUnauthorizedManager(){ | ||
List<UnauthorizedManagerResponseDto> response = memberService.getUnauthorizedManager(); | ||
return new SuccessResponse<>(response); | ||
} | ||
|
||
@GetMapping("/{nickName}") | ||
public SuccessResponse<CheckNickNameResponseDto> checkNickName(@PathVariable String nickName){ | ||
memberService.validateNickname(nickName); | ||
CheckNickNameResponseDto response = new CheckNickNameResponseDto(nickName); | ||
return new SuccessResponse<>(response, nickName+" 사용가능합니다."); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/tave/tavewebsite/domain/member/dto/request/RegisterManagerRequestDto.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,31 @@ | ||
package com.tave.tavewebsite.domain.member.dto.request; | ||
|
||
import com.tave.tavewebsite.domain.member.entity.DepartmentType; | ||
import com.tave.tavewebsite.domain.member.entity.JobType; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
|
||
public record RegisterManagerRequestDto( | ||
|
||
@Email(message = "이메일 형식에 맞게 작성해주세요.") | ||
String email, | ||
@NotNull(message = "비밀번호를 입력하세요.") | ||
@Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\W).+$", | ||
message = "비밀번호는 8자 이상이어야 하며, 대문자, 소문자, 특수문자를 포함해야 합니다.") | ||
String password, | ||
@NotNull(message ="아이디를 입력해주세요") | ||
String nickname, | ||
@NotNull(message ="이름을 입력해주세요") | ||
String username, | ||
@NotNull(message ="아지트 아이디를 입력해주세요") | ||
String agitId, | ||
@NotNull(message = "본인 기수를 입력해주세요") | ||
String generation, | ||
@NotNull(message = "부서를 선택해주세요") | ||
DepartmentType department, | ||
@NotNull(message = "직책을 선택해주세요") | ||
JobType job | ||
|
||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/tave/tavewebsite/domain/member/dto/response/CheckNickNameResponseDto.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,6 @@ | ||
package com.tave.tavewebsite.domain.member.dto.response; | ||
|
||
public record CheckNickNameResponseDto( | ||
String email | ||
) { | ||
} |
25 changes: 25 additions & 0 deletions
25
.../java/com/tave/tavewebsite/domain/member/dto/response/UnauthorizedManagerResponseDto.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,25 @@ | ||
package com.tave.tavewebsite.domain.member.dto.response; | ||
|
||
import com.tave.tavewebsite.domain.member.entity.DepartmentType; | ||
import com.tave.tavewebsite.domain.member.entity.JobType; | ||
import com.tave.tavewebsite.domain.member.entity.Member; | ||
|
||
public record UnauthorizedManagerResponseDto( | ||
|
||
String username, | ||
DepartmentType department, | ||
JobType job, | ||
String generation, | ||
String agitId | ||
|
||
) { | ||
public static UnauthorizedManagerResponseDto fromEntity(Member member){ | ||
return new UnauthorizedManagerResponseDto( | ||
member.getUsername(), | ||
member.getDepartment(), | ||
member.getJob(), | ||
member.getGeneration(), | ||
member.getAgitId() | ||
); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/tave/tavewebsite/domain/member/entity/RoleType.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,8 @@ | ||
package com.tave.tavewebsite.domain.member.entity; | ||
|
||
public enum RoleType { | ||
MEMBER, | ||
MANAGER, | ||
ADMIN, | ||
UNAUTHORIZED_MANAGER | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/tave/tavewebsite/domain/member/exception/DuplicateEmailException.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,11 @@ | ||
package com.tave.tavewebsite.domain.member.exception; | ||
|
||
import com.tave.tavewebsite.global.exception.BaseErrorException; | ||
|
||
import static com.tave.tavewebsite.domain.member.exception.ErrorMessage.DUPLICATE_EMAIL; | ||
|
||
public class DuplicateEmailException extends BaseErrorException { | ||
public DuplicateEmailException() { | ||
super(DUPLICATE_EMAIL.getCode(), DUPLICATE_EMAIL.getMessage()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/tave/tavewebsite/domain/member/exception/DuplicateNicknameException.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,11 @@ | ||
package com.tave.tavewebsite.domain.member.exception; | ||
|
||
import com.tave.tavewebsite.global.exception.BaseErrorException; | ||
|
||
import static com.tave.tavewebsite.domain.member.exception.ErrorMessage.DUPLICATE_NICKNAME; | ||
|
||
public class DuplicateNicknameException extends BaseErrorException { | ||
public DuplicateNicknameException() { | ||
super(DUPLICATE_NICKNAME.getCode(), DUPLICATE_NICKNAME.getMessage()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/tave/tavewebsite/domain/member/exception/ErrorMessage.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,16 @@ | ||
package com.tave.tavewebsite.domain.member.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorMessage { | ||
|
||
NOT_FOUNT_USER(400, "유저를 찾을 수 없습니다."), | ||
DUPLICATE_EMAIL(400, "중복되는 이메일입니다."), | ||
DUPLICATE_NICKNAME(400, "이미 사용중인 아이디입니다. 다른 아이디로 가입해주세요."); | ||
|
||
final int code; | ||
final String message; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/tave/tavewebsite/domain/member/exception/NotFoundMemberException.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,11 @@ | ||
package com.tave.tavewebsite.domain.member.exception; | ||
|
||
import com.tave.tavewebsite.global.exception.BaseErrorException; | ||
|
||
import static com.tave.tavewebsite.domain.member.exception.ErrorMessage.NOT_FOUNT_USER; | ||
|
||
public class NotFoundMemberException extends BaseErrorException { | ||
public NotFoundMemberException() { | ||
super(NOT_FOUNT_USER.getCode(), NOT_FOUNT_USER.getMessage()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/tave/tavewebsite/domain/member/memberRepository/MemberRepository.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,17 @@ | ||
package com.tave.tavewebsite.domain.member.memberRepository; | ||
|
||
import com.tave.tavewebsite.domain.member.entity.Member; | ||
import com.tave.tavewebsite.domain.member.entity.RoleType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> findByEmail(String email); | ||
|
||
Optional<Member> findByNickname(String Nickname); | ||
|
||
List<Member> findByRole(RoleType role); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/tave/tavewebsite/domain/member/service/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,60 @@ | ||
package com.tave.tavewebsite.domain.member.service; | ||
|
||
import com.tave.tavewebsite.domain.member.dto.request.RegisterManagerRequestDto; | ||
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto; | ||
import com.tave.tavewebsite.domain.member.entity.Member; | ||
import com.tave.tavewebsite.domain.member.entity.RoleType; | ||
import com.tave.tavewebsite.domain.member.exception.DuplicateEmailException; | ||
import com.tave.tavewebsite.domain.member.exception.DuplicateNicknameException; | ||
import com.tave.tavewebsite.domain.member.memberRepository.MemberRepository; | ||
import com.tave.tavewebsite.global.mail.service.MailService; | ||
import com.tave.tavewebsite.global.mail.dto.MailResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
import static com.tave.tavewebsite.domain.member.entity.RoleType.UNAUTHORIZED_MANAGER; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final MailService mailService; | ||
|
||
public MailResponseDto saveMember(RegisterManagerRequestDto requestDto){ | ||
|
||
validateNickname(requestDto.nickname()); | ||
validateEmail(requestDto.email()); | ||
|
||
// PasswordEncoder 추가되면 | ||
// toMember에서 encode(requestDto.getPassword()) 추가하기 | ||
// 추가 후 위 주석은 삭제 | ||
Member saveMember = memberRepository.save(Member.toMember(requestDto)); | ||
return mailService.sendManagerRegisterMessage(saveMember.getEmail()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<UnauthorizedManagerResponseDto> getUnauthorizedManager(){ | ||
return memberRepository.findByRole(UNAUTHORIZED_MANAGER).stream() | ||
.map(UnauthorizedManagerResponseDto::fromEntity) | ||
.toList(); | ||
} | ||
|
||
private void validateEmail(String email){ | ||
memberRepository.findByEmail(email).ifPresent( | ||
member -> {throw new DuplicateEmailException();} | ||
); | ||
} | ||
|
||
public void validateNickname(String nickname){ | ||
memberRepository.findByNickname(nickname).ifPresent( | ||
member -> {throw new DuplicateNicknameException();} | ||
); | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/tave/tavewebsite/domain/session/entity/repository/SessionRepository.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,9 @@ | ||
package com.tave.tavewebsite.domain.session.entity.repository; | ||
|
||
|
||
import com.tave.tavewebsite.domain.session.entity.Session; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SessionRepository extends JpaRepository<Session, Long> { | ||
|
||
} |
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
Oops, something went wrong.