11package com .example .gimmegonghakauth .user .service ;
22
3- import com .example .gimmegonghakauth .completed .infrastructure .CompletedCoursesDao ;
4- import com .example .gimmegonghakauth .user .infrastructure .UserRepository ;
5- import com .example .gimmegonghakauth .completed .domain .CompletedCoursesDomain ;
63import com .example .gimmegonghakauth .common .domain .MajorsDomain ;
4+ import com .example .gimmegonghakauth .completed .domain .CompletedCoursesDomain ;
5+ import com .example .gimmegonghakauth .completed .infrastructure .CompletedCoursesDao ;
76import com .example .gimmegonghakauth .user .domain .UserDomain ;
7+ import com .example .gimmegonghakauth .user .infrastructure .UserRepository ;
88import com .example .gimmegonghakauth .user .service .dto .ChangePasswordDto ;
99import com .example .gimmegonghakauth .user .service .dto .UserJoinDto ;
1010import com .example .gimmegonghakauth .user .service .exception .UserNotFoundException ;
1111import com .example .gimmegonghakauth .user .service .port .UserEncoder ;
12+ import java .time .LocalDate ;
1213import java .util .List ;
1314import lombok .RequiredArgsConstructor ;
15+ import lombok .extern .slf4j .Slf4j ;
1416import org .springframework .security .core .userdetails .UsernameNotFoundException ;
1517import org .springframework .stereotype .Service ;
1618import org .springframework .transaction .annotation .Transactional ;
1921@ Transactional
2022@ Service
2123@ RequiredArgsConstructor
24+ @ Slf4j
2225public class UserService {
2326
2427 private final UserRepository userRepository ;
2528 private final CompletedCoursesDao completedCoursesDao ;
2629 private final UserEncoder userEncoder ;
2730
28- public UserDomain create (String _studentId , String password , String email ,
29- MajorsDomain majorsDomain , String name ) {
31+ public UserDomain create (String _studentId , String password , String email , MajorsDomain majorsDomain , String name ) {
3032 Long studentId = Long .parseLong (_studentId );
3133 UserDomain user = UserDomain .builder ()
32- .studentId (studentId ).password (userEncoder .encode (password ))
33- .email (email ).majorsDomain (majorsDomain ).name (name )
34- .build ();
34+ .studentId (studentId ).password (userEncoder .encode (password ))
35+ .email (email ).majorsDomain (majorsDomain ).name (name )
36+ .build ();
3537 userRepository .save (user );
38+
39+ log .info ("{} {}학번 {} {}님이 가입하셨습니다." ,
40+ LocalDate .now (), studentId / 1000000 , majorsDomain .getMajor (), user .getName ());
41+
3642 return user ;
3743 }
3844
@@ -44,7 +50,7 @@ public UserDomain updatePassword(UserDomain user, String newPassword) {
4450
4551 public UserDomain getByStudentId (Long studentId ) {
4652 return userRepository .findByStudentId (studentId )
47- .orElseThrow (() -> new UserNotFoundException (studentId ));
53+ .orElseThrow (() -> new UserNotFoundException (studentId ));
4854 }
4955
5056 public boolean joinValidation (UserJoinDto userJoinDto , BindingResult bindingResult ) {
@@ -82,7 +88,7 @@ public boolean withdrawal(String _studentId, String password) {
8288 Long studentId = Long .parseLong (_studentId );
8389
8490 UserDomain user = userRepository .findByStudentId (studentId )
85- .orElseThrow (() -> new UsernameNotFoundException ("학번이 존재하지 않습니다." ));
91+ .orElseThrow (() -> new UsernameNotFoundException ("학번이 존재하지 않습니다." ));
8692
8793 if (userEncoder .matches (password , user .getPassword ())) {
8894 List <CompletedCoursesDomain > coursesList = completedCoursesDao .findByUserDomain (user );
@@ -98,24 +104,24 @@ public boolean withdrawal(String _studentId, String password) {
98104 }
99105
100106 public boolean changePasswordValidation (ChangePasswordDto changePasswordDto ,
101- BindingResult bindingResult , UserDomain user ) {
107+ BindingResult bindingResult , UserDomain user ) {
102108 String password = user .getPassword ();
103109 String inputPassword = changePasswordDto .getCurrentPassword ();
104110 if (!userEncoder .matches (inputPassword , password )) { //입력한 패스워드가 현재 패스워드와 일치하지 않을 경우
105111 bindingResult .rejectValue ("currentPassword" , "currentPasswordInCorrect" ,
106- "현재 패스워드가 일치하지 않습니다." );
112+ "현재 패스워드가 일치하지 않습니다." );
107113 return false ;
108114 }
109115 if (userEncoder .matches (changePasswordDto .getNewPassword1 (),
110- password )) { //입력한 새 패스워드가 현재 패스워드와 일치하는 경우
116+ password )) { //입력한 새 패스워드가 현재 패스워드와 일치하는 경우
111117 bindingResult .rejectValue ("newPassword1" , "sameCurrentPassword" ,
112- "현재 패스워드와 다른 패스워드를 입력해주세요." );
118+ "현재 패스워드와 다른 패스워드를 입력해주세요." );
113119 return false ;
114120 }
115121 if (!changePasswordDto .getNewPassword1 ()
116- .equals (changePasswordDto .getNewPassword2 ())) {//새 패스워드 2개의 입력이 일치하지 않는 경우
122+ .equals (changePasswordDto .getNewPassword2 ())) {//새 패스워드 2개의 입력이 일치하지 않는 경우
117123 bindingResult .rejectValue ("newPassword2" , "newPasswordInCorrect" ,
118- "입력한 패스워드가 일치하지 않습니다." );
124+ "입력한 패스워드가 일치하지 않습니다." );
119125 return false ;
120126 }
121127 return true ;
0 commit comments