[ADD]profileの作成
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ProfileModel {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private LocalDate brithDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
public interface ProfileService {
|
||||
ProfileModel findOne(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
import com.example.demo.app.domain.service.ProfileService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileServiceImpl implements ProfileService{
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public ProfileModel findOne(Long userId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
|
||||
if(userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ProfileModel(
|
||||
userEntity.getUserId(),
|
||||
userEntity.getUserName(),
|
||||
userEntity.getMailAddress(),
|
||||
userEntity.getBirthDate(),
|
||||
userEntity.getSaving(),
|
||||
userEntity.getAnnualIncome(),
|
||||
userEntity.getMonthlyBudget());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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 com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
import com.example.demo.app.domain.service.ProfileService;
|
||||
import com.example.demo.app.presentation.form.ProfileForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileController {
|
||||
private final ProfileService profileService;
|
||||
|
||||
@GetMapping("/profile")
|
||||
public String profile(Model model, HttpSession session) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
ProfileModel profileModel = profileService.findOne(loginUser.getUserId());
|
||||
|
||||
ProfileForm profileForm = ProfileForm.convertForm(profileModel);
|
||||
|
||||
model.addAttribute("profileForm", profileForm);
|
||||
return "profile";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProfileForm {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private LocalDate brithDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
|
||||
public static ProfileForm convertForm(ProfileModel profileModel) {
|
||||
return new ProfileForm(
|
||||
profileModel.getUserId(),
|
||||
profileModel.getUserName(),
|
||||
profileModel.getEmailAddress(),
|
||||
profileModel.getBrithDate(),
|
||||
profileModel.getSaving(),
|
||||
profileModel.getAnnualIncome(),
|
||||
profileModel.getMonthlyBudget());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user