Команда получить продукт по id
This commit is contained in:
parent
5b95fff14d
commit
2ffcca7eeb
@ -0,0 +1,29 @@
|
||||
package me.zinch.Lab6.Client.commands;
|
||||
|
||||
import me.zinch.Lab6.Client.client.Client;
|
||||
import me.zinch.Lab6.Client.console.Console;
|
||||
import me.zinch.Lab6.Client.exceptions.CommandActionException;
|
||||
import me.zinch.Lab6.Domain.dto.BodyfulMessage;
|
||||
import me.zinch.Lab6.Domain.dto.BodylessMessage;
|
||||
import me.zinch.Lab6.Domain.dto.MessageType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GetProductById extends Command {
|
||||
public GetProductById() {
|
||||
super("get_product_by_id {element}", "", Pattern.compile("^get_product_by_id +."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String action(Client client) throws CommandActionException {
|
||||
try {
|
||||
Long id = Long.parseLong(Console.getLastCommand().split(" ")[1]);
|
||||
var response = (BodylessMessage) client.sendMessage(new BodyfulMessage(MessageType.POST, Console.getLastCommand(), id));
|
||||
if (response.getType() == MessageType.ERROR) throw new CommandActionException(response.getBody().toString());
|
||||
return response.getBody().toString();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
throw new CommandActionException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user