1515import org .springframework .web .bind .annotation .RequestMapping ;
1616
1717import com .spring .bioMedical .entity .Admin ;
18+ import com .spring .bioMedical .entity .Appointment ;
1819import com .spring .bioMedical .service .AdminServiceImplementation ;
20+ import com .spring .bioMedical .service .AppointmentServiceImplementation ;
1921import com .spring .bioMedical .service .UserService ;
2022
2123@ Controller
@@ -27,11 +29,15 @@ public class AdminController {
2729
2830 private AdminServiceImplementation adminServiceImplementation ;
2931
32+ private AppointmentServiceImplementation appointmentServiceImplementation ;
33+
34+
3035 @ Autowired
31- public AdminController (UserService userService ,AdminServiceImplementation obj ) {
36+ public AdminController (UserService userService ,AdminServiceImplementation obj ,
37+ AppointmentServiceImplementation app ) {
3238 this .userService = userService ;
3339 adminServiceImplementation =obj ;
34-
40+ appointmentServiceImplementation = app ;
3541 }
3642
3743
@@ -331,4 +337,45 @@ public String update(@ModelAttribute("profile") Admin admin) {
331337 }
332338
333339
340+ @ RequestMapping ("/appointments" )
341+ public String appointments (Model model ){
342+
343+
344+ // get last seen
345+ String username ="" ;
346+ Object principal = SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ();
347+ if (principal instanceof UserDetails ) {
348+ username = ((UserDetails )principal ).getUsername ();
349+ String Pass = ((UserDetails )principal ).getPassword ();
350+ System .out .println ("One + " +username +" " +Pass );
351+
352+
353+ } else {
354+ username = principal .toString ();
355+ System .out .println ("Two + " +username );
356+ }
357+
358+ Admin admin = adminServiceImplementation .findByEmail (username );
359+
360+ SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yyyy HH:mm:ss" );
361+ Date now = new Date ();
362+
363+ String log =now .toString ();
364+
365+ admin .setLastseen (log );
366+
367+ adminServiceImplementation .save (admin );
368+
369+
370+
371+ List <Appointment > list =appointmentServiceImplementation .findAll ();
372+
373+
374+
375+ // add to the spring model
376+ model .addAttribute ("app" , list );
377+
378+
379+ return "admin/admin" ;
380+ }
334381}
0 commit comments