The question I have might not be specific enough initially but I will try to offer more details.
I am building a Spring Boot application that makes calls to Facebook Graph API and News API. So far my structure has:
.
└── com
└── psyonik
└── FBAccess
├── config
│ └── SecurityConfig.java
├── controller
│ └── HomeController.java
├── dao
├── entity
│ ├── Feed.java
│ ├── Paging.java
│ ├── Post.java
│ └── User.java
├── FbAccessApplication.java
└── service
└── NewsLoaderService.java
The controller just now is a simple test controller where I am checking the outputs to the requests I make to the Graph API. The config holds the security configuration for the OAuth2 Facebook Login, the DAO folder will eventually hold the repositories that will save the responses to a db, entity folder holds the entities that represent the response objects and service is where the 'business logic' should sit.
Now at this point, I make the calls to the Graph API in the controller directly. Where should these calls ideally be made, as in, in what part of the application?
Should the Service folder hold a FacebookAPIService class that makes a call to the Graph API, builds a Feed object and returns a list of items for example and then the methods of the class are called in the controller instead of making the calls, buildings the objects and so in the controller?
I understand that in the DAO folder I would keep my JpaRepositories, then in the Service folder I would have a FacebookService and a FacebookServiceImpl that would hold the methods for talking to a database, but I wanted to clarify if the service could also hold the calls to the graph API.
My main question would be, in an Spring Boot application where calls are made to an API, where data is written/read from a DB and data is generated and displayed dynamically to a website based on either the API/DB, how would you structure this?
To further add on, the responses from the Graph API would be used to create new calls to the News API (e.g. "User A posted something on the 5th of November, what news articles were posted on AlJazeera on the 5th of November and then combine the two responses into a new class that would then be called and displayed on the page"). I could make all of these calls in the Controller.... but that's just bad.
These are typically called services. So create a services package and have them in there. If there would be multiple services related to the same thing you could then group them in there too. So if you see you need more FB related services that logically deal with different actions, then you could have them in different services but all under services.facebook like: services.facebook.FacebookAuthService.java adn services.facebook.FacebookGraphService.java