Hi there. I don't know if "DTO" is the right word to describe what I'm talking about, but...
I have a Discord bot which is also hosting an API to allow other bots/platforms/applications to interact with the bot for some features in a TOS-abiding way. At the present moment, my DB models also have logic attached to them, which I plan to separate in some way to keep the models themselves tidy and readable.
I've been told it's not a best practice to return/serve DB models directly as JSON in API calls, so I am looking to avoid doing that via, what I believe would be DTOs. How do I avoid the unnecessary code duplication in what would effectively be a copy of the model class(es) in the API? My main concern is, even if I couldn't avoid it, any changes to DB models would require me to remember to make an identical modification where appropriate to the API DTOs. This is not something I'd prefer as my current setup already suffers from that issue.
Any suggestions or ideas are welcome. At the moment, I don't see a huge need for DTOs on my bot side of things as I'd be doing the data manipulation behind the scenes and Discord bots don't exactly return data like APIs do...but I do have some pretty complicated logic attached to the current models that I'd either have to extract as extension methods or DTOs...for a second time (bot DTOs / API DTOs)