-
Notifications
You must be signed in to change notification settings - Fork 0
Feat : Chapter 8. API & Swagger & Annotation #9
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
Merged
Merged
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/umc9th/domain/member/controller/MemberController.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,27 @@ | ||
| package com.example.umc9th.domain.member.controller; | ||
|
|
||
| import com.example.umc9th.domain.member.dto.req.MemberReqDTO; | ||
| import com.example.umc9th.domain.member.dto.res.MemberResDTO; | ||
| import com.example.umc9th.domain.member.exception.code.MemberSuccessCode; | ||
| import com.example.umc9th.domain.member.service.command.MemberCommandService; | ||
| import com.example.umc9th.global.apiPayload.ApiResponse; | ||
| 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.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class MemberController { | ||
|
|
||
| private final MemberCommandService memberCommandService; | ||
|
|
||
| // 회원가입 | ||
| @PostMapping("/sign-up") | ||
| public ApiResponse<MemberResDTO.JoinDTO> signUp( | ||
| @RequestBody @Valid MemberReqDTO.JoinDTO dto | ||
| ){ | ||
| return ApiResponse.onSuccess(MemberSuccessCode.FOUND, memberCommandService.signup(dto)); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/umc9th/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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.umc9th.domain.member.converter; | ||
|
|
||
| import com.example.umc9th.domain.member.dto.req.MemberReqDTO; | ||
| import com.example.umc9th.domain.member.dto.res.MemberResDTO; | ||
| import com.example.umc9th.domain.member.entity.Member; | ||
|
|
||
| public class MemberConverter { | ||
|
|
||
| // Entity -> DTO | ||
| public static MemberResDTO.JoinDTO toJoinDTO( | ||
| Member member | ||
| ){ | ||
| return MemberResDTO.JoinDTO.builder() | ||
| .memberId(member.getId()) | ||
| .createAt(member.getCreatedAt()) | ||
| .build(); | ||
| } | ||
|
|
||
| // DTO -> Entity | ||
| public static Member toMember( | ||
| MemberReqDTO.JoinDTO dto | ||
| ){ | ||
| return Member.builder() | ||
| .name(dto.name()) | ||
| .birth(dto.birth()) | ||
| .address(dto.address()) | ||
| .detailAddress(dto.specAddress()) | ||
| .gender(dto.gender()) | ||
| .build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/umc9th/domain/member/dto/req/MemberReqDTO.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,26 @@ | ||
| package com.example.umc9th.domain.member.dto.req; | ||
|
|
||
| import com.example.umc9th.domain.member.enums.Gender; | ||
| import com.example.umc9th.global.annotation.ExistFoods; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| public class MemberReqDTO { | ||
| public record JoinDTO( | ||
| @NotBlank | ||
| String name, | ||
| @NotNull | ||
| Gender gender, | ||
| @NotNull | ||
| LocalDate birth, | ||
| @NotNull | ||
| String address, | ||
| @NotNull | ||
| String specAddress, | ||
| @ExistFoods | ||
| List<Long> preferCategory | ||
| ){} | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/umc9th/domain/member/dto/res/MemberResDTO.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.umc9th.domain.member.dto.res; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class MemberResDTO { | ||
| @Builder | ||
| public record JoinDTO( | ||
| Long memberId, | ||
| LocalDateTime createAt | ||
| ){} | ||
| } |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/umc9th/domain/member/enums/SocialType.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,5 +1,5 @@ | ||
| package com.example.umc9th.domain.member.enums; | ||
|
|
||
| public enum SocialType { | ||
| KAKAO, NAVER, APPLE, GOOGLE | ||
| KAKAO, NAVER, APPLE, GOOGLE, LOCAL | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/umc9th/domain/member/exception/FoodException.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.umc9th.domain.member.exception; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import com.example.umc9th.global.apiPayload.exception.GeneralException; | ||
|
|
||
| public class FoodException extends GeneralException { | ||
| public FoodException(BaseErrorCode code) { | ||
| super(code); | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/umc9th/domain/member/exception/MemberException.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.umc9th.domain.member.exception; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import com.example.umc9th.global.apiPayload.exception.GeneralException; | ||
|
|
||
| public class MemberException extends GeneralException { | ||
| public MemberException(BaseErrorCode code) { | ||
| super(code); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/umc9th/domain/member/exception/code/FoodErrorCode.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,20 @@ | ||
| package com.example.umc9th.domain.member.exception.code; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum FoodErrorCode implements BaseErrorCode { | ||
|
|
||
| NOT_FOUND(HttpStatus.NOT_FOUND, | ||
| "FOOD404_1", | ||
| "해당 음식을 찾지 못했습니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/umc9th/domain/member/exception/code/FoodSuccessCode.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,20 @@ | ||
| package com.example.umc9th.domain.member.exception.code; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum FoodSuccessCode implements BaseErrorCode { | ||
|
|
||
| FOUND(HttpStatus.OK, | ||
| "FOOD200_1", | ||
| "성공적으로 음식을 조회했습니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/umc9th/domain/member/exception/code/MemberErrorCode.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,20 @@ | ||
| package com.example.umc9th.domain.member.exception.code; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum MemberErrorCode implements BaseErrorCode { | ||
|
|
||
| NOT_FOUND(HttpStatus.NOT_FOUND, | ||
| "MEMBER404_1", | ||
| "해당 사용자를 찾지 못했습니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/umc9th/domain/member/exception/code/MemberSuccessCode.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,20 @@ | ||
| package com.example.umc9th.domain.member.exception.code; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum MemberSuccessCode implements BaseSuccessCode { | ||
|
|
||
| FOUND(HttpStatus.OK, | ||
| "MEMBER200_1", | ||
| "성공적으로 사용자를 조회했습니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/umc9th/domain/member/repository/FoodRepository.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,11 @@ | ||
| package com.example.umc9th.domain.member.repository; | ||
|
|
||
| import com.example.umc9th.domain.member.entity.Food; | ||
| import com.example.umc9th.domain.member.entity.Member; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface FoodRepository extends JpaRepository<Food,Long> { | ||
|
|
||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/umc9th/domain/member/repository/MemberFoodRepository.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,11 @@ | ||
| package com.example.umc9th.domain.member.repository; | ||
|
|
||
| import com.example.umc9th.domain.member.entity.Member; | ||
| import com.example.umc9th.domain.member.entity.mapping.MemberFood; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface MemberFoodRepository extends JpaRepository<MemberFood,Long> { | ||
|
|
||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandService.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,9 @@ | ||
| package com.example.umc9th.domain.member.service.command; | ||
|
|
||
| import com.example.umc9th.domain.member.dto.req.MemberReqDTO; | ||
| import com.example.umc9th.domain.member.dto.res.MemberResDTO; | ||
|
|
||
| public interface MemberCommandService { | ||
| // 회원가입 | ||
| MemberResDTO.JoinDTO signup(MemberReqDTO.JoinDTO dto); | ||
| } |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandServiceImpl.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,70 @@ | ||
| package com.example.umc9th.domain.member.service.command; | ||
|
|
||
| import com.example.umc9th.domain.member.converter.MemberConverter; | ||
| import com.example.umc9th.domain.member.dto.req.MemberReqDTO; | ||
| import com.example.umc9th.domain.member.dto.res.MemberResDTO; | ||
| import com.example.umc9th.domain.member.entity.Food; | ||
| import com.example.umc9th.domain.member.entity.Member; | ||
| import com.example.umc9th.domain.member.entity.mapping.MemberFood; | ||
| import com.example.umc9th.domain.member.exception.FoodException; | ||
| import com.example.umc9th.domain.member.exception.code.FoodErrorCode; | ||
| import com.example.umc9th.domain.member.repository.FoodRepository; | ||
| import com.example.umc9th.domain.member.repository.MemberFoodRepository; | ||
| import com.example.umc9th.domain.member.repository.MemberRepository; | ||
| import jakarta.transaction.Transactional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MemberCommandServiceImpl implements MemberCommandService{ | ||
|
|
||
| private final MemberRepository memberRepository; | ||
| private final MemberFoodRepository memberFoodRepository; | ||
| private final FoodRepository foodRepository; | ||
|
|
||
| // 회원가입 | ||
| @Override | ||
| @Transactional | ||
| public MemberResDTO.JoinDTO signup( | ||
| MemberReqDTO.JoinDTO dto | ||
| ){ | ||
| // 사용자 생성 | ||
| Member member = MemberConverter.toMember(dto); | ||
| // DB 적용 | ||
| memberRepository.save(member); | ||
|
|
||
| // 선호 음식 존재 여부 확인 | ||
| if (dto.preferCategory().size() > 1){ | ||
| List<MemberFood> memberFoodList = new ArrayList<>(); | ||
|
|
||
| // 선호 음식 ID별 조회 | ||
| for (Long id : dto.preferCategory()){ | ||
|
|
||
| // 음식 존재 여부 검증 | ||
| Food food = foodRepository.findById(id) | ||
| .orElseThrow(() -> new FoodException(FoodErrorCode.NOT_FOUND)); | ||
|
|
||
| // MemberFood 엔티티 생성 (컨버터 사용해야 함) | ||
| MemberFood memberFood = MemberFood.builder() | ||
| .member(member) | ||
| .food(food) | ||
| .build(); | ||
|
|
||
| // 사용자 - 음식 (선호 음식) 추가 | ||
| memberFoodList.add(memberFood); | ||
| } | ||
|
|
||
| // 모든 선호 음식 추가: DB 적용 | ||
| memberFoodRepository.saveAll(memberFoodList); | ||
| } | ||
|
|
||
|
|
||
| // 응답 DTO 생성 | ||
| return MemberConverter.toJoinDTO(member); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/example/umc9th/domain/member/service/query/MemberQuerySercvice.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,4 @@ | ||
| package com.example.umc9th.domain.member.service.query; | ||
|
|
||
| public interface MemberQuerySercvice { | ||
| } |
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.
꼭 도메인별로 나눌 필요 없다는 점 remind!