#change architecture/method so it can work with two similar DTOs

1 messages · Page 1 of 1 (latest)

quick coral
#

hi guys. so i have a method validateRequest. and i want to do changes in my code so it can be called twice, from two different places:
perlasService.validateRequest(perlasIdCheckRequestDTO); and
perlasService.validateRequest(perlasSaleRequestDTO);

Now my PerlasIdCheckRequestDTO is: https://pastecode.io/s/c3a9kmkq

PerlasSaleRequestDTO is: https://pastecode.io/s/u9um8pzr

and validateRequest is: https://pastecode.io/s/1iqnm5x5

And the thing is that idk how to design/change my DTOs ir validateRequest method. Can smb help me out? thanks

oak graniteBOT
#

<@&987246841693360200> please have a look, thanks.

neat rune
#

Generally speaking they'd need to have a common parent class. I'd expect the former to be an ID element of the latter.

worldly needle
#

@quick coral
To modify the validateRequest method to work with both PerlasIdCheckRequestDTO and PerlasSaleRequestDTO, we need to make it more generic. This includes redesigning the DTOs or using a common interface or superclass that both DTOs can implement or extend

Create a common interface :
public interface ValidatableRequest { String getUserId(); String getTransactionId(); }

oak graniteBOT