Commit bd7e703f authored by Deep Dey's avatar Deep Dey

feat: add api to get admission form count

parent 5108c51e
......@@ -82,7 +82,7 @@ public class AdmissionFormController {
public Object setAdmissionInterview(
HttpServletRequest request,
@RequestHeader("apikey") String apiKey,
@RequestParam(defaultValue = "" ) String formIds,
@RequestParam(defaultValue = "") String formIds,
@RequestParam("interactionDate") String interactionDate,
@RequestParam("interactionTime") String interactionTime
) throws Exception {
......@@ -316,4 +316,30 @@ public class AdmissionFormController {
response.setHeader("Content-Disposition", "attachment; filename=master-interaction-template.pdf");
IOUtils.copy(pdfStream, response.getOutputStream());
}
@GetMapping(
value = "/admission-form/count",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "SUCCESS"),
@ApiResponse(code = 400, message = "FAILED"),
@ApiResponse(code = 500, message = "Exception Occurred")
})
@ApiOperation(value = "")
public Object getAdmissionFormsCount(
HttpServletRequest request,
@RequestHeader("apikey") String apiKey
) throws Exception {
// TODO: validation of api key using redis
return new ResponseEntity<>(
new GeneralResponse(
true,
AppConstants.RESPONSE_SUCCESS_STATUS_CODE,
"Data Fetched Successfully",
this.admissionFormDAOController.getAdmissionFormCount()
),
HttpStatus.OK);
}
}
......@@ -2,6 +2,7 @@ package com.example.LaMartin.admission.dao.controller;
import com.example.LaMartin.admission.dao.repository.AdmissionFormDataRepository;
import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.admission.pojo.AdmissionFormCount;
import com.example.LaMartin.common.service.EmailService;
import com.example.LaMartin.common.service.FileStorageService;
import com.example.LaMartin.common.service.PdfService;
......@@ -126,4 +127,8 @@ public class AdmissionFormDAOController {
return updated;
}
public AdmissionFormCount getAdmissionFormCount() {
return admissionFormDataRepository.getAdmissionFormCount();
}
}
package com.example.LaMartin.admission.dao.repository;
import com.example.LaMartin.admission.mapper.AdmissionFormCountMapper;
import com.example.LaMartin.admission.mapper.AdmissionFormMapper;
import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.admission.pojo.AdmissionFormCount;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -245,4 +247,19 @@ public class AdmissionFormDataRepository {
int rowsAffected = namedParameterJdbcTemplate.update(sql, params);
return rowsAffected > 0;
}
public AdmissionFormCount getAdmissionFormCount() {
String sql = """
SELECT
COUNT(CASE WHEN school = 'La Martiniere for Boys' THEN 1 END) AS LMBCount,
COUNT(CASE WHEN school = 'La Martiniere for Girls' THEN 1 END) AS LMGCount
FROM admission_form_data
""";
MapSqlParameterSource parameters = new MapSqlParameterSource();
return namedParameterJdbcTemplate
.queryForObject(sql, parameters, new AdmissionFormCountMapper());
}
}
package com.example.LaMartin.admission.mapper;
import com.example.LaMartin.admission.pojo.AdmissionFormCount;
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 AdmissionFormCountMapper implements RowMapper<AdmissionFormCount> {
@Override
public AdmissionFormCount mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException {
AdmissionFormCount formCount = new AdmissionFormCount();
formCount.setLMGCount(rs.getInt("LMGCount"));
formCount.setLMBCount(rs.getInt("LMBCount"));
return formCount;
}
}
package com.example.LaMartin.admission.pojo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class AdmissionFormCount {
private int LMGCount;
private int LMBCount;
}
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