Business Scenario
In this lab, you will troubleshoot and resolve compilation and startup errors in the Medicare Spring Boot backend that appeared after introducing JWT authentication, role-based access control, and service-layer refactoring.
Problem 1 — Resolve Duplicate Appointment Endpoints & Outdated Controller Methods
package com.medicare.controller;
import java.util.List;
import com.medicare.dto.AppointmentResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import com.medicare.dto.AppointmentRequest;
import com.medicare.entity.Appointment;
import com.medicare.service.AppointmentService;
import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/appointments")
public class AppointmentController {
private final AppointmentService appointmentService;
public AppointmentController(
AppointmentService appointmentService) { this.appointmentService =
appointmentService;
}
@PostMapping
public ResponseEntity<AppointmentResponse>
createAppointment(
@Valid
@RequestBody
AppointmentRequest request,
Authentication authentication) {
AppointmentResponse response =
appointmentService
.createAppointment(
request,
authentication.getName()
);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(response);
}
@GetMapping
public ResponseEntity<List<Appointment>>
getAllAppointments() {
return ResponseEntity.ok(appointmentService.getAllAppointments());
} @GetMapping("/{id}")
public ResponseEntity<Appointment>
getAppointmentById(
@PathVariable Long id) {
return ResponseEntity.ok(
appointmentService
.getAppointmentById(id)
);
}
@GetMapping("/patient/{patientId}")
public ResponseEntity<List<Appointment>>
getAppointmentsByPatient(
@PathVariable Long patientId) {
return ResponseEntity.ok(
appointmentService.getAppointmentsByPatient(patientId)
);
}
@GetMapping("/doctor/{doctorId}")
public ResponseEntity<List<Appointment>>
getAppointmentsByDoctor(
@PathVariable Long doctorId) {
return ResponseEntity.ok( appointmentService
.getAppointmentsByDoctor(doctorId)
);
} @GetMapping("/my")
public ResponseEntity<List<AppointmentResponse>>
getMyAppointments(Authentication authentication) {
return ResponseEntity.ok(appointmentService
.getMyAppointments(authentication.getName())
);
}
@GetMapping("/{id}")
public ResponseEntity<AppointmentResponse>
getAppointmentById(@PathVariable Long id,Authentication authentication) {
return ResponseEntity.ok(
appointmentService
.getAppointmentById(id,authentication.getName())
);
}
@PatchMapping("/{id}/cancel")
public ResponseEntity<AppointmentResponse>
cancelAppointment( @PathVariable Long id,Authentication authentication) {
return ResponseEntity.ok(
appointmentService.cancelAppointment(id,authentication.getName())
);
}
@PatchMapping("/{id}/complete")
public ResponseEntity<AppointmentResponse>
completeAppointment(
@PathVariable Long id, Authentication authentication) { return ResponseEntity.ok(
appointmentService.completeAppointment(id,authentication.getName())
);
}
}
""
C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\controller
\AppointmentController.java:67:25
java: method getAppointmentById in class com.medicare.service.AppointmentService
cannot be applied to given types;
required: java.lang.Long,java.lang.String
found: java.lang.Long
reason: actual and formal argument lists differ in length
""getAppointmentById() requires two arguments but receives only one.
Duplicate GET /api/appointments/{id} mappings.
Old patient and doctor ID-based endpoints are still present.
The older Phase 5 appointment endpoints were not removed after the Phase 10 JWT-based refactoring.
You currently have two methods mapped to the exact same endpoint:
@GetMapping("/{id}")
public ResponseEntity<Appointment>
getAppointmentById(@PathVariable Long id) {
return ResponseEntity.ok(appointmentService.getAppointmentById(id) // ❌ OLD);
}and later:
@GetMapping("/{id}")
public ResponseEntity<AppointmentResponse>
getAppointmentById(@PathVariable Long id,Authentication authentication) {
return ResponseEntity.ok(appointmentService
.getAppointmentById(id,authentication.getName())
);
}The second one is the correct Phase 10 version.
So don't change your service back
Delete the old controller method.
There is another issue too: because both methods use:
@GetMapping("/{id}")Spring would eventually also complain about an ambiguous mapping even if the Java compilation issue were fixed.
Remove the old getAppointmentById(Long id) method.
Remove getAllAppointments().
Remove getAppointmentsByPatient(patientId).
Remove getAppointmentsByDoctor(doctorId).
Add the secure GET /doctor/me endpoint.
Keep the newer JWT-based appointment methods.
Remove the unused Appointment entity import.
Why? -> Because after JWT/RBAC we intentionally changed:
/api/appointments/patient/{patientId}to:
/api/appointments/my
and:
/api/appointments/doctor/{doctorId}/api/appointments/doctor/me
to:
You currently have:
GET /api/appointments/my
But this is not present :
GET /api/appointments/doctor/me
So add that as well.
package com.medicare.controller;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medicare.dto.AppointmentRequest;
import com.medicare.dto.AppointmentResponse;
import com.medicare.service.AppointmentService;
import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/appointments")
public class AppointmentController {
private final AppointmentService appointmentService;
public AppointmentController(
AppointmentService appointmentService) {
this.appointmentService = appointmentService; }
// -------------------------------------------------
// PATIENT - BOOK APPOINTMENT
// -------------------------------------------------
@PostMapping
public ResponseEntity<AppointmentResponse>
createAppointment(
@Valid
@RequestBody
AppointmentRequest request,
Authentication authentication) {
AppointmentResponse response =
appointmentService
.createAppointment(
request,
authentication.getName()
);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(response);
}
// -------------------------------------------------
// PATIENT - VIEW OWN APPOINTMENTS
// ------------------------------------------------- @GetMapping("/my")
public ResponseEntity<List<AppointmentResponse>>
getMyAppointments(
Authentication authentication) {
return ResponseEntity.ok(
appointmentService
.getMyAppointments(
authentication.getName()
)
);
}
// -------------------------------------------------
// DOCTOR - VIEW OWN APPOINTMENTS
// -------------------------------------------------
@GetMapping("/doctor/me")
public ResponseEntity<List<AppointmentResponse>>
getMyDoctorAppointments(
Authentication authentication) {
return ResponseEntity.ok(
appointmentService
.getMyDoctorAppointments(
authentication.getName()
)
);
} // -------------------------------------------------
// PATIENT / DOCTOR - VIEW APPOINTMENT DETAILS
// -------------------------------------------------
@GetMapping("/{id}")
public ResponseEntity<AppointmentResponse>
getAppointmentById(
@PathVariable Long id,
Authentication authentication) {
return ResponseEntity.ok(
appointmentService
.getAppointmentById(
id,
authentication.getName()
)
);
}
// -------------------------------------------------
// PATIENT - CANCEL OWN APPOINTMENT
// -------------------------------------------------
@PatchMapping("/{id}/cancel")
public ResponseEntity<AppointmentResponse>
cancelAppointment(
@PathVariable Long id,
Authentication authentication) { return ResponseEntity.ok(
appointmentService
.cancelAppointment(
id,
authentication.getName()
)
);
}
// -------------------------------------------------
// DOCTOR - COMPLETE ASSIGNED APPOINTMENT
// -------------------------------------------------
@PatchMapping("/{id}/complete")
public ResponseEntity<AppointmentResponse>
completeAppointment(
@PathVariable Long id,
Authentication authentication) {
return ResponseEntity.ok(
appointmentService
.completeAppointment(
id,
authentication.getName()
)
);
}
}Problem 2 — Fix Missing Helper Methods in AppointmentService
C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\service\AppointmentService.java:53:17 java: cannot find symbol symbol: method findUserByEmail(java.lang.String) location: class com.medicare.service.AppointmentService
The updated AppointmentService calls helper methods that were never added to the class.
Add these helper methods : Put all of these after mapToAppointmentResponse() and before the final } of AppointmentService:
private User findUserByEmail(String email) {
return userRepository.findByEmailIgnoreCase(email)
.orElseThrow(() ->
new UserNotFoundException("User not found")
);
}
private DoctorProfile findDoctorByUserId(
Long userId) {
return doctorRepository.findByUserId(userId)
.orElseThrow(() ->
new DoctorNotFoundException("Doctor profile not found")
);
}private Appointment findAppointmentById(
Long appointmentId) {
return appointmentRepository
.findById(appointmentId)
.orElseThrow(() ->
new AppointmentNotFoundException(
"Appointment not found with id: "+ appointmentId
)
);
}
private void verifyAppointmentAccess(Appointment appointment,User user) {
if (user.getRole() == Role.PATIENT) {
if (!appointment
.getPatient()
.getId()
.equals(user.getId())) {
throw new AccessDeniedException(
"You cannot access this appointment"
);
}
return;
}
if (user.getRole() == Role.DOCTOR) {
DoctorProfile doctor =
findDoctorByUserId(
user.getId()
);
if (!appointment.getDoctor().getId().equals(doctor.getId())) {
throw new AccessDeniedException(
"You cannot access this appointment"
);
}
}
}Also add this missing import
import org.springframework.security.access.AccessDeniedException;getAllAppointments()
getAppointmentsByPatient()
getAppointmentsByDoctor()
Keep the newer JWT-based methods for retrieving patient and doctor appointments.
Problem 3 — Remove Outdated Doctor CRUD Methods from DoctorController
package com.medicare.controller;
import java.math.BigDecimal;
import java.util.List;
import com.medicare.dto.DoctorPageResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.medicare.dto.DoctorProfileRequest;
import com.medicare.dto.DoctorResponse;
import com.medicare.service.DoctorService;
import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/doctors")
public class DoctorController {
private final DoctorService doctorService;
public DoctorController(
DoctorService doctorService) {
this.doctorService = doctorService;
}
@PostMapping
public ResponseEntity<DoctorResponse> createDoctor(@Valid @RequestBody DoctorProfileRequest request) {
DoctorResponse savedDoctor = doctorService.createDoctor(request);
return ResponseEntity.status(HttpStatus.CREATED).body(savedDoctor);
}
@GetMapping
public ResponseEntity<DoctorPageResponse>
searchDoctors(
@RequestParam(required = false)
String specialization,
@RequestParam(required = false)
BigDecimal maxFee,
@RequestParam(required = false)
String name,
@RequestParam(defaultValue = "0")
int page,
@RequestParam(defaultValue = "6")
int size,
@RequestParam(defaultValue = "consultationFee")
String sortBy,
@RequestParam(defaultValue = "asc")
String direction) {
DoctorPageResponse response =doctorService.searchDoctors(
specialization,maxFee,name,page,size,
sortBy,direction
);
return ResponseEntity.ok(response);
}
@GetMapping("/{id}")
public ResponseEntity<DoctorResponse>
getDoctorById(@PathVariable Long id) {
return ResponseEntity.ok(doctorService.getDoctorById(id));
}
@PutMapping("/{id}")
public ResponseEntity<DoctorResponse>
updateDoctor(@PathVariable Long id,@Valid @RequestBody
DoctorProfileRequest request) {
return ResponseEntity.ok(doctorService.updateDoctor(id,request)
);
}
@DeleteMapping("/{id}")
public ResponseEntity<Void>
deleteDoctor(@PathVariable Long id) {
doctorService.deleteDoctor(id);
return ResponseEntity.noContent().build();
}
@PostMapping("/profile")
public ResponseEntity<DoctorResponse>
createMyProfile(@Valid @RequestBody DoctorProfileRequest request,
Authentication authentication) {
DoctorResponse response = doctorService.createMyProfile(
request,authentication.getName()
);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}
@GetMapping("/profile/me")
public ResponseEntity<DoctorResponse>
getMyProfile(Authentication authentication) {
return ResponseEntity.ok(doctorService.getMyProfile(
authentication.getName()
)
);
}
@PutMapping("/profile/me")
public ResponseEntity<DoctorResponse>
updateMyProfile(
@Valid @RequestBody DoctorProfileRequest request,
Authentication authentication) {
return ResponseEntity.ok(
doctorService.updateMyProfile(
authentication.getName(),request
)
);
}
@DeleteMapping("/profile/me")
public ResponseEntity<Void>
deleteMyProfile(Authentication authentication) {
doctorService.deleteMyProfile(authentication.getName());
return ResponseEntity.noContent().build();
}
}
""
C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\controller\DoctorController.java:46:30
java: cannot find symbol
symbol: method createDoctor(@jakarta.validation.Valid com.medicare.dto.DoctorProfileRequest)
location: variable doctorService of type com.medicare.service.DoctorService
"" DoctorPageResponse response =doctorService.searchDoctors(
specialization,maxFee,name,page,size,
sortBy,direction
);
return ResponseEntity.ok(response);
}
@GetMapping("/{id}")
public ResponseEntity<DoctorResponse>
getDoctorById(@PathVariable Long id) {
return ResponseEntity.ok(doctorService.getDoctorById(id));
}
@PutMapping("/{id}")
public ResponseEntity<DoctorResponse>
updateDoctor(@PathVariable Long id,@Valid @RequestBody
DoctorProfileRequest request) {
return ResponseEntity.ok(doctorService.updateDoctor(id,request)
);
}
@DeleteMapping("/{id}")
public ResponseEntity<Void>
deleteDoctor(@PathVariable Long id) {
doctorService.deleteDoctor(id);
return ResponseEntity.noContent().build();
}
@PostMapping("/profile") public ResponseEntity<DoctorResponse>
createMyProfile(@Valid @RequestBody DoctorProfileRequest request,
Authentication authentication) {
DoctorResponse response = doctorService.createMyProfile(
request,authentication.getName()
);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}
@GetMapping("/profile/me")
public ResponseEntity<DoctorResponse>
getMyProfile(Authentication authentication) {
return ResponseEntity.ok(doctorService.getMyProfile(
authentication.getName()
)
);
}
@PutMapping("/profile/me")
public ResponseEntity<DoctorResponse>
updateMyProfile(
@Valid @RequestBody DoctorProfileRequest request,
Authentication authentication) {
return ResponseEntity.ok(
doctorService.updateMyProfile(
authentication.getName(),request
) );
}
@DeleteMapping("/profile/me")
public ResponseEntity<Void>
deleteMyProfile(Authentication authentication) {
doctorService.deleteMyProfile(authentication.getName());
return ResponseEntity.noContent().build();
}
}
""
C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\controller\
DoctorController.java:46:30 java: cannot find symbol symbol: method createDoctor(
@jakarta.validation.Valid com.medicare.dto.DoctorProfileRequest)
location: variable doctorService of type com.medicare.service.DoctorService ""cannot find symbol: method createDoctor(DoctorProfileRequest)
The DoctorController still calls the older createDoctor(), updateDoctor(), and deleteDoctor() service methods, which were removed during the JWT/RBAC refactoring.
POST /api/doctors
PUT /api/doctors/{id}
DELETE /api/doctors/{id}
Remove the old endpoints:
POST /api/doctors/profile
GET /api/doctors/profile/me
PUT /api/doctors/profile/me
DELETE /api/doctors/profile/me
authentication.getName().package com.medicare.controller;
import java.math.BigDecimal;
import com.medicare.dto.DoctorPageResponse;
import com.medicare.dto.DoctorProfileRequest;
import com.medicare.dto.DoctorResponse;
import com.medicare.service.DoctorService;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/doctors")
public class DoctorController {
private final DoctorService doctorService;
public DoctorController(
DoctorService doctorService) {
this.doctorService = doctorService;
}
// -------------------------------------------------
// SEARCH / FILTER / PAGINATION
// -------------------------------------------------
@GetMapping
public ResponseEntity<DoctorPageResponse>
searchDoctors(
@RequestParam(required = false)
String specialization,
@RequestParam(required = false)
BigDecimal maxFee,
@RequestParam(required = false)
String name,
@RequestParam(defaultValue = "0")
int page,
@RequestParam(defaultValue = "6")
int size,
@RequestParam(
defaultValue = "consultationFee"
)
String sortBy,
@RequestParam(defaultValue = "asc")
String direction) { DoctorPageResponse response =
doctorService.searchDoctors(
specialization,
maxFee,
name,
page,
size,
sortBy,
direction
);
return ResponseEntity.ok(response);
}
// -------------------------------------------------
// VIEW DOCTOR DETAILS
// -------------------------------------------------
@GetMapping("/{id}")
public ResponseEntity<DoctorResponse> getDoctorById(@PathVariable Long id) {
return ResponseEntity.ok(doctorService.getDoctorById(id));
}
// -------------------------------------------------
// DOCTOR - CREATE OWN PROFILE
// -------------------------------------------------
@PostMapping("/profile")
public ResponseEntity<DoctorResponse>
createMyProfile(
@Valid
@RequestBody
DoctorProfileRequest request,
Authentication authentication) {
DoctorResponse response =
doctorService.createMyProfile(
request,
authentication.getName()
);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(response);
}
// -------------------------------------------------
// DOCTOR - VIEW OWN PROFILE
// -------------------------------------------------
@GetMapping("/profile/me")
public ResponseEntity<DoctorResponse>
getMyProfile(Authentication authentication) {
return ResponseEntity.ok(doctorService.getMyProfile(authentication.getName())
);
}
// -------------------------------------------------
// DOCTOR - UPDATE OWN PROFILE
// -------------------------------------------------
@PutMapping("/profile/me")
public ResponseEntity<DoctorResponse>
updateMyProfile(
@Valid
@RequestBody
DoctorProfileRequest request,
Authentication authentication) {
return ResponseEntity.ok(
doctorService.updateMyProfile(
authentication.getName(),
request
)
);
}
// -------------------------------------------------
// DOCTOR - DELETE OWN PROFILE
// -------------------------------------------------
@DeleteMapping("/profile/me")
public ResponseEntity<Void>
deleteMyProfile(
Authentication authentication) {
doctorService.deleteMyProfile(
authentication.getName()
);
return ResponseEntity
.noContent()
.build();
}
}Problem 4 — Fix Repository Method Name Mismatch in UserService
package com.medicare.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import com.medicare.dto.UserRequest;
import com.medicare.dto.UserResponse;
import com.medicare.entity.User;
import com.medicare.exception.UserNotFoundException;
import com.medicare.repository.UserRepository;
@Service
public class UserService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
public UserService(
UserRepository userRepository,
PasswordEncoder passwordEncoder) {
this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder;
}
public UserResponse createUser(
UserRequest request) {
if (userRepository.existsByEmail(request.getEmail())) {
throw new IllegalArgumentException(
"Email is already registered"
);
}
User user = new User();
user.setName(request.getName());
user.setEmail(request.getEmail());
user.setPhone(request.getPhone());
/*
* Never store a plain-text password.
* BCrypt converts it into a secure hash.
*/
user.setPassword(passwordEncoder.encode(request.getPassword())
);
user.setRole(request.getRole());
User savedUser = userRepository.save(user);
return mapToUserResponse(savedUser);
}
public List<UserResponse> getAllUsers() {
List<User> users =
userRepository.findAll();
List<UserResponse> responses =
new ArrayList<>();
for (User user : users) {
responses.add(mapToUserResponse(user));
}
return responses;
}
public UserResponse getUserById(Long id) {
User user = userRepository
.findById(id)
.orElseThrow(() ->
new UserNotFoundException(
"User not found with id: " + id
)
);
return mapToUserResponse(user);
}
public UserResponse getCurrentUser(
String email) {
User user =
userRepository
.findByEmailIgnoreCase(email)
.orElseThrow(() ->
new UserNotFoundException(
"User not found"
)
);
return mapToUserResponse(user);
}
private UserResponse mapToUserResponse(User user) {
return new UserResponse(
user.getId(),
user.getName(),
user.getEmail(),
user.getPhone(),
user.getRole()
);
}
}
"" C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\service\
UserService.java:32:27
java: cannot find symbol
symbol: method existsByEmail(java.lang.String)
location: variable userRepository of type com.medicare.repository.UserRepository ""cannot find symbol: method existsByEmail(String)
The UserService uses an outdated repository method name that no longer matches the updated UserRepository.
createUser(), getAllUsers(), getUserById()
existsByEmail() with : existsByEmailIgnoreCase()getCurrentUser() because user registration and authentication are now handled by AuthService.package com.medicare.service;
import org.springframework.stereotype.Service;
import com.medicare.dto.UserResponse;
import com.medicare.entity.User;
import com.medicare.exception.UserNotFoundException;
import com.medicare.repository.UserRepository;
@Service
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public UserResponse getCurrentUser(
String email) {
User user = userRepository.findByEmailIgnoreCase(email)
.orElseThrow(() ->new UserNotFoundException(
"User not found")
);
return mapToUserResponse(user);
}
private UserResponse mapToUserResponse(User user) {
return new UserResponse(
user.getId(),
user.getName(),
user.getEmail(),
user.getPhone(),
user.getRole()
);
}
}package com.medicare.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import com.medicare.entity.User;
public interface UserRepository extends JpaRepository<User, Long> {
boolean existsByEmailIgnoreCase(String email);
Optional<User> findByEmailIgnoreCase(String email);
}Problem 5 — Remove Outdated User Endpoints from UserController
package com.medicare.controller;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.medicare.dto.UserRequest;
import com.medicare.dto.UserResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medicare.entity.User;
import com.medicare.service.UserService;
import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/users")
public class UserController {
private final UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@PostMapping
public ResponseEntity<UserResponse>
createUser(@Valid @RequestBody UserRequest request) {
UserResponse response = userService.createUser(request);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}
@GetMapping("/me")
public ResponseEntity<Map<String, Object>>
getCurrentUser() {
Authentication authentication =
SecurityContextHolder.getContext().getAuthentication();
Map<String, Object> response = new LinkedHashMap<>();
response.put("username",authentication.getName());
response.put("authorities",authentication.getAuthorities());
return ResponseEntity.ok(response);
}
@GetMapping
public ResponseEntity<List<UserResponse>> getAllUsers() {
return ResponseEntity.ok(userService.getAllUsers());
}
@GetMapping("/{id}")
public ResponseEntity<UserResponse> getUserById(@PathVariable Long id) {
return ResponseEntity.ok(userService.getUserById(id));
}
@GetMapping("/me")
public ResponseEntity<UserResponse>
getCurrentUser(Authentication authentication) {
return ResponseEntity.ok(
userService.getCurrentUser(authentication.getName())
);
}
}
"""C:\MEDICARE PROJECT\medicare-backend\src\main\java\com\medicare\controller\
UserController.java:45:28
java: cannot find symbol
symbol: method createUser(@jakarta.validation.Valid
com.medicare.dto.UserRequest)
location: variable userService of type com.medicare.service.UserService""cannot find symbol: method createUser(UserRequest)
The UserController still contains older Phase 8 endpoints even though user registration and authentication have moved to AuthController and AuthService.
GET /api/users/me, creating a duplicate endpoint mapping.POST /api/users
GET /api/users
GET /api/users/{id}
/me method that uses SecurityContextHolder and returns a MapGET /api/users/meAuthentication and call userService.getCurrentUser().Review the updated controllers and services.
Confirm that no outdated methods remain.
Check that duplicate endpoint mappings have been removed.
Verify that repository method names match their declarations.
Run the Spring Boot application.
Confirm that the backend starts without compilation or startup errors.