diff --git a/src/main/java/com/example/demo/app/domain/service/UserService.java b/src/main/java/com/example/demo/app/domain/service/UserService.java new file mode 100644 index 0000000..4a7a338 --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/UserService.java @@ -0,0 +1,8 @@ +package com.example.demo.app.domain.service; + +import com.example.demo.app.presentation.form.UserForm; + +public interface UserService { + + void register(UserForm userForm); +} diff --git a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..a74f42b --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java @@ -0,0 +1,58 @@ +package com.example.demo.app.domain.service.impl; + +import org.springframework.stereotype.Service; + +import com.example.demo.app.domain.service.UserService; +import com.example.demo.app.infra.entity.CourseEntity; +import com.example.demo.app.infra.entity.GoalEntity; +import com.example.demo.app.infra.entity.QuestionEntity; +import com.example.demo.app.infra.entity.UserEntity; +import com.example.demo.app.infra.repository.CourseRepository; +import com.example.demo.app.infra.repository.GoalRepository; +import com.example.demo.app.infra.repository.QuestionRepository; +import com.example.demo.app.infra.repository.UserRepository; +import com.example.demo.app.presentation.form.UserForm; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + private final QuestionRepository questionRepository; + private final GoalRepository goalRepository; + private final CourseRepository courseRepository; + + @Override + public void register(UserForm userForm) { + + UserEntity userEntity = new UserEntity(); + + userEntity.setUserName(userForm.getUserName()); + userEntity.setMailAddress(userForm.getMailAddress()); + userEntity.setPassword(userForm.getPassword()); + userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer()); + userEntity.setBirthDate(userForm.getBirthDate()); + userEntity.setSaving(userForm.getSaving()); + userEntity.setAnnualIncome(userForm.getAnnualIncome()); + userEntity.setMonthlyBudget(userForm.getMonthlyBudget()); + + QuestionEntity questionEntity = + questionRepository.findById(userForm.getSecretQuestionId()).orElse(null); + + GoalEntity goalEntity = + goalRepository.findById(userForm.getGoalId()).orElse(null); + + CourseEntity courseEntity = + courseRepository.findById(userForm.getCourseId()).orElse(null); + + userEntity.setQuestionEntity(questionEntity); + userEntity.setGoalEntity(goalEntity); + userEntity.setCourseEntity(courseEntity); + + userEntity.setDeleteFlag(0); + + userRepository.save(userEntity); + } +} diff --git a/src/main/java/com/example/demo/app/infra/entity/QuestionEntity.java b/src/main/java/com/example/demo/app/infra/entity/QuestionEntity.java index 6b94b7f..a028437 100644 --- a/src/main/java/com/example/demo/app/infra/entity/QuestionEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/QuestionEntity.java @@ -24,7 +24,7 @@ public class QuestionEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "secret_question_id") - private Integer secretQuestionId; + private Long secretQuestionId; @Column(name = "question_text", nullable = false) private String questionText; diff --git a/src/main/java/com/example/demo/app/presentation/controller/UserController.java b/src/main/java/com/example/demo/app/presentation/controller/UserController.java new file mode 100644 index 0000000..2914032 --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/controller/UserController.java @@ -0,0 +1,35 @@ +package com.example.demo.app.presentation.controller; + +import jakarta.servlet.http.HttpSession; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; + +import com.example.demo.app.presentation.form.UserForm; + +import lombok.RequiredArgsConstructor; + +@Controller +@RequiredArgsConstructor +public class UserController { + + @GetMapping("/user/register") + public String showRegister(Model model) { + model.addAttribute("userForm", new UserForm()); + return "user_register"; + } + + @PostMapping("/user/register/confirm") + public String confirmRegister( + @ModelAttribute UserForm userForm, + HttpSession session) { + + session.setAttribute("userForm", userForm); + + return "user_register_confirm"; + } + +} diff --git a/src/main/java/com/example/demo/app/presentation/form/UserForm.java b/src/main/java/com/example/demo/app/presentation/form/UserForm.java new file mode 100644 index 0000000..e51f23f --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/UserForm.java @@ -0,0 +1,24 @@ +package com.example.demo.app.presentation.form; + +import java.time.LocalDate; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class UserForm { + private String userName; + private String mailAddress; + private String password; + private Long secretQuestionId; + private String SecretAnswer; + private LocalDate birthDate; + private Integer saving; + private Integer annualIncome; + private Integer monthlyBudget; + private Long goalId; + private Long courseId; +}