Skip to content

Commit

Permalink
Merge branch 'master' into feature/#2
Browse files Browse the repository at this point in the history
  • Loading branch information
ahtop00 authored Nov 21, 2024
2 parents c314f8f + 52f4f59 commit 33b7faf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
6 changes: 4 additions & 2 deletions src/main/java/javalab/umc7th_mission/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public class Member extends BaseEntity {
@ColumnDefault("0")
private Integer point;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<MemberAddress> addressList = new ArrayList<>();
//24.11.21 fix/#7
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "address_id")
private MemberAddress address;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<MemberAgree> memberAgreeList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class MemberAddress extends BaseEntity {
@JoinColumn(name = "region_id", referencedColumnName = "id")
private Region region;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", referencedColumnName = "id")
//24.11.21 fix/#7
@OneToOne(mappedBy = "address",fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Member member;

@Column(nullable = false, length = 100)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package javalab.umc7th_mission.repository.MemberPreferRepository;

import javalab.umc7th_mission.domain.mapping.MemberPrefer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface MemberPreferRepository extends JpaRepository<MemberPrefer, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import jakarta.transaction.Transactional;
import javalab.umc7th_mission.apiPayload.code.status.ErrorStatus;
import javalab.umc7th_mission.apiPayload.exception.FoodCategoryNotFoundException;
import javalab.umc7th_mission.apiPayload.exception.RegionNotFoundException;
import javalab.umc7th_mission.converter.MemberConverter;
import javalab.umc7th_mission.converter.MemberPreferConverter;
import javalab.umc7th_mission.domain.FoodCategory;
import javalab.umc7th_mission.domain.Member;
import javalab.umc7th_mission.domain.Region;
import javalab.umc7th_mission.domain.enums.Gender;
import javalab.umc7th_mission.domain.mapping.MemberAddress;
import javalab.umc7th_mission.domain.mapping.MemberPrefer;
import javalab.umc7th_mission.repository.FoodCategoryRepository.FoodCategoryRepository;
Expand Down Expand Up @@ -36,15 +36,13 @@ public class MemberCommandServiceImpl implements MemberCommandService {
@Override
@Transactional //트렌잭션 어노테이션
public Member joinMember(MemberRequestDTO.JoinDto request) {
//후에 지역을 다 추가하고 해당 지역이 있는지 확인 api필요해보임
Region region = regionRepository.findByName(request.getRegion());
if (region == null) {
throw new RegionNotFoundException(ErrorStatus.REGION_NOT_FOUND);
}

//member 생성 및 저장
Member newMember = MemberConverter.toMember(request);

if (newMember.getAddressList() == null) {
newMember.setAddressList(new ArrayList<>());
}
//foodCategory list 조회
List<FoodCategory> foodCategoryList = request.getPreferCategory().stream()
.map(category -> {
Expand All @@ -56,10 +54,13 @@ public Member joinMember(MemberRequestDTO.JoinDto request) {
memberPreferList.forEach(memberPrefer -> {memberPrefer.setMember(newMember);});
newMember.setMemberPreferList(memberPreferList);

//24.11.21 fix/#7
//memberAddress 생성 및 연결
MemberAddress memberAddress = MemberConverter.toMemberAddress(newMember, region, request);


memberAddress.setMember(newMember);
newMember.getAddressList().add(memberAddress);
newMember.setAddress(memberAddress);

memberAddressRepository.save(memberAddress);

Expand Down
31 changes: 14 additions & 17 deletions src/main/java/javalab/umc7th_mission/web/dto/MemberRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,31 @@ public static class JoinDto {
@Size(max = 50, message = "이메일은 최대 50자까지 가능합니다.")
private final String email;

//어노테이션 추가 필요 지역 관련 이슈
//24.11.21 fix/#7
@NotBlank(message = "지역명은 필수 항목입니다.")
@Size(max = 50, message = "지역명은 최대 50자까지 가능합니다.")
private final String region;

@NotBlank(message = "세부 주소는 필수 항목입니다.")
@Size(max = 100, message = "세부 주소는 최대 100자까지 가능합니다.")
private final String detailedAddress;

@NotBlank(message = "우편번호는 필수 항목입니다.")
@Size(max = 40, message = "우편번호는 최대 40자까지 가능합니다.")
private final String zipcode;

List<Long> preferCategory;

/*
24.11.21 fix/#7 -> remove @
유효성 검증은 객체 생성 이후에 처리되도록 설계 -> 생성자에서 어노테이션을 적용할 이유 없음
*/
public JoinDto(
@NotBlank(message = "이름은 필수 항목입니다.")
@Size(max = 20, message = "이름은 최대 20자까지 가능합니다.")
String name,

@NotBlank(message = "닉네임은 필수 항목입니다.")
@Size(max = 20, message = "닉네임은 최대 20자까지 가능합니다.")
String nickname,

@NotBlank(message = "전화번호는 필수 항목입니다.")
//전화번호 형식 검증 정규식
@Pattern(regexp = "^(02|0\\d{2})-\\d{3,4}-\\d{4}$", message = "전화번호 형식이 올바르지 않습니다.")
String phoneNumber,

@NotNull(message = "성별은 필수 항목입니다.")
Gender gender,

@NotBlank(message = "이메일은 필수 항목입니다.")
@Email(message = "이메일 형식이 올바르지 않습니다.")
@Size(max = 50, message = "이메일은 최대 50자까지 가능합니다.")
String email,

String region,
String detailedAddress,
String zipcode,
Expand Down

0 comments on commit 33b7faf

Please sign in to comment.