Skip to content

Commit 83224ce

Browse files
authored
Merge pull request #51 from UMCWegg/feature/#8
Feature/#8
2 parents 7fa0026 + 07fa23e commit 83224ce

File tree

10 files changed

+174
-71
lines changed

10 files changed

+174
-71
lines changed

src/main/java/umc/wegg/WeggApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@EnableJpaAuditing
88
@SpringBootApplication
9+
@EnableJpaAuditing
910
public class WeggApplication {
1011

1112
public static void main(String[] args) {

src/main/java/umc/wegg/converter/UserConverter.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package umc.wegg.converter;
22

33
import lombok.RequiredArgsConstructor;
4+
import umc.wegg.domain.ContactFriend;
45
import umc.wegg.domain.Setting;
56
import umc.wegg.domain.User;
67
import umc.wegg.domain.enums.AccountVisibility;
@@ -9,7 +10,9 @@
910
import umc.wegg.dto.UserResponseDTO;
1011

1112
import java.time.LocalDateTime;
13+
import java.util.ArrayList;
1214
import java.util.List;
15+
import java.util.stream.Collectors;
1316

1417
@RequiredArgsConstructor
1518
public class UserConverter {
@@ -21,25 +24,25 @@ public static UserResponseDTO.UserJoinResultDTO toJoinResultDTO(User user){
2124
.build();
2225
}
2326

24-
public static UserResponseDTO.UserJoinResultDTO toJoinResultDTO(User user, List<UserResponseDTO.UserJoinResultDTO.ExistingUserDTO> existingUsers){
27+
public static UserResponseDTO.UserJoinResultDTO toJoinResultDTO(User user, List<UserResponseDTO.UserJoinResultDTO.ContactFriendDto> contactFriends){
2528
return UserResponseDTO.UserJoinResultDTO.builder()
2629
.userId(user.getId())
2730
.createdAt(LocalDateTime.now())
2831
//연락처에 있는 유저 목록 추가
29-
.existingUsers(existingUsers)
32+
.contactFriends(contactFriends)
3033
.build();
3134
}
3235

33-
public static UserResponseDTO.OAuth2UserJoinResultDTO toOAuth2JoinResultDTO(User user, List<UserResponseDTO.OAuth2UserJoinResultDTO.ExistingUserDTO> existingUsers){
36+
public static UserResponseDTO.OAuth2UserJoinResultDTO toOAuth2JoinResultDTO(User user, List<UserResponseDTO.OAuth2UserJoinResultDTO.ContactFriendDto> contactFriends){
3437
return UserResponseDTO.OAuth2UserJoinResultDTO.builder()
3538
.userId(user.getId())
3639
.createdAt(LocalDateTime.now())
3740
//연락처에 있는 유저 목록 추가
38-
.existingUsers(existingUsers)
41+
.contactFriends(contactFriends)
3942
.build();
4043
}
4144

42-
public static User toUser(UserRequestDTO.UserJoinDto request){
45+
public static User toUser(UserRequestDTO.UserJoinDto request, List<UserResponseDTO.ContactFriendDTO> contactFriends){
4346

4447
User user = User.builder()
4548
.email(request.getEmail())
@@ -76,10 +79,24 @@ public static User toUser(UserRequestDTO.UserJoinDto request){
7679
// 관계 설정
7780
user.setSetting(setting);
7881

82+
// ContactFriends 초기화
83+
if (contactFriends != null && !contactFriends.isEmpty()) {
84+
List<ContactFriend> contactFriendList = contactFriends.stream()
85+
.map(contactFriend -> ContactFriend.builder()
86+
.user(user)
87+
.friend(contactFriend.getFriend())
88+
.phoneNum(contactFriend.getPhone()) // 기존 사용자의 전화번호 추가
89+
.isFollowing(false)
90+
.build())
91+
.collect(Collectors.toList());
92+
93+
user.setContactFriendList(contactFriendList);
94+
}
95+
7996
return user;
8097
}
8198

82-
public static User toOAuthUser(UserRequestDTO.OAuth2UserJoinDto request){
99+
public static User toOAuthUser(UserRequestDTO.OAuth2UserJoinDto request, List<UserResponseDTO.ContactFriendDTO> contactFriends){
83100

84101
User user = User.builder()
85102
.accountId(request.getAccountId())
@@ -118,6 +135,20 @@ public static User toOAuthUser(UserRequestDTO.OAuth2UserJoinDto request){
118135
// 관계 설정
119136
user.setSetting(setting);
120137

138+
// ContactFriends 초기화
139+
if (contactFriends != null && !contactFriends.isEmpty()) {
140+
List<ContactFriend> contactFriendList = contactFriends.stream()
141+
.map(contactFriend -> ContactFriend.builder()
142+
.user(user)
143+
.friend(contactFriend.getFriend())
144+
.phoneNum(contactFriend.getPhone()) // 기존 사용자의 전화번호 추가
145+
.isFollowing(false)
146+
.build())
147+
.collect(Collectors.toList());
148+
149+
user.setContactFriendList(contactFriendList);
150+
}
151+
121152
return user;
122153
}
123154

src/main/java/umc/wegg/domain/ContactFriend.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
@Builder
99
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1010
@AllArgsConstructor
11-
@Table(name = "contact_friends")
11+
//user_id와 phone_num 조합이 유일하도록 UNIQUE 제약 조건 추가
12+
@Table(name = "contact_friends", uniqueConstraints = {
13+
@UniqueConstraint(columnNames = {"user_id", "phone_num"})
14+
})
1215
public class ContactFriend {
1316

1417
@Id
@@ -19,7 +22,14 @@ public class ContactFriend {
1922
@JoinColumn(name = "user_id", nullable = false) // 외래 키 매핑
2023
private User user;
2124

25+
@ManyToOne(fetch = FetchType.LAZY) // User와 다대일 관계
26+
@JoinColumn(name = "friend_id", nullable = false) // 외래 키 매핑
27+
private User friend;
28+
2229
@Column(name = "phone_num", nullable = false, length = 255)
2330
private String phoneNum;
31+
32+
@Column(name = "is_following", nullable = false, length = 255)
33+
private Boolean isFollowing;
2434
}
2535

src/main/java/umc/wegg/domain/User.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hibernate.annotations.DynamicUpdate;
88
import umc.wegg.domain.common.BaseEntity;
99
import umc.wegg.domain.enums.Job;
10+
import umc.wegg.domain.enums.ReasonType;
1011
import umc.wegg.domain.mapping.Emoji;
1112
import umc.wegg.domain.mapping.Follow;
1213
import umc.wegg.domain.mapping.MyTemplate;
@@ -52,6 +53,11 @@ public class User extends BaseEntity {
5253
@Column(nullable = false)
5354
private int successCount = 0; // 연속 인증 성공 횟수
5455

56+
@ColumnDefault("0")
57+
@Builder.Default
58+
@Column(nullable = false)
59+
private int successPoint = 0; // 받을 수 있는 포인트
60+
5561
@Column(nullable = true)
5662
private Float currentLat; // 현재 위치 위도
5763
@Column(nullable = true)
@@ -60,7 +66,8 @@ public class User extends BaseEntity {
6066
@Enumerated(EnumType.STRING)
6167
private Job job; // 사용자 신분
6268

63-
private String reason; // 이 앱을 시작한 이유
69+
@Enumerated(EnumType.STRING)
70+
private ReasonType reason; // 이 앱을 시작한 이유
6471

6572
@Column(nullable = false, length = 100)
6673
private String phone; // 사용자 전화번호
@@ -97,6 +104,12 @@ public class User extends BaseEntity {
97104
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
98105
private List<MyTemplate> myTemplateList = new ArrayList<>();
99106

107+
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
108+
private List<ContactFriend> contactUserList = new ArrayList<>();
109+
110+
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
111+
private List<ContactFriend> contactFriendList = new ArrayList<>();
112+
100113
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
101114
private Setting setting;
102115

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package umc.wegg.domain.enums;
2+
3+
public enum ReasonType {
4+
5+
HABIT_FORMATION("공부 습관을 형성하기 위해서"),
6+
FOLLOW_FRIENDS("친구들을 따라서"),
7+
STUDY_RECORD("공부를 기록하기 위해서"),
8+
FIND_GOOD_PLACE("주변의 공부하기 좋은 장소를 찾기 위해서"),
9+
CUSTOM_INPUT("직접 입력하기");
10+
11+
private final String description;
12+
13+
ReasonType(String description) {
14+
this.description = description;
15+
}
16+
17+
public String getDescription() {
18+
return description;
19+
}
20+
}

src/main/java/umc/wegg/dto/UserRequestDTO.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package umc.wegg.dto;
22

3+
import jakarta.validation.Valid;
34
import jakarta.validation.constraints.*;
45
import lombok.*;
56
import umc.wegg.domain.enums.Job;
7+
import umc.wegg.domain.enums.ReasonType;
68
import umc.wegg.domain.enums.VerificationType;
79

810
import java.util.List;
@@ -20,6 +22,7 @@ public static class UserJoinDto{
2022
private String email; // 사용자 이메일
2123

2224
@NotBlank(message = "비밀번호는 필수 항목입니다.")
25+
@Size(min = 6, message = "비밀번호는 최소 6자 이상이어야 합니다.")
2326
private String password; // 비밀번호
2427

2528
@NotNull
@@ -35,7 +38,7 @@ public static class UserJoinDto{
3538

3639
private Job job; // 사용자 신분
3740

38-
private String reason; // 이 앱을 시작한 이유
41+
private ReasonType reason; // 이 앱을 시작한 이유
3942

4043
@Pattern(regexp = "\\d{3}\\d{4}\\d{4}", message = "전화번호 형식이 맞아야 합니다.")
4144
@NotBlank(message = "전화번호는 필수 항목입니다.")
@@ -46,6 +49,7 @@ public static class UserJoinDto{
4649

4750
// 연락처 리스트
4851
@Size(max = 10, message = "최대 10개의 연락처를 제공할 수 있습니다.")
52+
@Valid
4953
private List<ContactDto> contact; // 연락처 정보 리스트
5054
}
5155

@@ -72,7 +76,7 @@ public static class OAuth2UserJoinDto{
7276

7377
private Job job; // 사용자 신분
7478

75-
private String reason; // 이 앱을 시작한 이유
79+
private ReasonType reason; // 이 앱을 시작한 이유
7680

7781
@Pattern(regexp = "\\d{3}\\d{4}\\d{4}", message = "전화번호 형식이 맞아야 합니다.")
7882
@NotBlank(message = "전화번호는 필수 항목입니다.")
@@ -94,8 +98,8 @@ public static class OAuth2UserJoinDto{
9498
@NoArgsConstructor
9599
@AllArgsConstructor
96100
public static class ContactDto {
97-
private String contactName;
98101
@Pattern(regexp = "\\d{3}\\d{4}\\d{4}", message = "전화번호 형식이 맞아야 합니다.")
102+
@NotBlank
99103
private String phone; // 연락처 전화번호
100104
}
101105

src/main/java/umc/wegg/dto/UserResponseDTO.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package umc.wegg.dto;
22

33
import lombok.*;
4+
import umc.wegg.domain.User;
45

56
import java.time.LocalDateTime;
67
import java.util.List;
@@ -15,14 +16,16 @@ public class UserResponseDTO {
1516
public static class UserJoinResultDTO{
1617
Long userId;
1718
LocalDateTime createdAt;
18-
List<ExistingUserDTO> existingUsers;
19+
List<ContactFriendDto> contactFriends;
1920

2021
//연락처에 있는 user
2122
@Getter
2223
@AllArgsConstructor
23-
public static class ExistingUserDTO {
24-
private String contactName;
24+
public static class ContactFriendDto {
25+
private Long friendId;
26+
private String accountId;
2527
private String name;
28+
private String profileImage;
2629
private String phone;
2730
}
2831
}
@@ -34,18 +37,30 @@ public static class ExistingUserDTO {
3437
public static class OAuth2UserJoinResultDTO{
3538
Long userId;
3639
LocalDateTime createdAt;
37-
List<ExistingUserDTO> existingUsers;
40+
List<ContactFriendDto> contactFriends;
3841

3942
//연락처에 있는 user
4043
@Getter
4144
@AllArgsConstructor
42-
public static class ExistingUserDTO {
43-
private String contactName;
45+
public static class ContactFriendDto {
46+
private Long friendId;
47+
private String accountId;
4448
private String name;
49+
private String profileImage;
4550
private String phone;
4651
}
4752
}
4853

54+
@Getter
55+
@AllArgsConstructor
56+
public static class ContactFriendDTO {
57+
private User friend;
58+
private String accountId;
59+
private String name;
60+
private String profileImage;
61+
private String phone;
62+
}
63+
4964
@Getter
5065
@Builder
5166
@NoArgsConstructor

src/main/java/umc/wegg/service/MailService/MailServiceImpl.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import umc.wegg.util.EmailUtil;
1010
import umc.wegg.util.RedisUtil;
1111

12-
import java.util.Random;
13-
1412
@Service
1513
@RequiredArgsConstructor
1614
public class MailServiceImpl implements MailService {
@@ -22,7 +20,8 @@ public class MailServiceImpl implements MailService {
2220

2321
@Override
2422
public UserResponseDTO.VerificationResultDTO sendMail(UserRequestDTO.SendEmailVerificationDto request) {
25-
String number = createNumber(); // 랜덤 인증번호 생성
23+
// 인증번호 생성 (6자리)
24+
String number = String.format("%06d", (int) (Math.random() * 1000000));
2625
String sendEmail = request.getEmail();
2726
String subject = "이메일 인증";
2827
String body = "요청하신 인증 번호입니다.<p><h3>" + number + "</h3>";
@@ -42,20 +41,4 @@ public UserResponseDTO.VerificationResultDTO sendMail(UserRequestDTO.SendEmailVe
4241

4342
return new UserResponseDTO.VerificationResultDTO("인증번호가 전송되었습니다.");
4443
}
45-
46-
private String createNumber() {
47-
Random random = new Random();
48-
StringBuilder key = new StringBuilder();
49-
50-
for (int i = 0; i < 8; i++) { // 인증 코드 8자리
51-
int index = random.nextInt(3);
52-
53-
switch (index) {
54-
case 0 -> key.append((char) (random.nextInt(26) + 97)); // 소문자
55-
case 1 -> key.append((char) (random.nextInt(26) + 65)); // 대문자
56-
case 2 -> key.append(random.nextInt(10)); // 숫자
57-
}
58-
}
59-
return key.toString();
60-
}
6144
}

src/main/java/umc/wegg/service/SmsService/SmsServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public String sendSms(UserRequestDTO.SendPhoneVerificationDto request) {
2626
redisUtil.deleteData(phone);
2727
}
2828

29-
// 인증번호 생성
30-
String number = Integer.toString((int) (Math.random() * 900000) + 100000);
29+
// 인증번호 생성 (6자리)
30+
String number = String.format("%06d", (int) (Math.random() * 1000000));
3131
// SMS 전송
3232
smsCertificationUtil.sendSMS(phone, number);
3333

0 commit comments

Comments
 (0)