I want to assign the logged-in user to the adminProfile field. Is it possible to do this without using userService in the CompanyController? I'm using JPA Repository
CompanyController
@Controller
@RequiredArgsConstructor
public class CompanyController {
private static final String COMPANY_PATH = "/companies";
private static final String COMPANY_PATH_ID = COMPANY_PATH + "/{companyId}";
private final CompanyService companyService;
@GetMapping(COMPANY_PATH + "/create")
public String creationForm(Model model) {
model.addAttribute("company", new CompanyDTO());
return "company_create";
}
@PostMapping(COMPANY_PATH + "/create")
public String createCompany(@ModelAttribute("company") CompanyDTO companyDTO) {
}
CompanyDTO
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CompanyDTO {
private Long id;
private String companyName;
private AppUser adminProfile;
}
I know that with userService here I can easily assign the user to adminProfile field, but I've read that using multiple services in a controller is considered bad practice