Add hubid for user
This commit is contained in:
@@ -157,4 +157,10 @@ public class GepafinConstant {
|
||||
public static final String IS_PIVA="isPIVA";
|
||||
|
||||
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
|
||||
public static final String HUB_CREATE_SUCCESS = "hub_create_success";
|
||||
public static final String HUB_UPDATE_SUCCESS = "hub_update_success";
|
||||
public static final String HUB_GET_SUCCESS = "hub_get_success";
|
||||
public static final String HUB_GET_ALL_SUCCESS = "hub_get_all_success";
|
||||
public static final String HUB_DELETE_SUCCESS = "hub_delete_success";
|
||||
public static final String HUB_NOT_FOUND = "hub_not_found";
|
||||
}
|
||||
|
||||
92
src/main/java/net/gepafin/tendermanagement/dao/HubDao.java
Normal file
92
src/main/java/net/gepafin/tendermanagement/dao/HubDao.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.NanoIdUtils;
|
||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Component
|
||||
public class HubDao {
|
||||
|
||||
@Autowired
|
||||
private HubRepository hubRepository;
|
||||
|
||||
public HubResponseBean createHub(HubReq hubReq) {
|
||||
HubEntity hubEntity = createOrUpdateHubEntity(new HubEntity(), hubReq);
|
||||
hubRepository.save(hubEntity);
|
||||
return convertToHubResponseBean(hubEntity);
|
||||
}
|
||||
|
||||
public HubResponseBean updateHub(Long hubId, HubReq hubReq) {
|
||||
HubEntity hubEntity = validateHub(hubId);
|
||||
createOrUpdateHubEntity(hubEntity, hubReq);
|
||||
return convertToHubResponseBean(hubEntity);
|
||||
}
|
||||
|
||||
public HubResponseBean getHubById(Long hubId) {
|
||||
return convertToHubResponseBean(validateHub(hubId));
|
||||
}
|
||||
|
||||
public List<HubResponseBean> getAllHubs() {
|
||||
List<HubEntity> hubs = hubRepository.findAll();
|
||||
return hubs.stream().map(this::convertToHubResponseBean).toList();
|
||||
}
|
||||
|
||||
public void deleteHub(Long hubId) {
|
||||
HubEntity hubEntity = validateHub(hubId);
|
||||
hubRepository.deleteById(hubId);
|
||||
hubRepository.save(hubEntity);
|
||||
}
|
||||
|
||||
private HubEntity validateHub(Long hubId) {
|
||||
return hubRepository.findById(hubId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.HUB_NOT_FOUND)));
|
||||
}
|
||||
|
||||
private HubEntity createOrUpdateHubEntity(HubEntity hubEntity, HubReq hubReq) {
|
||||
hubEntity.setCompanyName(hubReq.getCompanyName());
|
||||
hubEntity.setFirstName(hubReq.getFirstName());
|
||||
hubEntity.setLastName(hubReq.getLastName());
|
||||
hubEntity.setEmail(hubReq.getEmail());
|
||||
hubEntity.setCity(hubReq.getCity());
|
||||
hubEntity.setCountry(hubReq.getCountry());
|
||||
hubEntity.setVatNumber(hubReq.getVatNumber());
|
||||
hubEntity.setUniqueUuid(NanoIdUtils.randomNanoId());
|
||||
hubEntity.setDomainName(hubReq.getDomainName());
|
||||
hubEntity.setAppConfig(hubReq.getAppConfig() != null ? hubReq.getAppConfig().toString() : null);
|
||||
hubEntity.setCreatedDate(hubEntity.getCreatedDate() == null ? LocalDateTime.now() : hubEntity.getCreatedDate());
|
||||
hubEntity.setUpdatedDate(LocalDateTime.now());
|
||||
return hubEntity;
|
||||
}
|
||||
|
||||
private HubResponseBean convertToHubResponseBean(HubEntity hubEntity) {
|
||||
HubResponseBean responseBean = new HubResponseBean();
|
||||
responseBean.setId(hubEntity.getId());
|
||||
responseBean.setCompanyName(hubEntity.getCompanyName());
|
||||
responseBean.setFirstName(hubEntity.getFirstName());
|
||||
responseBean.setLastName(hubEntity.getLastName());
|
||||
responseBean.setEmail(hubEntity.getEmail());
|
||||
responseBean.setCity(hubEntity.getCity());
|
||||
responseBean.setCountry(hubEntity.getCountry());
|
||||
responseBean.setVatNumber(hubEntity.getVatNumber());
|
||||
responseBean.setUniqueUuid(hubEntity.getUniqueUuid());
|
||||
responseBean.setDomainName(hubEntity.getDomainName());
|
||||
responseBean.setAppConfig(hubEntity.getAppConfig());
|
||||
responseBean.setCreatedDate(hubEntity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(hubEntity.getUpdatedDate());
|
||||
return responseBean;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,13 @@ import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserHubEntity;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
import net.gepafin.tendermanagement.repositories.UserHubRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
@@ -22,7 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@@ -39,7 +43,8 @@ public class UserDao {
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
private UserHubRepository userHubRepository;
|
||||
@Autowired
|
||||
private RoleDao roleDao;
|
||||
|
||||
@@ -226,5 +231,25 @@ public class UserDao {
|
||||
log.info("User status updated to {} for user ID: {}", statusReq, userId);
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
public List<UserResponseBean> getUserByHubId(String hubId) {
|
||||
log.info("Fetching users for hub ID: {}", hubId);
|
||||
List<UserHubEntity> userHubMappings = userHubRepository.findByHubId(hubId);
|
||||
List<UserResponseBean> userResponseBeans = new ArrayList<>();
|
||||
for (UserHubEntity mapping : userHubMappings) {
|
||||
UserEntity userEntity = validateUser(mapping.getUserId());
|
||||
userResponseBeans.add(convertUserEntityToUserResponse(userEntity));
|
||||
}
|
||||
return userResponseBeans;
|
||||
}
|
||||
|
||||
public UserResponseBean createUserByHubId(String hubId, UserReq userReq) {
|
||||
log.info("Creating user for hub ID: {}", hubId);
|
||||
UserResponseBean createdUser = createUser(userReq);
|
||||
UserHubEntity mapping = new UserHubEntity();
|
||||
mapping.setHubId(hubId);
|
||||
mapping.setUserId(createdUser.getId());
|
||||
userHubRepository.save(mapping);
|
||||
log.info("User created and mapped to hub ID: {} with User ID: {}", hubId, createdUser.getId());
|
||||
return createdUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.gepafin.tendermanagement.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name="hub")
|
||||
@Setter
|
||||
@Getter
|
||||
public class HubEntity extends BaseEntity{
|
||||
|
||||
|
||||
@Column(name = "COMPANY_NAME", length = 255,nullable = false)
|
||||
private String companyName;
|
||||
|
||||
@Column(name = "FIRST_NAME", length = 255)
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "LAST_NAME", length = 255)
|
||||
private String lastName;
|
||||
|
||||
@Column(name = "EMAIL", length = 255,nullable = false)
|
||||
private String email;
|
||||
|
||||
@Column(name = "CITY", length = 255)
|
||||
private String city;
|
||||
|
||||
@Column(name = "COUNTRY", length = 255, nullable = false)
|
||||
private String country;
|
||||
|
||||
@Size(min=5,max=15)
|
||||
@Column(name = "VAT_NUMBER", length = 255,nullable = false, unique = true)
|
||||
private String vatNumber;
|
||||
|
||||
@Column(name = "DOMAIN_NAME", length = 255)
|
||||
private String domainName;
|
||||
|
||||
@Column(name = "APP_CONFIG", columnDefinition = "TEXT")
|
||||
private String appConfig;
|
||||
|
||||
@Column(name = "UNIQUE_UUID", length = 255,nullable = false, unique = true)
|
||||
private String uniqueUuid;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.gepafin.tendermanagement.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hub_user")
|
||||
@Getter
|
||||
@Setter
|
||||
public class HubUserEntity extends BaseEntity{
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "hub_id", nullable = false)
|
||||
private HubEntity hub;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private UserEntity user;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.gepafin.tendermanagement.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "USER_HUB")
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserHubEntity extends BaseEntity {
|
||||
|
||||
@Column(name = "hub_id")
|
||||
private String hubId;
|
||||
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class HubReq {
|
||||
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
|
||||
private String companyName;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String city;
|
||||
|
||||
private String country;
|
||||
|
||||
private String vatNumber;
|
||||
|
||||
private String domainName;
|
||||
|
||||
private Map<String, Object> appConfig;
|
||||
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private String uniqueUuid;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.gepafin.tendermanagement.model.BaseBean;
|
||||
|
||||
import java.util.Map;
|
||||
@Getter
|
||||
@Setter
|
||||
public class HubResponseBean extends BaseBean {
|
||||
|
||||
private String companyName;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String city;
|
||||
|
||||
private String country;
|
||||
|
||||
private String vatNumber;
|
||||
|
||||
private String appConfig;
|
||||
|
||||
private String domainName;
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private String uniqueUuid;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Copyright (c) 2017 The JNanoID Authors
|
||||
* Copyright (c) 2017 Aventrix LLC
|
||||
* Copyright (c) 2017 Andrey Sitnik
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.gepafin.tendermanagement.model.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public final class NanoIdUtils {
|
||||
|
||||
/**
|
||||
* <code>NanoIdUtils</code> instances should NOT be constructed in standard programming.
|
||||
* Instead, the class should be used as <code>NanoIdUtils.randomNanoId();</code>.
|
||||
*/
|
||||
private NanoIdUtils() {
|
||||
//Do Nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* The default random number generator used by this class.
|
||||
* Creates cryptographically strong NanoId Strings.
|
||||
*/
|
||||
public static final SecureRandom DEFAULT_NUMBER_GENERATOR = new SecureRandom();
|
||||
|
||||
/**
|
||||
* The default alphabet used by this class.
|
||||
* Creates url-friendly NanoId Strings using 64 unique symbols.
|
||||
*/
|
||||
public static final char[] DEFAULT_ALPHABET =
|
||||
"_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
||||
|
||||
/**
|
||||
* The default size used by this class.
|
||||
* Creates NanoId Strings with slightly more unique values than UUID v4.
|
||||
*/
|
||||
public static final int DEFAULT_SIZE = 21;
|
||||
|
||||
/**
|
||||
* Static factory to retrieve a url-friendly, pseudo randomly generated, NanoId String.
|
||||
*
|
||||
* The generated NanoId String will have 21 symbols.
|
||||
*
|
||||
* The NanoId String is generated using a cryptographically strong pseudo random number
|
||||
* generator.
|
||||
*
|
||||
* @return A randomly generated NanoId String.
|
||||
*/
|
||||
public static String randomNanoId() {
|
||||
return randomNanoId(DEFAULT_NUMBER_GENERATOR, DEFAULT_ALPHABET, DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory to retrieve a NanoId String.
|
||||
*
|
||||
* The string is generated using the given random number generator.
|
||||
*
|
||||
* @param random The random number generator.
|
||||
* @param alphabet The symbols used in the NanoId String.
|
||||
* @param size The number of symbols in the NanoId String.
|
||||
* @return A randomly generated NanoId String.
|
||||
*/
|
||||
public static String randomNanoId(final Random random, final char[] alphabet, final int size) {
|
||||
|
||||
if (random == null) {
|
||||
throw new IllegalArgumentException("random cannot be null.");
|
||||
}
|
||||
|
||||
if (alphabet == null) {
|
||||
throw new IllegalArgumentException("alphabet cannot be null.");
|
||||
}
|
||||
|
||||
if (alphabet.length == 0 || alphabet.length >= 256) {
|
||||
throw new IllegalArgumentException("alphabet must contain between 1 and 255 symbols.");
|
||||
}
|
||||
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("size must be greater than zero.");
|
||||
}
|
||||
|
||||
double value = (double) (alphabet.length - 1);
|
||||
|
||||
final int mask = (2 << (int) Math.floor(Math.log(value) / Math.log(2))) - 1;
|
||||
final int step = (int) Math.ceil(1.6 * mask * size / alphabet.length);
|
||||
|
||||
final StringBuilder idBuilder = new StringBuilder();
|
||||
|
||||
while (true) {
|
||||
|
||||
final byte[] bytes = new byte[step];
|
||||
random.nextBytes(bytes);
|
||||
|
||||
for (int i = 0; i < step; i++) {
|
||||
|
||||
final int alphabetIndex = bytes[i] & mask;
|
||||
|
||||
if (alphabetIndex < alphabet.length) {
|
||||
idBuilder.append(alphabet[alphabetIndex]);
|
||||
if (idBuilder.length() == size) {
|
||||
return idBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.HubEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface HubRepository extends JpaRepository<HubEntity, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
|
||||
|
||||
import net.gepafin.tendermanagement.entities.UserHubEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserHubRepository extends JpaRepository<UserHubEntity, Long> {
|
||||
List<UserHubEntity> findByHubId(String hubId);
|
||||
UserHubEntity findByHubIdAndUserId(String hubId, Long userId);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.gepafin.tendermanagement.service;
|
||||
|
||||
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HubService {
|
||||
HubResponseBean createHub(HubReq hubReq);
|
||||
HubResponseBean updateHub(Long hubId, HubReq hubReq);
|
||||
HubResponseBean getHubById(Long hubId);
|
||||
List<HubResponseBean> getAllHubs();
|
||||
void deleteHub(Long hubId);
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
UserResponseBean createUser(UserReq userReq);
|
||||
|
||||
@@ -35,4 +37,6 @@ public interface UserService {
|
||||
UserResponseBean updateUserStatus(Long userId, UserStatusEnum statusReq);
|
||||
|
||||
UserResponseBean getValidUser(HttpServletRequest request);
|
||||
List<UserResponseBean> getUserByHubId(String hubId);
|
||||
UserResponseBean createUserByHubId(String hubId, UserReq userReq);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import net.gepafin.tendermanagement.dao.HubDao;
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HubServiceImpl implements HubService {
|
||||
|
||||
@Autowired
|
||||
private HubDao hubDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HubResponseBean createHub(HubReq hubReq) {
|
||||
return hubDao.createHub(hubReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HubResponseBean updateHub(Long hubId, HubReq hubReq) {
|
||||
return hubDao.updateHub(hubId, hubReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public HubResponseBean getHubById(Long hubId) {
|
||||
return hubDao.getHubById(hubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<HubResponseBean> getAllHubs() {
|
||||
return hubDao.getAllHubs();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteHub(Long hubId) {
|
||||
hubDao.deleteHub(hubId);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -93,4 +94,15 @@ public class UserServiceImpl implements UserService {
|
||||
UserEntity user=tokenProvider.validateUser(userInfo);
|
||||
return userDao.getUserById(user.getId());
|
||||
}
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<UserResponseBean> getUserByHubId(String hubId) {
|
||||
return userDao.getUserByHubId(hubId);
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserResponseBean createUserByHubId(String hubId, UserReq userReq) {
|
||||
return userDao.createUserByHubId(hubId, userReq);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.validation.Valid;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
@RequestMapping("/hub")
|
||||
public interface HubApi {
|
||||
|
||||
@Operation(summary = "API to create a hub", 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) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@PostMapping(value = "", produces = "application/json")
|
||||
ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request,
|
||||
@Parameter(description = "Hub request object", required = true)
|
||||
@Valid @RequestBody HubReq hubReq);
|
||||
|
||||
@Operation(summary = "API to update a hub", 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) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@PutMapping(value = "/{hubId}", produces = "application/json")
|
||||
ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@PathVariable("hubId") Long hubId,
|
||||
@Parameter(description = "Hub request object", required = true)
|
||||
@Valid @RequestBody HubReq hubReq);
|
||||
|
||||
@Operation(summary = "API to get a hub 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) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@GetMapping(value = "/{hubId}", produces = "application/json")
|
||||
ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@PathVariable("hubId") Long hubId);
|
||||
|
||||
@Operation(summary = "API to get all hubs", 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) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@GetMapping(value = "", produces = "application/json")
|
||||
ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request);
|
||||
|
||||
@Operation(summary = "API to delete a hub", 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) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@DeleteMapping(value = "/{hubId}")
|
||||
ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@PathVariable("hubId") Long hubId);
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Validated
|
||||
public interface UserApi {
|
||||
@@ -186,6 +188,36 @@ public interface UserApi {
|
||||
@GetMapping(value = "/me",
|
||||
produces = { "application/json" })
|
||||
ResponseEntity<Response<UserResponseBean>> getValidUser(HttpServletRequest request);
|
||||
@Operation(summary = "API to create user by hubId",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "User created successfully"),
|
||||
@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)}))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@RequestMapping(value = "/hub/{hubId}",
|
||||
produces = {"application/json"},
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Response<UserResponseBean>> createUserByHubId(
|
||||
@Parameter(description = "The hubId", required = true) @PathVariable("hubId") String hubId,
|
||||
@Parameter(description = "User request object for hubId", required = true) @Valid @RequestBody UserReq userReq);
|
||||
|
||||
@Operation(summary = "Api to get user by hubId",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@RequestMapping(value = "/hub/{hubId}",
|
||||
produces = {"application/json"},
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<Response<List<UserResponseBean>>> getUserByHubId(
|
||||
@Parameter(description = "The hubId", required = true) @PathVariable("hubId") String hubId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.HubApi;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class HubApiController implements HubApi {
|
||||
|
||||
private final HubService hubService;
|
||||
private final Validator validator;
|
||||
|
||||
public HubApiController(HubService hubService, Validator validator) {
|
||||
this.hubService = hubService;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request, @Valid HubReq hubReq) {
|
||||
validator.validateUser(request);
|
||||
HubResponseBean hubResponse = hubService.createHub(hubReq);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_CREATE_SUCCESS)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request, Long hubId, @Valid HubReq hubReq) {
|
||||
validator.validateUser(request);
|
||||
HubResponseBean hubResponse = hubService.updateHub(hubId, hubReq);
|
||||
if (hubResponse != null) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_UPDATE_SUCCESS)));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body(new Response<>(null, Status.NOT_FOUND, Translator.toLocale(GepafinConstant.HUB_NOT_FOUND)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, Long hubId) {
|
||||
validator.validateUser(request);
|
||||
HubResponseBean hubResponse = hubService.getHubById(hubId);
|
||||
if (hubResponse != null) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_SUCCESS)));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body(new Response<>(null, Status.NOT_FOUND, Translator.toLocale(GepafinConstant.HUB_NOT_FOUND)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request) {
|
||||
validator.validateUser(request);
|
||||
List<HubResponseBean> hubs = hubService.getAllHubs();
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(hubs, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_ALL_SUCCESS)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, Long hubId) {
|
||||
validator.validateUser(request);
|
||||
hubService.deleteHub(hubId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_DELETE_SUCCESS)));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
|
||||
@@ -124,4 +126,20 @@ public class UserApiController implements UserApi {
|
||||
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
|
||||
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<UserResponseBean>> createUserByHubId(
|
||||
@PathVariable("hubId") String hubId,
|
||||
@Valid @RequestBody UserReq userReq) {
|
||||
log.info("Create User by Hub ID - Hub ID: {}, Request Body: {}", hubId, userReq);
|
||||
UserResponseBean createdUser = userService.createUserByHubId(hubId, userReq);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(createdUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_CREATED_SUCCESS_MSG)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<List<UserResponseBean>>> getUserByHubId(String hubId) {
|
||||
log.info("Get User by Hub ID - Hub ID: {}", hubId);
|
||||
List<UserResponseBean> user = userService.getUserByHubId(hubId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user