Commit 8bec9265 authored by Deep Dey's avatar Deep Dey

feat: add form-submit without image

parent 76a1d49b
Pipeline #263 canceled with stages
package com.example.LaMartin.admission.controller; package com.example.LaMartin.admission.controller;
import com.example.LaMartin.admission.dao.controller.AdmissionFormDAOController;
import com.example.LaMartin.admission.model.AdmissionFormData; import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.common.model.GeneralResponse; import com.example.LaMartin.common.model.GeneralResponse;
import com.example.LaMartin.constants.AppConstants; import com.example.LaMartin.constants.AppConstants;
...@@ -21,6 +22,8 @@ import javax.validation.Valid; ...@@ -21,6 +22,8 @@ import javax.validation.Valid;
@AllArgsConstructor(onConstructor = @__(@Autowired)) @AllArgsConstructor(onConstructor = @__(@Autowired))
public class AdmissionFormController { public class AdmissionFormController {
private final AdmissionFormDAOController admissionFormDAOController;
@PostMapping( @PostMapping(
value = "/admission-form/submit", value = "/admission-form/submit",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
...@@ -40,6 +43,11 @@ public class AdmissionFormController { ...@@ -40,6 +43,11 @@ public class AdmissionFormController {
@RequestPart("motherImage") MultipartFile motherImage @RequestPart("motherImage") MultipartFile motherImage
) throws Exception { ) throws Exception {
if (!admissionFormDAOController
.addNewAdmissionData(admissionFormData)) {
throw new Exception("Form Submission Failed");
}
return new ResponseEntity<>( return new ResponseEntity<>(
new GeneralResponse( new GeneralResponse(
true, true,
......
package com.example.LaMartin.admission.dao;
public class AdmissionFormDAOController {
}
package com.example.LaMartin.admission.dao.controller;
import com.example.LaMartin.admission.dao.repository.AdmissionFormDataRepository;
import com.example.LaMartin.admission.model.AdmissionFormData;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
@AllArgsConstructor(onConstructor_ = @__({@Autowired}))
public class AdmissionFormDAOController {
private final AdmissionFormDataRepository admissionFormDataRepository;
public boolean addNewAdmissionData(@NotNull AdmissionFormData formData) {
//TODO: process images
return admissionFormDataRepository.saveAdmissionFormData(formData) > 0;
}
}
package com.example.LaMartin.admission.dao.repository;
import com.example.LaMartin.admission.model.AdmissionFormData;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.Map;
@Repository
@AllArgsConstructor(onConstructor_ = @__({@Autowired}))
public class AdmissionFormDataRepository {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Transactional
public Long saveAdmissionFormData(@NotNull AdmissionFormData formData) {
String sql = "INSERT INTO admission_form_data (" +
"school, category, full_name, admission_class, " +
"date_of_birth, nationality, religion, mother_tongue, community, " +
"other_children, marital_status, " +
"father_name, father_mobile, father_email, father_nationality, father_religion, " +
"father_mother_tongue, father_community, father_school_info, father_college_info, " +
"father_university_info, father_professional_qualification, father_occupation, " +
"father_monthly_income, father_workplace_info, " +
"mother_name, mother_mobile, mother_email, mother_nationality, mother_religion, " +
"mother_mother_tongue, mother_community, mother_school_info, mother_college_info, " +
"mother_university_info, mother_professional_qualification, mother_occupation, " +
"mother_monthly_income, mother_workplace_info, " +
"candidate_image_name, " +
"father_image_name, " +
"mother_image_name) " +
"VALUES (:school, :category, :fullName, :admissionClass, " +
":dateOfBirth, :nationality, :religion, :motherTongue, :community, " +
":otherChildren, :maritalStatus, " +
":fatherName, :fatherMobile, :fatherEmail, :fatherNationality, :fatherReligion, " +
":fatherMotherTongue, :fatherCommunity, :fatherSchoolInfo, :fatherCollegeInfo, " +
":fatherUniversityInfo, :fatherProfessionalQualification, :fatherOccupation, " +
":fatherMonthlyIncome, :fatherWorkplaceInfo, " +
":motherName, :motherMobile, :motherEmail, :motherNationality, :motherReligion, " +
":motherMotherTongue, :motherCommunity, :motherSchoolInfo, :motherCollegeInfo, " +
":motherUniversityInfo, :motherProfessionalQualification, :motherOccupation, " +
":motherMonthlyIncome, :motherWorkplaceInfo, " +
":candidateImageName, " +
":fatherImageName, " +
":motherImageName)";
try {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("school", formData.getSchool());
params.addValue("category", formData.getCategory());
params.addValue("fullName", formData.getFullName());
params.addValue("admissionClass", formData.getAdmissionClass());
params.addValue("dateOfBirth", formData.getDateOfBirth());
params.addValue("nationality", formData.getNationality());
params.addValue("religion", formData.getReligion());
params.addValue("motherTongue", formData.getMotherTongue());
params.addValue("community", formData.getCommunity());
params.addValue("otherChildren", formData.getOtherChildren());
params.addValue("maritalStatus", formData.getMaritalStatus());
params.addValue("fatherName", formData.getFatherName());
params.addValue("fatherMobile", formData.getFatherMobile());
params.addValue("fatherEmail", formData.getFatherEmail());
params.addValue("fatherNationality", formData.getFatherNationality());
params.addValue("fatherReligion", formData.getFatherReligion());
params.addValue("fatherMotherTongue", formData.getFatherMotherTongue());
params.addValue("fatherCommunity", formData.getFatherCommunity());
params.addValue("fatherSchoolInfo", formData.getFatherSchoolInfo());
params.addValue("fatherCollegeInfo", formData.getFatherCollegeInfo());
params.addValue("fatherUniversityInfo", formData.getFatherUniversityInfo());
params.addValue("fatherProfessionalQualification", formData.getFatherProfessionalQualification());
params.addValue("fatherOccupation", formData.getFatherOccupation());
params.addValue("fatherMonthlyIncome", formData.getFatherMonthlyIncome());
params.addValue("fatherWorkplaceInfo", formData.getFatherWorkplaceInfo());
params.addValue("motherName", formData.getMotherName());
params.addValue("motherMobile", formData.getMotherMobile());
params.addValue("motherEmail", formData.getMotherEmail());
params.addValue("motherNationality", formData.getMotherNationality());
params.addValue("motherReligion", formData.getMotherReligion());
params.addValue("motherMotherTongue", formData.getMotherMotherTongue());
params.addValue("motherCommunity", formData.getMotherCommunity());
params.addValue("motherSchoolInfo", formData.getMotherSchoolInfo());
params.addValue("motherCollegeInfo", formData.getMotherCollegeInfo());
params.addValue("motherUniversityInfo", formData.getMotherUniversityInfo());
params.addValue("motherProfessionalQualification", formData.getMotherProfessionalQualification());
params.addValue("motherOccupation", formData.getMotherOccupation());
params.addValue("motherMonthlyIncome", formData.getMotherMonthlyIncome());
params.addValue("motherWorkplaceInfo", formData.getMotherWorkplaceInfo());
params.addValue("candidateImageName", formData.getCandidateImageName());
params.addValue("fatherImageName", formData.getFatherImageName());
params.addValue("motherImageName", formData.getMotherImageName());
KeyHolder keyHolder = new GeneratedKeyHolder();
int cnt = namedParameterJdbcTemplate.update(sql, params, keyHolder);
Long id = null;
if (cnt > 0) {
Map<String, Object> keys = keyHolder.getKeys();
assert keys != null;
Object id_obj = keys.get("id");
id = Long.parseLong(id_obj.toString());
}
return id;
} catch (Exception e) {
return null;
}
}
}
...@@ -3,59 +3,65 @@ package com.example.LaMartin.admission.mapper; ...@@ -3,59 +3,65 @@ package com.example.LaMartin.admission.mapper;
import com.example.LaMartin.admission.model.AdmissionFormData; import com.example.LaMartin.admission.model.AdmissionFormData;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@Component
public class AdmissionFormMapper implements RowMapper<AdmissionFormData> { public class AdmissionFormMapper implements RowMapper<AdmissionFormData> {
@Override @Override
public AdmissionFormData mapRow(@NotNull ResultSet resultSet, int rowNum) throws SQLException { public AdmissionFormData mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException {
return AdmissionFormData AdmissionFormData formData = new AdmissionFormData();
.builder()
.id(resultSet.getLong("id")) formData.setId(rs.getLong("id"));
.school(resultSet.getString("school")) formData.setSchool(rs.getString("school"));
.category(resultSet.getString("category")) formData.setCategory(rs.getString("category"));
.fullName(resultSet.getString("fullName")) formData.setFullName(rs.getString("full_name"));
.admissionClass(resultSet.getString("admissionClass")) formData.setAdmissionClass(rs.getString("admission_class"));
.dateOfBirth(resultSet.getString("dateOfBirth")) formData.setDateOfBirth(rs.getString("date_of_birth"));
.nationality(resultSet.getString("nationality")) formData.setNationality(rs.getString("nationality"));
.religion(resultSet.getString("religion")) formData.setReligion(rs.getString("religion"));
.motherTongue(resultSet.getString("motherTongue")) formData.setMotherTongue(rs.getString("mother_tongue"));
.community(resultSet.getString("community")) formData.setCommunity(rs.getString("community"));
.otherChildren(resultSet.getString("otherChildren")) formData.setOtherChildren(rs.getString("other_children"));
.maritalStatus(resultSet.getString("maritalStatus")) formData.setMaritalStatus(rs.getString("marital_status"));
.fatherName(resultSet.getString("fatherName"))
.fatherMobile(resultSet.getString("fatherMobile")) formData.setFatherName(rs.getString("father_name"));
.fatherEmail(resultSet.getString("fatherEmail")) formData.setFatherMobile(rs.getString("father_mobile"));
.fatherNationality(resultSet.getString("fatherNationality")) formData.setFatherEmail(rs.getString("father_email"));
.fatherReligion(resultSet.getString("fatherReligion")) formData.setFatherNationality(rs.getString("father_nationality"));
.fatherMotherTongue(resultSet.getString("fatherMotherTongue")) formData.setFatherReligion(rs.getString("father_religion"));
.fatherCommunity(resultSet.getString("fatherCommunity")) formData.setFatherMotherTongue(rs.getString("father_mother_tongue"));
.fatherSchoolInfo(resultSet.getString("fatherSchoolInfo")) formData.setFatherCommunity(rs.getString("father_community"));
.fatherCollegeInfo(resultSet.getString("fatherCollegeInfo")) formData.setFatherSchoolInfo(rs.getString("father_school_info"));
.fatherUniversityInfo(resultSet.getString("fatherUniversityInfo")) formData.setFatherCollegeInfo(rs.getString("father_college_info"));
.fatherProfessionalQualification(resultSet.getString("fatherProfessionalQualification")) formData.setFatherUniversityInfo(rs.getString("father_university_info"));
.fatherOccupation(resultSet.getString("fatherOccupation")) formData.setFatherProfessionalQualification(rs.getString("father_professional_qualification"));
.fatherMonthlyIncome(resultSet.getString("fatherMonthlyIncome")) formData.setFatherOccupation(rs.getString("father_occupation"));
.fatherWorkplaceInfo(resultSet.getString("fatherWorkplaceInfo")) formData.setFatherMonthlyIncome(rs.getString("father_monthly_income"));
.motherName(resultSet.getString("motherName")) formData.setFatherWorkplaceInfo(rs.getString("father_workplace_info"));
.motherMobile(resultSet.getString("motherMobile"))
.motherEmail(resultSet.getString("motherEmail")) formData.setMotherName(rs.getString("mother_name"));
.motherNationality(resultSet.getString("motherNationality")) formData.setMotherMobile(rs.getString("mother_mobile"));
.motherReligion(resultSet.getString("motherReligion")) formData.setMotherEmail(rs.getString("mother_email"));
.motherMotherTongue(resultSet.getString("motherMotherTongue")) formData.setMotherNationality(rs.getString("mother_nationality"));
.motherCommunity(resultSet.getString("motherCommunity")) formData.setMotherReligion(rs.getString("mother_religion"));
.motherSchoolInfo(resultSet.getString("motherSchoolInfo")) formData.setMotherMotherTongue(rs.getString("mother_mother_tongue"));
.motherCollegeInfo(resultSet.getString("motherCollegeInfo")) formData.setMotherCommunity(rs.getString("mother_community"));
.motherUniversityInfo(resultSet.getString("motherUniversityInfo")) formData.setMotherSchoolInfo(rs.getString("mother_school_info"));
.motherProfessionalQualification(resultSet.getString("motherProfessionalQualification")) formData.setMotherCollegeInfo(rs.getString("mother_college_info"));
.motherOccupation(resultSet.getString("motherOccupation")) formData.setMotherUniversityInfo(rs.getString("mother_university_info"));
.motherMonthlyIncome(resultSet.getString("motherMonthlyIncome")) formData.setMotherProfessionalQualification(rs.getString("mother_professional_qualification"));
.motherWorkplaceInfo(resultSet.getString("motherWorkplaceInfo")) formData.setMotherOccupation(rs.getString("mother_occupation"));
.candidateImageName(resultSet.getString("candidateImageName")) formData.setMotherMonthlyIncome(rs.getString("mother_monthly_income"));
.fatherImageName(resultSet.getString("fatherImageName")) formData.setMotherWorkplaceInfo(rs.getString("mother_workplace_info"));
.motherImageName(resultSet.getString("motherImageName"))
.build(); formData.setCandidateImageName(rs.getString("candidate_image_name"));
formData.setFatherImageName(rs.getString("father_image_name"));
formData.setMotherImageName(rs.getString("mother_image_name"));
return formData;
} }
} }
...@@ -2,7 +2,7 @@ logging.level.web=DEBUG ...@@ -2,7 +2,7 @@ logging.level.web=DEBUG
#server.error.include-binding-errors=never #server.error.include-binding-errors=never
#server.error.include-message=always #server.error.include-message=always
server.http2.enabled=true server.http2.enabled=true
spring.datasource.url=jdbc:postgresql://localhost:5432/webomagic spring.datasource.url=jdbc:postgresql://localhost:5432/lamartin
spring.web.resources.cache.cachecontrol.s-max-age=3600000 spring.web.resources.cache.cachecontrol.s-max-age=3600000
spring.datasource.username=postgres spring.datasource.username=postgres
spring.datasource.password=2580 spring.datasource.password=2580
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment