Search in sources :

Example 1 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResource method updateOperation.

/**
 * PUT  /operations : Updates an existing operation.
 *
 * @param operationDTO the operationDTO to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated operationDTO,
 * or with status 400 (Bad Request) if the operationDTO is not valid,
 * or with status 500 (Internal Server Error) if the operationDTO couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/operations")
@Timed
public ResponseEntity<OperationDTO> updateOperation(@Valid @RequestBody OperationDTO operationDTO) throws URISyntaxException {
    log.debug("REST request to update Operation : {}", operationDTO);
    if (operationDTO.getId() == null) {
        return createOperation(operationDTO);
    }
    Operation operation = operationMapper.toEntity(operationDTO);
    operation = operationRepository.save(operation);
    OperationDTO result = operationMapper.toDto(operation);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, operationDTO.getId().toString())).body(result);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResource method getAllOperations.

/**
 * GET  /operations : get all the operations.
 *
 * @param pageable the pagination information
 * @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many)
 * @return the ResponseEntity with status 200 (OK) and the list of operations in body
 */
@GetMapping("/operations")
@Timed
public ResponseEntity<List<OperationDTO>> getAllOperations(Pageable pageable, @RequestParam(required = false, defaultValue = "false") boolean eagerload) {
    log.debug("REST request to get a page of Operations");
    Page<OperationDTO> page;
    if (eagerload) {
        page = operationRepository.findAllWithEagerRelationships(pageable).map(operationMapper::toDto);
    } else {
        page = operationRepository.findAll(pageable).map(operationMapper::toDto);
    }
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, String.format("/api/operations?eagerload=%b", eagerload));
    return new ResponseEntity<>(operationMapper.toDto(page.getContent()), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method createOperation.

@Test
@Transactional
public void createOperation() throws Exception {
    int databaseSizeBeforeCreate = operationRepository.findAll().size();
    // Create the Operation
    OperationDTO operationDTO = operationMapper.toDto(operation);
    restOperationMockMvc.perform(post("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isCreated());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeCreate + 1);
    Operation testOperation = operationList.get(operationList.size() - 1);
    assertThat(testOperation.getDate()).isEqualTo(DEFAULT_DATE);
    assertThat(testOperation.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testOperation.getAmount()).isEqualTo(DEFAULT_AMOUNT);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method checkDateIsRequired.

@Test
@Transactional
public void checkDateIsRequired() throws Exception {
    int databaseSizeBeforeTest = operationRepository.findAll().size();
    // set the field null
    operation.setDate(null);
    // Create the Operation, which fails.
    OperationDTO operationDTO = operationMapper.toDto(operation);
    restOperationMockMvc.perform(post("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isBadRequest());
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeTest);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method updateOperation.

@Test
@Transactional
public void updateOperation() throws Exception {
    // Initialize the database
    operationRepository.saveAndFlush(operation);
    int databaseSizeBeforeUpdate = operationRepository.findAll().size();
    // Update the operation
    Operation updatedOperation = operationRepository.findById(operation.getId()).get();
    // Disconnect from session so that the updates on updatedOperation are not directly saved in db
    em.detach(updatedOperation);
    updatedOperation.setDate(UPDATED_DATE);
    updatedOperation.setDescription(UPDATED_DESCRIPTION);
    updatedOperation.setAmount(UPDATED_AMOUNT);
    OperationDTO operationDTO = operationMapper.toDto(updatedOperation);
    restOperationMockMvc.perform(put("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isOk());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeUpdate);
    Operation testOperation = operationList.get(operationList.size() - 1);
    assertThat(testOperation.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testOperation.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testOperation.getAmount()).isEqualTo(UPDATED_AMOUNT);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OperationDTO (io.github.jhipster.sample.service.dto.OperationDTO)10 Operation (io.github.jhipster.sample.domain.Operation)8 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Timed (com.codahale.metrics.annotation.Timed)3 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1