package hu.rbr.sfinapp.account;

import hu.rbr.sfinapp.account.command.CreateAccountCommand;
import hu.rbr.sfinapp.account.command.DeleteAccountCommand;
import hu.rbr.sfinapp.account.command.UpdateAccountCommand;
import hu.rbr.sfinapp.core.cache.ETagResponseBuilder;
import hu.rbr.sfinapp.core.command.CommandExecutor;

import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("accounts")
@Produces(MediaType.APPLICATION_JSON)
public class AccountResource {

	private final AccountQueryService service;
	private final CommandExecutor commandExecutor;
	private final ETagResponseBuilder eTagResponseBuilder;

	@Inject
	public AccountResource(AccountQueryService service, CommandExecutor commandExecutor, ETagResponseBuilder eTagResponseBuilder) {
		this.service = service;
		this.commandExecutor = commandExecutor;
		this.eTagResponseBuilder = eTagResponseBuilder;
	}

	@GET
	public Response getAll() {
		return eTagResponseBuilder.build(service::getVersion, service::getAll);
	}
	
	@GET
	@Path("/{id}")
	public Response getById(@PathParam("id") int id) {
		return eTagResponseBuilder.build(service::getVersion, () -> service.get(id));
	}

	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public void create(CreateAccountCommand command) {
		commandExecutor.execute(command);
	}
	
	@PUT
	@Path("/{id}")
	@Consumes(MediaType.APPLICATION_JSON)
	public void update(@PathParam("id") int id, UpdateAccountCommand command) {
        command.id = id;
		commandExecutor.execute(command);
	}
	
	@DELETE
	@Path("/{id}")
	public void delete(@PathParam("id") Integer id) {
		commandExecutor.execute(new DeleteAccountCommand(id));
	}

}

@@ -1255,20 +1255,24 @@
 %09public 
-void
+Response
  create(
@@ -1330,32 +1330,65 @@
 xecute(command);
+%0A%0A%09%09return Response.ok().build();
 %0A%09%7D%0A%09%0A%09@PUT%0A%09@Pa
@@ -1446,20 +1446,24 @@
 %09public 
-void
+Response
  update(
@@ -1579,16 +1579,49 @@
 ommand);
+%0A%0A%09%09return Response.ok().build();
 %0A%09%7D%0A%09%0A%09@
@@ -1655,12 +1655,16 @@
 lic 
-void
+Response
  del
@@ -1750,19 +1750,52 @@
 ommand(id));
+%0A%0A%09%09return Response.ok().build();
 %0A%09%7D%0A%0A%7D%0A

Return successful response from api