Search in sources :

Example 6 with Agent

use of com.arnaugarcia.uplace.domain.Agent in project uplace.es by Uplace.

the class AgentResource method getAgent.

/**
 * GET  /agents/:id : get the "id" agent.
 *
 * @param id the id of the agent to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the agent, or with status 404 (Not Found)
 */
@GetMapping("/agents/{id}")
@Timed
public ResponseEntity<Agent> getAgent(@PathVariable Long id) {
    log.debug("REST request to get Agent : {}", id);
    Agent agent = agentService.findOne(id);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(agent));
}
Also used : Agent(com.arnaugarcia.uplace.domain.Agent) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with Agent

use of com.arnaugarcia.uplace.domain.Agent in project uplace.es by Uplace.

the class AgentResource method createAgent.

/**
 * POST  /agents : Create a new agent.
 *
 * @param agent the agent to create
 * @return the ResponseEntity with status 201 (Created) and with body the new agent, or with status 400 (Bad Request) if the agent has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/agents")
@Timed
public ResponseEntity<Agent> createAgent(@Valid @RequestBody Agent agent) throws URISyntaxException {
    log.debug("REST request to save Agent : {}", agent);
    if (agent.getId() != null) {
        throw new BadRequestAlertException("A new agent cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Agent result = agentService.save(agent);
    return ResponseEntity.created(new URI("/api/agents/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Agent(com.arnaugarcia.uplace.domain.Agent) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 8 with Agent

use of com.arnaugarcia.uplace.domain.Agent in project uplace.es by Uplace.

the class AgentResource method updateAgent.

/**
 * PUT  /agents : Updates an existing agent.
 *
 * @param agent the agent to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated agent,
 * or with status 400 (Bad Request) if the agent is not valid,
 * or with status 500 (Internal Server Error) if the agent couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/agents")
@Timed
public ResponseEntity<Agent> updateAgent(@Valid @RequestBody Agent agent) throws URISyntaxException {
    log.debug("REST request to update Agent : {}", agent);
    if (agent.getId() == null) {
        return createAgent(agent);
    }
    Agent result = agentService.save(agent);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, agent.getId().toString())).body(result);
}
Also used : Agent(com.arnaugarcia.uplace.domain.Agent) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Agent (com.arnaugarcia.uplace.domain.Agent)8 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Timed (com.codahale.metrics.annotation.Timed)3 Ignore (org.junit.Ignore)2 User (com.arnaugarcia.uplace.domain.User)1 BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1