Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ dependencies {
annotationProcessor "io.github.openfeign.querydsl:querydsl-apt:7.0:jpa"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.13'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.8.13'

// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
}

tasks.named('test') {
Expand Down
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));
}
}
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();
}
}
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
){}
}
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
){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.umc9th.domain.member.enums.Gender;
import com.example.umc9th.domain.member.enums.PhoneVerificationStatus;
import com.example.umc9th.domain.member.enums.SocialType;
import com.example.umc9th.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -19,7 +20,7 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Table(name = "member")
public class Member {
public class Member extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -41,6 +42,9 @@ public class Member {
@Column(name = "address", length = 125, nullable = false)
private String address;

@Column(name = "detail_address", length = 125, nullable = false)
private String detailAddress;


@Column(name = "point", nullable = false)
@Builder.Default
Expand All @@ -63,6 +67,7 @@ public class Member {
private Boolean isActive = true;

@OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE)
@Builder.Default
private List<MemberFood> memberFoodList = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE)
Expand Down
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
}
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼭 도메인별로 나눌 필요 없다는 점 remind!

super(code);
}
}
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);
}
}
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;
}
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;
}
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;
}
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;
}
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> {

}
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> {

}
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);
}
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);
}
}
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 {
}
Loading