diff options
author | mavlushechka <mavlushechka@gmail.com> | 2021-11-12 21:31:54 +0500 |
---|---|---|
committer | mavlushechka <mavlushechka@gmail.com> | 2021-11-12 21:31:54 +0500 |
commit | 8d284e1690faba5c0f834a07bac81e1ee00d515f (patch) | |
tree | dd587e71f8c091c1262a84cd2c7e1dd7cd7e4226 /src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java |
Initializing
Diffstat (limited to 'src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java')
-rwxr-xr-x | src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java new file mode 100755 index 0000000..76bc0f2 --- /dev/null +++ b/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java @@ -0,0 +1,41 @@ +package com.mavlushechka.studentdatabase.controller; + +import com.mavlushechka.studentdatabase.domain.Student; +import com.mavlushechka.studentdatabase.domain.User; +import com.mavlushechka.studentdatabase.repository.StudentRepository; +import com.mavlushechka.studentdatabase.repository.UserRepository; +import org.bson.BsonBinarySubType; +import org.bson.types.Binary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.Map; + +@Controller +public class StudentController { + @Autowired + private UserRepository userRepository; + @Autowired + private StudentRepository studentRepository; + + @GetMapping("/information/student") + public String getUserAndStudent(Authentication authentication, Map<String, Object> model) { + User user = userRepository.findByUsername(authentication.getName()); + Student student = studentRepository.findById(user.getId()).orElse(new Student()); + model.put("user", user); + model.put("student", student); + return "information/student"; + } + + @PostMapping("/information/student/save") + public String saveStudent(String id, String diploma, long telephoneNumber, String religion, String car, String house, MultipartFile photo) throws IOException { + Student student = new Student(id, diploma, telephoneNumber, religion, car, house, new Binary(BsonBinarySubType.BINARY, photo.getBytes())); + studentRepository.save(student); + return "redirect:/"; + } +}
\ No newline at end of file |