-
Notifications
You must be signed in to change notification settings - Fork 0
8주차 미션 [이서] #30
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
Open
seoyoon127
wants to merge
14
commits into
main
Choose a base branch
from
leeseo/week8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
8주차 미션 [이서] #30
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e8b4a6
feat: BaseEntity 생성 #15
seoyoon127 b69a725
feat: Entity 생성 #15
seoyoon127 94b4745
feat: 연관관계 매핑 #15
seoyoon127 151acba
feat: 회원 관련 api #15
seoyoon127 04bd0c8
feat: 미션 관련 api #15
seoyoon127 ca551d2
feat: 리뷰 관련 api #15
seoyoon127 0e4f719
refactor: 5주차 - @Schema, @Valid 추가 #21
seoyoon127 91dba6b
refactor: 6주차 - 공통 메서드 생성, N+1 문제 방지 #21
seoyoon127 402d009
feat: 미션 조회하기 페이징 (offset 기반) #21
seoyoon127 3c5f5f0
feat: 리뷰 조회하기 페이징 (cursor 기반) #21
seoyoon127 4994afd
refactor: 리뷰 별점순 조회 수정, 리뷰 사진 페이징 구현 #21
seoyoon127 4b4d1bc
refactor: cascade 추가 #21
seoyoon127 7a6da96
feat: 회원가입 api 구현 #29
seoyoon127 893a70e
feat: exceptionHandling 구현 #29
seoyoon127 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/controller/AuthController.java
This file contains hidden or 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,30 @@ | ||
| package com.example.umc10th.domain.auth.controller; | ||
|
|
||
| import com.example.umc10th.domain.auth.dto.AuthReqDto; | ||
| import com.example.umc10th.domain.auth.dto.AuthResDto; | ||
| import com.example.umc10th.domain.auth.exception.code.AuthSuccessCode; | ||
| import com.example.umc10th.domain.auth.service.AuthService; | ||
| import com.example.umc10th.global.apiPayload.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| 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; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/auth") | ||
| @Tag(name = "Auth", description = "인증 관련 API") | ||
| public class AuthController implements AuthControllerDocs{ | ||
|
|
||
| private final AuthService authService; | ||
|
|
||
| @PostMapping("/sign-up") | ||
| public ApiResponse<AuthResDto.Id> signUp( | ||
| @RequestBody @Valid AuthReqDto.Signup dto | ||
| ) { | ||
| return ApiResponse.onSuccess(AuthSuccessCode.SIGNUP_OK, authService.signUp(dto)); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
.../umc10th/src/main/java/com/example/umc10th/domain/auth/controller/AuthControllerDocs.java
This file contains hidden or 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,19 @@ | ||
| package com.example.umc10th.domain.auth.controller; | ||
|
|
||
| import com.example.umc10th.domain.auth.dto.AuthReqDto; | ||
| import com.example.umc10th.domain.auth.dto.AuthResDto; | ||
| import com.example.umc10th.global.apiPayload.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import jakarta.validation.Valid; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
|
|
||
| public interface AuthControllerDocs { | ||
|
|
||
| @Operation( | ||
| summary = "회원가입", | ||
| description = "이메일 회원가입 진행" | ||
| ) | ||
| public ApiResponse<AuthResDto.Id> signUp( | ||
| @RequestBody @Valid AuthReqDto.Signup dto | ||
| ); | ||
| } |
28 changes: 28 additions & 0 deletions
28
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/converter/AuthConverter.java
This file contains hidden or 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,28 @@ | ||
| package com.example.umc10th.domain.auth.converter; | ||
|
|
||
| import com.example.umc10th.domain.auth.dto.AuthReqDto; | ||
| import com.example.umc10th.domain.member.entity.Member; | ||
| import com.example.umc10th.domain.member.enums.SocialType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
|
|
||
| public class AuthConverter { | ||
|
|
||
| public static Member toMember( | ||
| AuthReqDto.Signup dto, | ||
| String salt | ||
| ) { | ||
| return Member.builder() | ||
| .email(dto.email()) | ||
| .password(salt) | ||
| .nickname(dto.nickname()) | ||
| .gender(dto.gender()) | ||
| .birth(dto.birth()) | ||
| .address(dto.address()) | ||
| .fullAddress(dto.fullAddress()) | ||
| .socialId("email"+UUID.randomUUID()) | ||
| .socialType(SocialType.EMAIL) | ||
| .build(); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/dto/AuthReqDto.java
This file contains hidden or 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,37 @@ | ||
| package com.example.umc10th.domain.auth.dto; | ||
|
|
||
| import com.example.umc10th.domain.member.dto.MemberReqDto; | ||
| import com.example.umc10th.domain.member.enums.FoodType; | ||
| import com.example.umc10th.domain.member.enums.Gender; | ||
| import com.example.umc10th.domain.mission.enums.Address; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| public class AuthReqDto { | ||
|
|
||
| @Schema(name = "SignUp", description = "회원가입 정보를 저장합합니다.") | ||
| public record Signup ( | ||
| @NotBlank | ||
| String email, | ||
| @NotBlank | ||
| String password, | ||
| @NotBlank | ||
| String nickname, | ||
| @NotNull | ||
| Gender gender, | ||
| @NotNull | ||
| LocalDate birth, | ||
| @NotNull | ||
| Address address, | ||
| @NotBlank | ||
| String fullAddress, | ||
| @NotNull | ||
| List<FoodType> food | ||
| ) {} | ||
| } |
13 changes: 13 additions & 0 deletions
13
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/dto/AuthResDto.java
This file contains hidden or 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,13 @@ | ||
| package com.example.umc10th.domain.auth.dto; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AuthResDto { | ||
|
|
||
| @Builder | ||
| public record Id( | ||
| Long id | ||
| ) {} | ||
| } |
10 changes: 10 additions & 0 deletions
10
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/exception/AuthException.java
This file contains hidden or 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,10 @@ | ||
| package com.example.umc10th.domain.auth.exception; | ||
|
|
||
| import com.example.umc10th.global.apiPayload.code.BaseErrorCode; | ||
| import com.example.umc10th.global.apiPayload.exception.BaseException; | ||
|
|
||
| public class AuthException extends BaseException { | ||
| public AuthException(BaseErrorCode errorCode) { | ||
| super(errorCode); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...umc10th/src/main/java/com/example/umc10th/domain/auth/exception/code/AuthSuccessCode.java
This file contains hidden or 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,19 @@ | ||
| package com.example.umc10th.domain.auth.exception.code; | ||
|
|
||
| import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum AuthSuccessCode implements BaseSuccessCode { | ||
|
|
||
| SIGNUP_OK(HttpStatus.OK, | ||
| "AUTH200_1", | ||
| "회원가입 되었습니다."); | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
49 changes: 49 additions & 0 deletions
49
leeseo/umc10th/src/main/java/com/example/umc10th/domain/auth/service/AuthService.java
This file contains hidden or 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,49 @@ | ||
| package com.example.umc10th.domain.auth.service; | ||
|
|
||
| import com.example.umc10th.domain.auth.converter.AuthConverter; | ||
| import com.example.umc10th.domain.auth.dto.AuthReqDto; | ||
| import com.example.umc10th.domain.auth.dto.AuthResDto; | ||
| import com.example.umc10th.domain.member.converter.MemberConverter; | ||
| import com.example.umc10th.domain.member.entity.Food; | ||
| import com.example.umc10th.domain.member.entity.Member; | ||
| import com.example.umc10th.domain.member.enums.FoodType; | ||
| import com.example.umc10th.domain.member.exception.FoodException; | ||
| import com.example.umc10th.domain.member.exception.MemberException; | ||
| import com.example.umc10th.domain.member.exception.code.FoodErrorCode; | ||
| import com.example.umc10th.domain.member.exception.code.MemberErrorCode; | ||
| import com.example.umc10th.domain.member.repository.FoodRepository; | ||
| import com.example.umc10th.domain.member.repository.MemberRepository; | ||
| import com.example.umc10th.domain.member.service.MemberService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AuthService { | ||
|
|
||
| private final FoodRepository foodRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final MemberRepository memberRepository; | ||
|
|
||
| @Transactional | ||
| public AuthResDto.Id signUp(AuthReqDto.Signup dto) { | ||
| String salt = passwordEncoder.encode(dto.password()); | ||
| Member member = AuthConverter.toMember(dto, salt); | ||
| List<Food> list = new ArrayList<>(); | ||
| if (dto.food() != null) { | ||
| for (FoodType f : dto.food()) { | ||
| Food food = foodRepository.findByName(f) | ||
| .orElseThrow(() -> new FoodException(FoodErrorCode.FOOD_TYPE_NOT_FOUND)); | ||
| list.add(food); | ||
| } | ||
| } | ||
| memberRepository.save(member); | ||
| member.updateFoodList(list); | ||
|
Comment on lines
+45
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재는 memberRepository.save(member) 이후 member.updateFoodList(list)를 호출하고 있는데, 음식 카테고리도 회원가입 과정에서 함께 생성되는 연관 정보이므로 먼저 연관관계를 세팅한 뒤 저장하는 흐름이 더 자연스러울 것 같습니다! |
||
| return AuthResDto.Id.builder().id(member.getId()).build(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
...eo/umc10th/src/main/java/com/example/umc10th/domain/member/converter/MemberConverter.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,33 @@ | ||
| package com.example.umc10th.domain.member.converter; | ||
|
|
||
| import com.example.umc10th.domain.member.dto.MemberResDto; | ||
| import com.example.umc10th.domain.member.entity.Food; | ||
| import com.example.umc10th.domain.member.entity.Member; | ||
| import com.example.umc10th.domain.member.entity.mapping.MemberFood; | ||
|
|
||
| public class MemberConverter { | ||
|
|
||
| public static MemberResDto.Profile toProfile( | ||
| Member member | ||
| ) { | ||
| return MemberResDto.Profile.builder() | ||
| .id(member.getId()) | ||
| .nickname(member.getNickname()) | ||
| .birth(member.getBirth()) | ||
| .address(member.getAddress()) | ||
| .fullAddress(member.getFullAddress()) | ||
| .gender(member.getGender()) | ||
| .food(member.getMemberFoodList().stream().map(MemberFood::getFood).toList()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static MemberFood toMemberFood( | ||
| Food food, | ||
| Member member | ||
| ) { | ||
| return MemberFood.builder() | ||
| .member(member) | ||
| .food(food) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
회원가입 시에 이메일 중복 검사를 추가하면 좋을 것 같습니다~