Beneficiary must be able to add to favorite a Call
This commit is contained in:
@@ -203,5 +203,17 @@ public class GepafinConstant {
|
||||
public static final String APPLICATION_SUBMITTED_CANNOT_CHANGE = "application.submitted.cannot.change";
|
||||
public static final String CALL_DOCUMENTS_FETCH_SUCCESS_MSG = "call.documents.fetch.success";
|
||||
public static final String CALL_DOCUMENTS_NOT_FOUND_MSG = "call.documents.not.found";
|
||||
|
||||
public static final String BENEFICIARY_PREFERRED_CALL_CREATED_SUCCESS_MSG = "beneficiary.preferred.call.created.success";
|
||||
public static final String GET_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG = "beneficiary.preferred.call.get.success";
|
||||
public static final String DELETE_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG = "beneficiary.preferred.call.delete.success";
|
||||
public static final String GET_BENEFICIARY_PREFERRED_CALLS_SUCCESS_MSG = "beneficiary.preferred.calls.get.success";
|
||||
public static final String BENEFICIARY_PREFERRED_CALL_UPDATED_SUCCESS_MSG = "beneficiary.preferred.call.updated.success";
|
||||
public static final String BENEFICIARY_CALL_NOT_FOUND = "beneficiary.preferred.call.not.found";
|
||||
public static final String BENEFICIARY_PREFERRED_CALL_STATUS_UPDATED_SUCCESS_MSG = "beneficiary.preferred.call.status.updated.success";
|
||||
public static final String GET_ALL_BENEFICIARY_PREFERRED_CALLS_SUCCESS_MSG = "beneficiary.preferred.calls.get.all.success";
|
||||
public static final String USER_ID_AND_BENEFICIARY_ID_ERROR = "userId.and.beneficiaryId.error";
|
||||
public static final String EITHER_USER_OR_BENEFICIARY_ID_REQUIRED = "either.user.or.beneficiary.id.required";
|
||||
public static final String USER_NOT_FOUND_WITH_BENEFICIARYID_MSG = "User.not.found.with.the.given.beneficiaryID";
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.BeneficiaryPreferredCallRepository;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@Component
|
||||
public class BeneficiaryPreferredCallDao {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(BeneficiaryPreferredCallDao.class);
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(BeneficiaryPreferredCallReq request,UserEntity user) {
|
||||
log.info("Creating new beneficiary preferred call with details: {}", request);
|
||||
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request,user);
|
||||
entity = beneficiaryPreferredCallRepository.save(entity);
|
||||
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
|
||||
return convertEntityToResponse(entity);
|
||||
}
|
||||
|
||||
private BeneficiaryPreferredCallEntity convertRequestToEntity(BeneficiaryPreferredCallReq request,UserEntity userEntity) {
|
||||
BeneficiaryPreferredCallEntity entity = new BeneficiaryPreferredCallEntity();
|
||||
UserEntity user= userService.validateUser(userEntity.getId());
|
||||
if (user.getBeneficiary()!=null) {
|
||||
entity.setBeneficiaryId(user.getBeneficiary().getId());
|
||||
}
|
||||
entity.setStatus(BeneficiaryCallStatus.ENABLED.getValue());
|
||||
entity.setCallId(request.getCallId());
|
||||
entity.setUserId(userEntity.getId());
|
||||
entity.setCompanyId(request.getCompanyId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
public BeneficiaryPreferredCallResponseBean getBeneficiaryPreferredCallById(Long id) {
|
||||
log.info("Fetching beneficiary preferred call with ID: {}", id);
|
||||
BeneficiaryPreferredCallEntity entity = validateBeneficiaryPreferredCall(id);
|
||||
log.info("Beneficiary preferred call found: {}", entity);
|
||||
return convertEntityToResponse(entity);
|
||||
}
|
||||
// public BeneficiaryPreferredCallResponseBean updateBeneficiaryPreferredCall(Long id, BeneficiaryPreferredCallReq request,
|
||||
// UserEntity userEntity) {
|
||||
// log.info("Updating beneficiary preferred call with ID: {}", id);
|
||||
// BeneficiaryPreferredCallEntity existingEntity = validateBeneficiaryPreferredCall(id);
|
||||
// setIfUpdated(existingEntity::getCallId, existingEntity::setCallId, request.getCallId());
|
||||
// setIfUpdated(existingEntity::getCompanyId, existingEntity::setCompanyId, request.getCompanyId());
|
||||
//
|
||||
// existingEntity = beneficiaryPreferredCallRepository.save(existingEntity);
|
||||
//
|
||||
// log.info("Beneficiary preferred call updated with ID: {}", existingEntity.getId());
|
||||
// return convertEntityToResponse(existingEntity);
|
||||
// }
|
||||
|
||||
private boolean isUserABeneficiary(Long userId) {
|
||||
UserEntity user=userService.validateUser(userId);
|
||||
return RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(user.getRoleEntity().getRoleType());
|
||||
}
|
||||
public void deleteBeneficiaryPreferredCallById(Long id) {
|
||||
log.info("Deleting beneficiary preferred call with ID: {}", id);
|
||||
validateBeneficiaryPreferredCall(id);
|
||||
beneficiaryPreferredCallRepository.deleteById(id);
|
||||
log.info("Beneficiary preferred call deleted with ID: {}", id);
|
||||
}
|
||||
|
||||
public List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls() {
|
||||
log.info("Fetching all beneficiary preferred calls");
|
||||
List<BeneficiaryPreferredCallResponseBean> calls = beneficiaryPreferredCallRepository.findAll()
|
||||
.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
.collect(Collectors.toList());
|
||||
log.info("Total beneficiary preferred calls found: {}", calls.size());
|
||||
return calls;
|
||||
}
|
||||
|
||||
private BeneficiaryPreferredCallEntity validateBeneficiaryPreferredCall(Long id) {
|
||||
log.info("Validating beneficiary preferred call with ID: {}", id);
|
||||
return beneficiaryPreferredCallRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.BENEFICIARY_CALL_NOT_FOUND)));
|
||||
}
|
||||
|
||||
private BeneficiaryPreferredCallResponseBean convertEntityToResponse(BeneficiaryPreferredCallEntity entity) {
|
||||
BeneficiaryPreferredCallResponseBean response = new BeneficiaryPreferredCallResponseBean();
|
||||
response.setId(entity.getId());
|
||||
response.setBeneficiaryId(entity.getBeneficiaryId());
|
||||
response.setStatus(BeneficiaryCallStatus.valueOf(entity.getStatus()));
|
||||
response.setCallId(entity.getCallId());
|
||||
response.setUserId(entity.getUserId());
|
||||
response.setCompanyId(entity.getCompanyId());
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
|
||||
return response;
|
||||
}
|
||||
public void updateBeneficiaryPreferredCallStatus(Long id, BeneficiaryCallStatus status) {
|
||||
log.info("Updating status for beneficiary preferred call with ID: {}", id);
|
||||
BeneficiaryPreferredCallEntity existingEntity = validateBeneficiaryPreferredCall(id);
|
||||
existingEntity.setStatus(status.getValue());
|
||||
beneficiaryPreferredCallRepository.save(existingEntity);
|
||||
log.info("Beneficiary preferred call status updated with ID: {}", existingEntity.getId());
|
||||
}
|
||||
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(UserEntity userEntity, Long companyId) {
|
||||
|
||||
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId);
|
||||
return calls.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,14 @@ public class UserDao {
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
}
|
||||
public UserEntity getUserByBeneficiaryId(Long beneficiaryId) {
|
||||
UserEntity user = userRepository.findByBeneficiaryId(beneficiaryId);
|
||||
if (user == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_WITH_BENEFICIARYID_MSG));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public String initiatePasswordReset(InitiatePasswordResetReq resetReq) {
|
||||
UserEntity user = userRepository.findByEmail(resetReq.getEmail());
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.gepafin.tendermanagement.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "beneficiary_preferred_call")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BeneficiaryPreferredCallEntity extends BaseEntity{
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "beneficiary_id")
|
||||
private Long beneficiaryId;
|
||||
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "company_id")
|
||||
private Long companyId;
|
||||
|
||||
@Column(name = "call_id")
|
||||
private Long callId;
|
||||
|
||||
@Column(name = "STATUS", length = 255)
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum BeneficiaryCallStatus {
|
||||
|
||||
ENABLED("ENABLED"),
|
||||
DISABLED("DISABLED"),
|
||||
APPLIED("APPLIED");
|
||||
|
||||
private String value;
|
||||
|
||||
BeneficiaryCallStatus(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class BeneficiaryPreferredCallReq {
|
||||
|
||||
private Long companyId;
|
||||
private Long callId;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class BeneficiaryPreferredCallResponseBean {
|
||||
|
||||
|
||||
private Long id;
|
||||
private Long beneficiaryId;
|
||||
private Long userId;
|
||||
private Long companyId;
|
||||
private Long callId;
|
||||
private BeneficiaryCallStatus status;
|
||||
private LocalDateTime createdDate;
|
||||
private LocalDateTime updatedDate;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
import net.gepafin.tendermanagement.entities.BeneficiaryPreferredCallEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface BeneficiaryPreferredCallRepository extends JpaRepository<BeneficiaryPreferredCallEntity, Long> {
|
||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryId(Long beneficiaryId);
|
||||
List<BeneficiaryPreferredCallEntity> findByUserId(Long userId);
|
||||
|
||||
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId)")
|
||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyId(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
|
||||
}
|
||||
@@ -18,4 +18,5 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||
Optional<UserEntity> findByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||
|
||||
boolean existsByBeneficiaryCodiceFiscale(String codiceFiscale);
|
||||
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.gepafin.tendermanagement.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BeneficiaryPreferredCallService {
|
||||
|
||||
BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest request, BeneficiaryPreferredCallReq beneficiaryPreferredCallRequest);
|
||||
|
||||
BeneficiaryPreferredCallResponseBean getBeneficiaryPreferredCallById(HttpServletRequest request, Long id);
|
||||
|
||||
void deleteBeneficiaryPreferredCall(HttpServletRequest request, Long id);
|
||||
|
||||
List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls(HttpServletRequest request);
|
||||
|
||||
// BeneficiaryPreferredCallResponseBean updateBeneficiaryPreferredCall(HttpServletRequest request, Long id, BeneficiaryPreferredCallReq beneficiaryPreferredCallRequest);
|
||||
void updateBeneficiaryPreferredCallStatus(HttpServletRequest request, Long id, BeneficiaryCallStatus status);
|
||||
|
||||
List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(HttpServletRequest request,Long userId,Long beneficiaryId,Long companyId);
|
||||
}
|
||||
@@ -40,4 +40,5 @@ public interface UserService {
|
||||
JWTToken validateExistingUserToken(HttpServletRequest request, String token);
|
||||
|
||||
UserSamlResponse validateNewUserToken(HttpServletRequest request, String token);
|
||||
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.BeneficiaryPreferredCallDao;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BeneficiaryPreferredCallServiceImpl implements BeneficiaryPreferredCallService {
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallDao beneficiaryPreferredCallDao;
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@Override
|
||||
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest request, BeneficiaryPreferredCallReq beneficiaryPreferredCallRequest) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return beneficiaryPreferredCallDao.createBeneficiaryPreferredCall(beneficiaryPreferredCallRequest,userEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeneficiaryPreferredCallResponseBean getBeneficiaryPreferredCallById(HttpServletRequest request, Long id) {
|
||||
return beneficiaryPreferredCallDao.getBeneficiaryPreferredCallById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBeneficiaryPreferredCall(HttpServletRequest request, Long id) {
|
||||
beneficiaryPreferredCallDao.deleteBeneficiaryPreferredCallById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls(HttpServletRequest request) {
|
||||
return beneficiaryPreferredCallDao.getAllBeneficiaryPreferredCalls();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public BeneficiaryPreferredCallResponseBean updateBeneficiaryPreferredCall(HttpServletRequest request, Long id,
|
||||
// BeneficiaryPreferredCallReq beneficiaryPreferredCallRequest) {
|
||||
// UserEntity userEntity = validator.validateUser(request);
|
||||
// return beneficiaryPreferredCallDao.updateBeneficiaryPreferredCall(id, beneficiaryPreferredCallRequest,userEntity);
|
||||
// }
|
||||
@Override
|
||||
public void updateBeneficiaryPreferredCallStatus(HttpServletRequest request, Long id, BeneficiaryCallStatus status) {
|
||||
beneficiaryPreferredCallDao.updateBeneficiaryPreferredCallStatus(id, status);
|
||||
}
|
||||
@Override
|
||||
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(HttpServletRequest request,Long userId,Long beneficiaryId,Long companyId) {
|
||||
UserEntity userEntity =validateGetBeneficiaryPreferredCallrequest(request,userId,beneficiaryId);
|
||||
return beneficiaryPreferredCallDao.getBeneficiaryPreferredCallByUserId(userEntity,companyId);
|
||||
}
|
||||
|
||||
private UserEntity validateGetBeneficiaryPreferredCallrequest(HttpServletRequest request, Long userId, Long beneficiaryId) {
|
||||
if (userId == null && beneficiaryId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.EITHER_USER_OR_BENEFICIARY_ID_REQUIRED));
|
||||
}
|
||||
if(userId!=null&&beneficiaryId!=null){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.USER_ID_AND_BENEFICIARY_ID_ERROR));
|
||||
}
|
||||
if(beneficiaryId!=null){
|
||||
UserEntity user = userService.getUserByBeneficiaryId(beneficiaryId);
|
||||
return validator.validateUserId(request,user.getId());
|
||||
}
|
||||
else{
|
||||
return validator.validateUserId(request, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,4 +115,8 @@ public class UserServiceImpl implements UserService {
|
||||
public UserSamlResponse validateNewUserToken(HttpServletRequest request, String token) {
|
||||
return userDao.validateNewUserToken(token);
|
||||
}
|
||||
@Override
|
||||
public UserEntity getUserByBeneficiaryId(Long beneficiaryId) {
|
||||
return userDao.getUserByBeneficiaryId(beneficiaryId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
@RequestMapping("/v1/beneficiaryPreferredCall")
|
||||
public interface BeneficiaryPreferredCallApi {
|
||||
|
||||
@Operation(summary = "Create a new beneficiary preferred call",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Created"),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)})),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> createBeneficiaryPreferredCall(HttpServletRequest request,
|
||||
@Parameter(required = true)
|
||||
@Valid @RequestBody BeneficiaryPreferredCallReq beneficiaryPreferredCallReq);
|
||||
|
||||
/* @Operation(summary = "Update an existing beneficiary preferred call",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)})),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> updateBeneficiaryPreferredCall(HttpServletRequest request,
|
||||
@Parameter( required = true)
|
||||
@PathVariable("id") Long id,
|
||||
@Valid @RequestBody BeneficiaryPreferredCallReq beneficiaryPreferredCallReq);
|
||||
*/
|
||||
@Operation(summary = "Get a beneficiary preferred call by ID",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> getBeneficiaryPreferredCallById(HttpServletRequest request,
|
||||
@Parameter( required = true)
|
||||
@PathVariable("id") Long id);
|
||||
|
||||
@Operation(summary = "Delete a beneficiary preferred call",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@DeleteMapping(value = "/{id}")
|
||||
ResponseEntity<Response<Void>> deleteBeneficiaryPreferredCall(HttpServletRequest request,
|
||||
@Parameter(required = true)
|
||||
@PathVariable("id") Long id);
|
||||
|
||||
@Operation(summary = "Update status of a beneficiary preferred call",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@PutMapping(value = "/{id}/status", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<Void>> updateBeneficiaryPreferredCallStatus(HttpServletRequest request,
|
||||
@Parameter( required = true)
|
||||
@PathVariable("id") Long id,
|
||||
@Parameter(description = "New status for the preferred call", required = true)
|
||||
@RequestParam(value = "status", required = true) BeneficiaryCallStatus status);
|
||||
|
||||
@Operation(summary = "Get all beneficiary preferred calls",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)}))})
|
||||
@GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ResponseEntity<Response<List<BeneficiaryPreferredCallResponseBean>>> getBeneficiaryPreferredCallByUserId(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(value = "userId",required = false) Long userId,
|
||||
@RequestParam(value = "beneficiaryId",required = false) Long beneficiaryId,
|
||||
@RequestParam(value = "companyId",required = false) Long companyId
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.BeneficiaryCallStatus;
|
||||
import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
|
||||
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.BeneficiaryPreferredCallService;
|
||||
import net.gepafin.tendermanagement.web.rest.api.BeneficiaryPreferredCallApi;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class BeneficiaryPreferredCallApiController implements BeneficiaryPreferredCallApi {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(BeneficiaryPreferredCallApiController.class);
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallService beneficiaryPreferredCallService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> createBeneficiaryPreferredCall(HttpServletRequest request, BeneficiaryPreferredCallReq beneficiaryPreferredCallReq) {
|
||||
log.info("Creating Beneficiary Preferred Call");
|
||||
BeneficiaryPreferredCallResponseBean responseBean = beneficiaryPreferredCallService.createBeneficiaryPreferredCall(request, beneficiaryPreferredCallReq);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(responseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.BENEFICIARY_PREFERRED_CALL_CREATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> updateBeneficiaryPreferredCall(HttpServletRequest request, Long id, BeneficiaryPreferredCallReq beneficiaryPreferredCallReq) {
|
||||
// log.info("Updating Beneficiary Preferred Call - ID: {}", id);
|
||||
// BeneficiaryPreferredCallResponseBean response = beneficiaryPreferredCallService.updateBeneficiaryPreferredCall(request, id, beneficiaryPreferredCallReq);
|
||||
// return ResponseEntity.status(HttpStatus.OK)
|
||||
// .body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.BENEFICIARY_PREFERRED_CALL_UPDATED_SUCCESS_MSG)));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<BeneficiaryPreferredCallResponseBean>> getBeneficiaryPreferredCallById(HttpServletRequest request, Long id) {
|
||||
log.info("Fetching Beneficiary Preferred Call by ID - ID: {}", id);
|
||||
BeneficiaryPreferredCallResponseBean response = beneficiaryPreferredCallService.getBeneficiaryPreferredCallById(request, id);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteBeneficiaryPreferredCall(HttpServletRequest request, Long id) {
|
||||
log.info("Deleting Beneficiary Preferred Call - ID: {}", id);
|
||||
beneficiaryPreferredCallService.deleteBeneficiaryPreferredCall(request, id);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_BENEFICIARY_PREFERRED_CALL_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> updateBeneficiaryPreferredCallStatus(HttpServletRequest request, Long id, BeneficiaryCallStatus status) {
|
||||
log.info("Updating status of Beneficiary Preferred Call - ID: {}, Status: {}", id, status);
|
||||
beneficiaryPreferredCallService.updateBeneficiaryPreferredCallStatus(request, id, status);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.BENEFICIARY_PREFERRED_CALL_STATUS_UPDATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<BeneficiaryPreferredCallResponseBean>>> getBeneficiaryPreferredCallByUserId(HttpServletRequest request,Long userId,Long beneficiaryId,Long companyId) {
|
||||
log.info("Fetching all Beneficiary Preferred Calls for User ID");
|
||||
List<BeneficiaryPreferredCallResponseBean> response = beneficiaryPreferredCallService.getBeneficiaryPreferredCallByUserId(request, userId,beneficiaryId,companyId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_ALL_BENEFICIARY_PREFERRED_CALLS_SUCCESS_MSG)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user