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;
import com.example.LaMartin.admission.dao.controller.AdmissionFormDAOController;
import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.common.model.GeneralResponse;
import com.example.LaMartin.constants.AppConstants;
......@@ -21,6 +22,8 @@ import javax.validation.Valid;
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class AdmissionFormController {
private final AdmissionFormDAOController admissionFormDAOController;
@PostMapping(
value = "/admission-form/submit",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
......@@ -40,6 +43,11 @@ public class AdmissionFormController {
@RequestPart("motherImage") MultipartFile motherImage
) throws Exception {
if (!admissionFormDAOController
.addNewAdmissionData(admissionFormData)) {
throw new Exception("Form Submission Failed");
}
return new ResponseEntity<>(
new GeneralResponse(
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;
import com.example.LaMartin.admission.model.AdmissionFormData;
import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
@Component
public class AdmissionFormMapper implements RowMapper<AdmissionFormData> {
@Override
public AdmissionFormData mapRow(@NotNull ResultSet resultSet, int rowNum) throws SQLException {
return AdmissionFormData
.builder()
.id(resultSet.getLong("id"))
.school(resultSet.getString("school"))
.category(resultSet.getString("category"))
.fullName(resultSet.getString("fullName"))
.admissionClass(resultSet.getString("admissionClass"))
.dateOfBirth(resultSet.getString("dateOfBirth"))
.nationality(resultSet.getString("nationality"))
.religion(resultSet.getString("religion"))
.motherTongue(resultSet.getString("motherTongue"))
.community(resultSet.getString("community"))
.otherChildren(resultSet.getString("otherChildren"))
.maritalStatus(resultSet.getString("maritalStatus"))
.fatherName(resultSet.getString("fatherName"))
.fatherMobile(resultSet.getString("fatherMobile"))
.fatherEmail(resultSet.getString("fatherEmail"))
.fatherNationality(resultSet.getString("fatherNationality"))
.fatherReligion(resultSet.getString("fatherReligion"))
.fatherMotherTongue(resultSet.getString("fatherMotherTongue"))
.fatherCommunity(resultSet.getString("fatherCommunity"))
.fatherSchoolInfo(resultSet.getString("fatherSchoolInfo"))
.fatherCollegeInfo(resultSet.getString("fatherCollegeInfo"))
.fatherUniversityInfo(resultSet.getString("fatherUniversityInfo"))
.fatherProfessionalQualification(resultSet.getString("fatherProfessionalQualification"))
.fatherOccupation(resultSet.getString("fatherOccupation"))
.fatherMonthlyIncome(resultSet.getString("fatherMonthlyIncome"))
.fatherWorkplaceInfo(resultSet.getString("fatherWorkplaceInfo"))
.motherName(resultSet.getString("motherName"))
.motherMobile(resultSet.getString("motherMobile"))
.motherEmail(resultSet.getString("motherEmail"))
.motherNationality(resultSet.getString("motherNationality"))
.motherReligion(resultSet.getString("motherReligion"))
.motherMotherTongue(resultSet.getString("motherMotherTongue"))
.motherCommunity(resultSet.getString("motherCommunity"))
.motherSchoolInfo(resultSet.getString("motherSchoolInfo"))
.motherCollegeInfo(resultSet.getString("motherCollegeInfo"))
.motherUniversityInfo(resultSet.getString("motherUniversityInfo"))
.motherProfessionalQualification(resultSet.getString("motherProfessionalQualification"))
.motherOccupation(resultSet.getString("motherOccupation"))
.motherMonthlyIncome(resultSet.getString("motherMonthlyIncome"))
.motherWorkplaceInfo(resultSet.getString("motherWorkplaceInfo"))
.candidateImageName(resultSet.getString("candidateImageName"))
.fatherImageName(resultSet.getString("fatherImageName"))
.motherImageName(resultSet.getString("motherImageName"))
.build();
public AdmissionFormData mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException {
AdmissionFormData formData = new AdmissionFormData();
formData.setId(rs.getLong("id"));
formData.setSchool(rs.getString("school"));
formData.setCategory(rs.getString("category"));
formData.setFullName(rs.getString("full_name"));
formData.setAdmissionClass(rs.getString("admission_class"));
formData.setDateOfBirth(rs.getString("date_of_birth"));
formData.setNationality(rs.getString("nationality"));
formData.setReligion(rs.getString("religion"));
formData.setMotherTongue(rs.getString("mother_tongue"));
formData.setCommunity(rs.getString("community"));
formData.setOtherChildren(rs.getString("other_children"));
formData.setMaritalStatus(rs.getString("marital_status"));
formData.setFatherName(rs.getString("father_name"));
formData.setFatherMobile(rs.getString("father_mobile"));
formData.setFatherEmail(rs.getString("father_email"));
formData.setFatherNationality(rs.getString("father_nationality"));
formData.setFatherReligion(rs.getString("father_religion"));
formData.setFatherMotherTongue(rs.getString("father_mother_tongue"));
formData.setFatherCommunity(rs.getString("father_community"));
formData.setFatherSchoolInfo(rs.getString("father_school_info"));
formData.setFatherCollegeInfo(rs.getString("father_college_info"));
formData.setFatherUniversityInfo(rs.getString("father_university_info"));
formData.setFatherProfessionalQualification(rs.getString("father_professional_qualification"));
formData.setFatherOccupation(rs.getString("father_occupation"));
formData.setFatherMonthlyIncome(rs.getString("father_monthly_income"));
formData.setFatherWorkplaceInfo(rs.getString("father_workplace_info"));
formData.setMotherName(rs.getString("mother_name"));
formData.setMotherMobile(rs.getString("mother_mobile"));
formData.setMotherEmail(rs.getString("mother_email"));
formData.setMotherNationality(rs.getString("mother_nationality"));
formData.setMotherReligion(rs.getString("mother_religion"));
formData.setMotherMotherTongue(rs.getString("mother_mother_tongue"));
formData.setMotherCommunity(rs.getString("mother_community"));
formData.setMotherSchoolInfo(rs.getString("mother_school_info"));
formData.setMotherCollegeInfo(rs.getString("mother_college_info"));
formData.setMotherUniversityInfo(rs.getString("mother_university_info"));
formData.setMotherProfessionalQualification(rs.getString("mother_professional_qualification"));
formData.setMotherOccupation(rs.getString("mother_occupation"));
formData.setMotherMonthlyIncome(rs.getString("mother_monthly_income"));
formData.setMotherWorkplaceInfo(rs.getString("mother_workplace_info"));
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
#server.error.include-binding-errors=never
#server.error.include-message=always
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.datasource.username=postgres
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