Selaa lähdekoodia

Implement-cert-tb-customer-and-feature-upload-stamp

new-feature
Viet.LeQ2 1 vuosi sitten
vanhempi
commit
1e3452af22
14 muutettua tiedostoa jossa 333 lisäystä ja 43 poistoa
  1. BIN
      build/libs/smart-farm-0.0.1-SNAPSHOT.war
  2. +4
    -0
      src/main/java/vn/azteam/tpf/Constants/Constants.java
  3. +12
    -0
      src/main/java/vn/azteam/tpf/domain/TBCustomer.java
  4. +2
    -0
      src/main/java/vn/azteam/tpf/service/FileStorageService.java
  5. +31
    -1
      src/main/java/vn/azteam/tpf/service/TBCustomerQueryService.java
  6. +32
    -4
      src/main/java/vn/azteam/tpf/service/TBExampleStampQueryService.java
  7. +7
    -0
      src/main/java/vn/azteam/tpf/service/TBExampleStampService.java
  8. +11
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBCustomerDTO.java
  9. +64
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java
  10. +5
    -0
      src/main/java/vn/azteam/tpf/service/impl/FileStorageServiceImpl.java
  11. +37
    -0
      src/main/java/vn/azteam/tpf/service/impl/TBExampleStampServiceImpl.java
  12. +68
    -31
      src/main/java/vn/azteam/tpf/web/rest/TBCustomerResource.java
  13. +58
    -7
      src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java
  14. +2
    -0
      src/main/resources/config/liquibase/sql/20240305_add_column_cert_image_tb_customer.sql

BIN
build/libs/smart-farm-0.0.1-SNAPSHOT.war Näytä tiedosto


+ 4
- 0
src/main/java/vn/azteam/tpf/Constants/Constants.java Näytä tiedosto

@@ -29,6 +29,10 @@ public class Constants {

public static String ACTIVE_TYPE_END = "ACTIVE_TYPE_END";

public static String EXAMPLE_STAMP = "EXAMPLE_STAMP";

public static String CUSTOMER_CERT = "CUSTOMER_CERT";

public static enum ENUM_MENU_ALWAYS_SHOW {
DASHBOARD
}

+ 12
- 0
src/main/java/vn/azteam/tpf/domain/TBCustomer.java Näytä tiedosto

@@ -57,6 +57,9 @@ public class TBCustomer implements Serializable {
@Column(name = "api_key")
private String apiKey;

@Column(name = "certification_image")
private String certificationImage;

@ManyToOne
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private TBAddress tbAddress;
@@ -287,6 +290,15 @@ public class TBCustomer implements Serializable {
this.apiKey = apiKey;
}


public String getCertificationImage() {
return certificationImage;
}

public void setCertificationImage(String certificationImage) {
this.certificationImage = certificationImage;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

+ 2
- 0
src/main/java/vn/azteam/tpf/service/FileStorageService.java Näytä tiedosto

@@ -16,6 +16,8 @@ public interface FileStorageService {
*/
String storeFiles(String itemTimeLineId, MultipartFile[] files);

String storeSingleFile(String itemTimeLineId, MultipartFile file);


/**
* Remove uploaded files

+ 31
- 1
src/main/java/vn/azteam/tpf/service/TBCustomerQueryService.java Näytä tiedosto

@@ -2,6 +2,7 @@ package vn.azteam.tpf.service;

import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import javax.persistence.EntityManager;
@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;

import io.github.jhipster.service.QueryService;
import io.github.jhipster.service.filter.LongFilter;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.domain.TBCustomer;
import vn.azteam.tpf.domain.*; // for static metamodels
import vn.azteam.tpf.repository.TBCustomerRepository;
@@ -48,6 +50,8 @@ public class TBCustomerQueryService extends QueryService<TBCustomer> {

private final TBCustomerSearchRepository tBCustomerSearchRepository;

private final FileStorageService fileStorageService;

private final TBCustomerService tBCustomerService;

private final TBAddressService tBAddressService;
@@ -56,10 +60,11 @@ public class TBCustomerQueryService extends QueryService<TBCustomer> {

private final EntityManager em;

public TBCustomerQueryService(TBCustomerRepository tBCustomerRepository, TBCustomerMapper tBCustomerMapper, TBCustomerSearchRepository tBCustomerSearchRepository, TBCustomerService tBCustomerService, TBAddressService tBAddressService, UserService userService, EntityManager em) {
public TBCustomerQueryService(TBCustomerRepository tBCustomerRepository, TBCustomerMapper tBCustomerMapper, TBCustomerSearchRepository tBCustomerSearchRepository, FileStorageService fileStorageService, TBCustomerService tBCustomerService, TBAddressService tBAddressService, UserService userService, EntityManager em) {
this.tBCustomerRepository = tBCustomerRepository;
this.tBCustomerMapper = tBCustomerMapper;
this.tBCustomerSearchRepository = tBCustomerSearchRepository;
this.fileStorageService = fileStorageService;
this.tBCustomerService = tBCustomerService;
this.tBAddressService = tBAddressService;
this.userService = userService;
@@ -192,6 +197,31 @@ public class TBCustomerQueryService extends QueryService<TBCustomer> {
return tBCustomerService.save(tBCustomerDTO);
}

@Transactional()
public TBCustomerDTO updateCustomerWithCertImage(TBCustomerDTO tBCustomerDTO,
MultipartFile file, String path){
Optional<UserDTO> currentUser = userService.getCurrentUserDTO();
String imagePath;
if (null != file) {
if (Objects.equals(file.getOriginalFilename(), "")) {
tBCustomerDTO.setCertificationImage(tBCustomerDTO.getCertificationImage());
} else {
imagePath = this.fileStorageService.storeSingleFile(path, file);
if (tBCustomerDTO.getCertificationImage() != null &&
!tBCustomerDTO.getCertificationImage().equals("")) {
tBCustomerDTO.setCertificationImage(imagePath);
} else {
tBCustomerDTO.setCertificationImage(imagePath);
}
}
} else {
tBCustomerDTO.setCertificationImage(tBCustomerDTO.getCertificationImage());
}
tBCustomerDTO.setModifiedById(currentUser.get().getId());
tBCustomerDTO.setModifiedDate(Instant.now());
return tBCustomerService.save(tBCustomerDTO);
}

@Transactional()
public TBCustomerDTO updateCustomer(TBCustomerDTO tBCustomerDTO){
Optional<UserDTO> currentUser = userService.getCurrentUserDTO();

+ 32
- 4
src/main/java/vn/azteam/tpf/service/TBExampleStampQueryService.java Näytä tiedosto

@@ -7,7 +7,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.domain.TBDetailUser;
import vn.azteam.tpf.domain.TBDetailUser_;
import vn.azteam.tpf.domain.TBExampleStamp;
@@ -19,6 +21,7 @@ import vn.azteam.tpf.service.mapper.TBExampleStampMapper;

import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import java.util.Objects;

@Service
@Transactional(readOnly = true)
@@ -28,11 +31,16 @@ public class TBExampleStampQueryService extends QueryService<TBExampleStamp> {

private final TBExampleStampRepository tBExampleStampRepository;

private final TBExampleStampMapper TBExampleStampMapper;
private final TBExampleStampMapper tBExampleStampMapper;

public TBExampleStampQueryService(TBExampleStampRepository tBExampleStampRepository, vn.azteam.tpf.service.mapper.TBExampleStampMapper tbExampleStampMapper) {
private final FileStorageService fileStorageService;

public TBExampleStampQueryService(TBExampleStampRepository tBExampleStampRepository,
TBExampleStampMapper tbExampleStampMapper,
FileStorageService fileStorageService) {
this.tBExampleStampRepository = tBExampleStampRepository;
TBExampleStampMapper = tbExampleStampMapper;
this.tBExampleStampMapper = tbExampleStampMapper;
this.fileStorageService = fileStorageService;
}

@Transactional(readOnly = true)
@@ -40,7 +48,7 @@ public class TBExampleStampQueryService extends QueryService<TBExampleStamp> {
log.debug("find by criteria : {}, page: {}", criteria, page);
final Specification<TBExampleStamp> specification = createSpecification(criteria);
return tBExampleStampRepository.findAll(specification, page)
.map(TBExampleStampMapper::toDto);
.map(tBExampleStampMapper::toDto);
}


@@ -128,4 +136,24 @@ public class TBExampleStampQueryService extends QueryService<TBExampleStamp> {
}
return specification;
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
public TBExampleStampDTO saveUploadedFile(TBExampleStampDTO tbExampleStampDTO, MultipartFile file, String path) {
String imagePath;
if (null != file) {
if (Objects.equals(file.getOriginalFilename(), "")) {
tbExampleStampDTO.setExampleStampImage(tbExampleStampDTO.getExampleStampImage());
} else {
imagePath = this.fileStorageService.storeSingleFile(path, file);
if (tbExampleStampDTO.getExampleStampImage() != null && !tbExampleStampDTO.getExampleStampImage().equals("")) {
tbExampleStampDTO.setExampleStampImage(imagePath);
} else {
tbExampleStampDTO.setExampleStampImage(imagePath);
}
}
} else {
tbExampleStampDTO.setExampleStampImage(tbExampleStampDTO.getExampleStampImage());
}
return tbExampleStampDTO;
}
}

+ 7
- 0
src/main/java/vn/azteam/tpf/service/TBExampleStampService.java Näytä tiedosto

@@ -0,0 +1,7 @@
package vn.azteam.tpf.service;

import vn.azteam.tpf.service.dto.TBExampleStampDTO;

public interface TBExampleStampService {
TBExampleStampDTO save(TBExampleStampDTO tBExampleStampDTO);
}

+ 11
- 0
src/main/java/vn/azteam/tpf/service/dto/TBCustomerDTO.java Näytä tiedosto

@@ -59,6 +59,8 @@ public class TBCustomerDTO implements Serializable {

private String apiKey;

private String certificationImage;

public Long getId() {
return id;
}
@@ -235,6 +237,15 @@ public class TBCustomerDTO implements Serializable {
this.apiKey = apiKey;
}


public String getCertificationImage() {
return certificationImage;
}

public void setCertificationImage(String certificationImage) {
this.certificationImage = certificationImage;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

+ 64
- 0
src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java Näytä tiedosto

@@ -19,4 +19,68 @@ public class TBExampleStampCreationDTO implements Serializable {
private Integer size;

private String exampleStampImage;

public String getExampleStampName() {
return exampleStampName;
}

public void setExampleStampName(String exampleStampName) {
this.exampleStampName = exampleStampName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}

public Integer getHeight() {
return height;
}

public void setHeight(Integer height) {
this.height = height;
}

public Integer getX() {
return x;
}

public void setX(Integer x) {
this.x = x;
}

public Integer getY() {
return y;
}

public void setY(Integer y) {
this.y = y;
}

public Integer getSize() {
return size;
}

public void setSize(Integer size) {
this.size = size;
}

public String getExampleStampImage() {
return exampleStampImage;
}

public void setExampleStampImage(String exampleStampImage) {
this.exampleStampImage = exampleStampImage;
}
}

+ 5
- 0
src/main/java/vn/azteam/tpf/service/impl/FileStorageServiceImpl.java Näytä tiedosto

@@ -76,6 +76,11 @@ public class FileStorageServiceImpl implements FileStorageService {
.collect(Collectors.joining( ";" ));
}

@Override
public String storeSingleFile(String itemTimeLineId, MultipartFile file) {
return this.storeFile(itemTimeLineId, file);
}

/**
* Remove file
* @param itemTimeLineId

+ 37
- 0
src/main/java/vn/azteam/tpf/service/impl/TBExampleStampServiceImpl.java Näytä tiedosto

@@ -0,0 +1,37 @@
package vn.azteam.tpf.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vn.azteam.tpf.domain.TBExampleStamp;
import vn.azteam.tpf.repository.TBExampleStampRepository;
import vn.azteam.tpf.service.TBExampleStampService;
import vn.azteam.tpf.service.dto.TBExampleStampDTO;
import vn.azteam.tpf.service.mapper.TBExampleStampMapper;

@Service
@Transactional
public class TBExampleStampServiceImpl implements TBExampleStampService {

private final Logger log = LoggerFactory.getLogger(TBExampleStampServiceImpl.class);

private final TBExampleStampRepository tbExampleStampRepository;

private final TBExampleStampMapper tBExampleStampMapper;

public TBExampleStampServiceImpl(TBExampleStampRepository tbExampleStampRepository, TBExampleStampMapper tBExampleStampMapper) {
this.tbExampleStampRepository = tbExampleStampRepository;
this.tBExampleStampMapper = tBExampleStampMapper;
}

@Override
public TBExampleStampDTO save(TBExampleStampDTO tBExampleStampDTO) {
log.debug("Request to save TBExampleStampDTO : {}", tBExampleStampDTO);

TBExampleStamp tbExampleStamp = tBExampleStampMapper.toEntity(tBExampleStampDTO);

tbExampleStamp = tbExampleStampRepository.save(tbExampleStamp);
return tBExampleStampMapper.toDto(tbExampleStamp);
}
}

+ 68
- 31
src/main/java/vn/azteam/tpf/web/rest/TBCustomerResource.java Näytä tiedosto

@@ -1,9 +1,22 @@
package vn.azteam.tpf.web.rest;

import com.codahale.metrics.annotation.Timed;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.Constants.Constants;
import vn.azteam.tpf.service.TBCustomerQueryService;
import vn.azteam.tpf.service.TBCustomerService;
import vn.azteam.tpf.service.TBRoleService;
import vn.azteam.tpf.service.UserService;
import vn.azteam.tpf.service.dto.TBCustomerCriteria;
import vn.azteam.tpf.service.dto.TBCustomerDTO;
import vn.azteam.tpf.service.dto.TBRoleDTO;
import vn.azteam.tpf.service.dto.UserDTO;
import vn.azteam.tpf.service.util.UserRoleUtil;
@@ -11,24 +24,12 @@ import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
import vn.azteam.tpf.web.rest.errors.ForbiddenException;
import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.service.dto.TBCustomerDTO;
import vn.azteam.tpf.service.dto.TBCustomerCriteria;
import vn.azteam.tpf.service.TBCustomerQueryService;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

/**
@@ -80,9 +81,11 @@ public class TBCustomerResource {
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result);
}
public String createApiKey(){

public String createApiKey() {
return UUID.randomUUID().toString();
}

/**
* PUT /tb-customers : Updates an existing tBCustomer.
*
@@ -105,22 +108,55 @@ public class TBCustomerResource {
.body(result);
}

@PutMapping("/tb-customers/{customerId}/upload-cert")
@Timed
public ResponseEntity<TBCustomerDTO> updateTBCustomer(@PathVariable Long customerId,
@RequestPart("file") MultipartFile file) throws URISyntaxException {
log.debug("REST request to update TBCustomer id : {}", customerId);
if (file.isEmpty()) {
throw new BadRequestAlertException("File upload ", ENTITY_NAME, "is not null");
}
if (customerId == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
Optional<TBCustomerDTO> tbCustomerDTOOptional = tBCustomerService.findOne(customerId);
if (!tbCustomerDTOOptional.isPresent()) {
throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "customernotfound");
}

UserDTO currentUser = userService.getCurrentUserDTO().get();
// if(currentUser.getCustomerId() != null && !currentUser.getCustomerId().equals(customerId)){
// throw new ForbiddenException();
// }
// if (currentUser.getCustomerId() != null) {
// throw new ForbiddenException();
// }
// String apiKeyNew = this.createApiKey();
TBCustomerDTO tbCustomerDTO = tbCustomerDTOOptional.get();
//tbCustomerDTO.setCertificationImage(apiKeyNew);
TBCustomerDTO result = tBCustomerQueryService.updateCustomerWithCertImage(tbCustomerDTO,
file, Constants.EXAMPLE_STAMP);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tbCustomerDTO.getId().toString()))
.body(result);
}

@PutMapping("/tb-customers-api-key/{customerId}")
@Timed
public ResponseEntity<TBCustomerDTO> updateTBCustomerApiKey(@PathVariable Long customerId) {
log.debug("REST request to update Api-Key TBCustomer");
if (customerId == null){
if (customerId == null) {
throw new BadRequestAlertException("Invalid customer", ENTITY_NAME, "customeridnull");
}
Optional<TBCustomerDTO> tbCustomerDTOOptional = tBCustomerService.findOne(customerId);
if (!tbCustomerDTOOptional.isPresent()){
if (!tbCustomerDTOOptional.isPresent()) {
throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "customernotfound");
}
UserDTO currentUser = userService.getCurrentUserDTO().get();
// if(currentUser.getCustomerId() != null && !currentUser.getCustomerId().equals(customerId)){
// throw new ForbiddenException();
// }
if (currentUser.getCustomerId() != null){
if (currentUser.getCustomerId() != null) {
throw new ForbiddenException();
}
String apiKeyNew = this.createApiKey();
@@ -131,6 +167,7 @@ public class TBCustomerResource {
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tbCustomerDTO.getId().toString()))
.body(result);
}

/**
* GET /tb-customers : get all the tBCustomers.
*
@@ -156,17 +193,17 @@ public class TBCustomerResource {
*/
@GetMapping("/tb-customers-dropdown-list/{roleId}")
@Timed
public ResponseEntity<List<TBCustomerDTO>> getAllTBCustomersByRoleId(@PathVariable Long roleId,TBCustomerCriteria criteria, Pageable pageable) {
public ResponseEntity<List<TBCustomerDTO>> getAllTBCustomersByRoleId(@PathVariable Long roleId, TBCustomerCriteria criteria, Pageable pageable) {
log.debug("REST request to get TBCustomers by criteria: {}", criteria);
UserDTO currentUser = userService.getCurrentUserDTO().get();
TBRoleDTO roleDTO = tbRoleService.findOne(roleId).get();

Page<TBCustomerDTO> page = tBCustomerQueryService.findByCriteria(criteria, pageable);
List<TBCustomerDTO> result = page.getContent();
if(currentUser.getCustomerId() != null){
if (currentUser.getCustomerId() != null) {
result = page.getContent().stream()
.filter(item -> item.getId().equals(currentUser.getCustomerId()))
.collect(Collectors.toList());
.collect(Collectors.toList());
} else {
if (!roleDTO.getIsAllCustomer()) {
result = page.getContent().stream()
@@ -179,11 +216,11 @@ public class TBCustomerResource {
}

/**
* GET /tb-customers/count : count all the tBCustomers.
*
* @param criteria the criterias which the requested entities should match
* @return the ResponseEntity with status 200 (OK) and the count in body
*/
* GET /tb-customers/count : count all the tBCustomers.
*
* @param criteria the criterias which the requested entities should match
* @return the ResponseEntity with status 200 (OK) and the count in body
*/
@GetMapping("/tb-customers/count")
@Timed
public ResponseEntity<Long> countTBCustomers(TBCustomerCriteria criteria) {
@@ -215,7 +252,7 @@ public class TBCustomerResource {
public ResponseEntity<TBCustomerDTO> getTBCustomerByCurrentUser() {

UserDTO currentUser = userService.getCurrentUserDTO().get();
if(currentUser.getCustomerId() != null) {
if (currentUser.getCustomerId() != null) {
Optional<TBCustomerDTO> tBCustomerDTO = tBCustomerService.findOne(currentUser.getCustomerId());
return ResponseUtil.wrapOrNotFound(tBCustomerDTO);
}
@@ -240,18 +277,18 @@ public class TBCustomerResource {
* SEARCH /_search/tb-customers?query=:query : search for the tBCustomer corresponding
* to the query.
*
* @param query the query of the tBCustomer search
* @param query the query of the tBCustomer search
* @param pageable the pagination information
* @return the result of the search
*/
@GetMapping("/_search/tb-customers")
@Timed
public ResponseEntity<List<TBCustomerDTO>> searchTBCustomers(@RequestParam String query, @RequestParam String status, Pageable pageable) {
public ResponseEntity<List<TBCustomerDTO>> searchTBCustomers(@RequestParam String query, @RequestParam String status, Pageable pageable) {
log.debug("REST request to search for a page of TBCustomers for query {}", query);
UserDTO currentUser = userService.getCurrentUserDTO().get();
if (currentUser.getCustomerId() != null) {
Page<TBCustomerDTO> page;
if((query != null && !query.isEmpty()) | (status != null && !status.isEmpty())) {
if ((query != null && !query.isEmpty()) | (status != null && !status.isEmpty())) {
page = tBCustomerQueryService.searchCustomer(query, status, pageable);
} else {
page = tBCustomerService.search(query, pageable);

+ 58
- 7
src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java Näytä tiedosto

@@ -2,7 +2,6 @@ package vn.azteam.tpf.web.rest;


import com.codahale.metrics.annotation.Timed;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
@@ -10,23 +9,25 @@ import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vn.azteam.tpf.domain.TBCodeStatusEnum;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.Constants.Constants;
import vn.azteam.tpf.service.TBExampleStampQueryService;
import vn.azteam.tpf.service.TBExampleStampService;
import vn.azteam.tpf.service.UserService;
import vn.azteam.tpf.service.dto.*;
import vn.azteam.tpf.service.dto.TBExampleStampCreationDTO;
import vn.azteam.tpf.service.dto.TBExampleStampCriteria;
import vn.azteam.tpf.service.dto.TBExampleStampDTO;
import vn.azteam.tpf.service.dto.UserDTO;
import vn.azteam.tpf.service.util.PageableUtil;
import vn.azteam.tpf.service.util.UserRoleUtil;
import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.web.rest.util.RandomStringUtil;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@@ -41,14 +42,18 @@ public class TBExampleStampResource {

private final UserRoleUtil userRoleUtil;

private final TBExampleStampService tBExampleStampService;

private final UserService userService;

private final PageableUtil pageableUtil;

public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil, UserService userService, PageableUtil pageableUtil){
public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil,
TBExampleStampService tBExampleStampService, UserService userService, PageableUtil pageableUtil) {

this.tBExampleStampQueryService = tBExampleStampQueryService;
this.userRoleUtil = userRoleUtil;
this.tBExampleStampService = tBExampleStampService;
this.userService = userService;
this.pageableUtil = pageableUtil;
}
@@ -100,4 +105,50 @@ public class TBExampleStampResource {
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-example-stamp");
return ResponseEntity.ok().headers(headers).body(pageResult.getContent());
}

@PostMapping("/tb-example-stamp")
public ResponseEntity<TBExampleStampDTO> create(@RequestPart("data") TBExampleStampCreationDTO tbExampleStampCreationDTO,
@RequestPart("file") MultipartFile file) {

UserDTO currentUser = userService.getCurrentUserDTO().get();
if (file.isEmpty()) {
throw new BadRequestAlertException("1019", ENTITY_NAME, "1019");
}

try {
TBExampleStampDTO tbExampleStampDTO = new TBExampleStampDTO();
tbExampleStampDTO.setY(tbExampleStampCreationDTO.getY());
tbExampleStampDTO.setX(tbExampleStampCreationDTO.getX());
tbExampleStampDTO.setWidth(tbExampleStampCreationDTO.getWidth());
tbExampleStampDTO.setHeight(tbExampleStampCreationDTO.getHeight());
tbExampleStampDTO.setDescription(tbExampleStampCreationDTO.getDescription());
tbExampleStampDTO.setExampleStampName("");
tbExampleStampDTO.setSize(tbExampleStampCreationDTO.getSize());

tbExampleStampDTO.setCreatedDate(Instant.now());
tbExampleStampDTO.setCreatedById(currentUser.getUserId());

TBExampleStampDTO result = null;
Boolean hasViolationException = false;
do {
try {
tbExampleStampDTO = tBExampleStampQueryService.saveUploadedFile(tbExampleStampDTO, file, Constants.EXAMPLE_STAMP);
result = tBExampleStampService.save(tbExampleStampDTO);
} catch (org.springframework.dao.DataIntegrityViolationException ex) {
if (ex.getMessage().contains("ux_tb_example_stamp")) {
hasViolationException = true;
} else {
throw ex;
}
}
}
while (hasViolationException);

return ResponseEntity.created(new URI("/api/tb-example-stamp/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result);
} catch (Exception exception) {
throw new RuntimeException();
}
}
}

+ 2
- 0
src/main/resources/config/liquibase/sql/20240305_add_column_cert_image_tb_customer.sql Näytä tiedosto

@@ -0,0 +1,2 @@
ALTER TABLE tb_customer
ADD certification_image varchar(255) null;

Loading…
Peruuta
Tallenna