Skip to content

Commit abfc62c

Browse files
Fix Q10: Added login and availability methods to DoctorService
Implemented methods for retrieving doctor details and checking login credentials.
1 parent 3299110 commit abfc62c

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed
Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,61 @@
11
package com.smartclinic.app.services;
22

3+
import com.smartclinic.app.models.Doctor;
4+
import com.smartclinic.app.repository.DoctorRepository;
5+
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.stereotype.Service;
4-
import com.smartclinic.app.models.Doctor; // Giả sử đã tạo
7+
8+
import java.time.LocalDate;
9+
import java.util.List;
10+
import java.util.Optional;
511

612
@Service
713
public class DoctorService {
814

9-
// Cần thêm logic nghiệp vụ, ví dụ:
10-
public Doctor getDoctorById(Long id) {
15+
private final DoctorRepository doctorRepository;
16+
// Có thể cần thêm AppointmentRepository để kiểm tra lịch trống
17+
// private final AppointmentRepository appointmentRepository;
18+
19+
@Autowired
20+
public DoctorService(DoctorRepository doctorRepository) {
21+
this.doctorRepository = doctorRepository;
22+
// this.appointmentRepository = appointmentRepository;
23+
}
24+
25+
// YÊU CẦU 1: Phương thức getDoctorById hoàn chỉnh
26+
public Optional<Doctor> getDoctorById(Long id) {
1127
// Logic truy vấn Doctor từ Repository
12-
return null;
28+
return doctorRepository.findById(id);
1329
}
1430

15-
public void updateDoctorProfile(Doctor doctor) {
16-
// Logic cập nhật thông tin Doctor
31+
// YÊU CẦU 2: Phương thức xác thực đăng nhập
32+
/**
33+
* Xác thực thông tin đăng nhập của bác sĩ.
34+
* @param email Email của bác sĩ.
35+
* @param password Mật khẩu thô (cần mã hóa trong thực tế).
36+
* @return Optional<Doctor> nếu xác thực thành công.
37+
*/
38+
public Optional<Doctor> checkLoginCredentials(String email, String password) {
39+
// Trong thực tế, sẽ cần sử dụng PasswordEncoder để so sánh mật khẩu.
40+
// Đây là logic đơn giản hóa cho bài tập:
41+
return doctorRepository.findByEmail(email)
42+
.filter(doctor -> doctor.getPassword().equals(password));
43+
}
44+
45+
// YÊU CẦU 3: Phương thức truy xuất lịch làm việc
46+
/**
47+
* Truy xuất thời gian rảnh (available time slots) của bác sĩ trong ngày.
48+
* @param doctorId ID của bác sĩ.
49+
* @param date Ngày cần kiểm tra lịch.
50+
* @return Danh sách các khung giờ còn trống.
51+
*/
52+
public List<String> getAvailability(Long doctorId, LocalDate date) {
53+
// Logic nghiệp vụ phức tạp sẽ được đặt ở đây:
54+
// 1. Lấy tất cả cuộc hẹn đã lên lịch của bác sĩ trong ngày (dùng AppointmentRepository).
55+
// 2. So sánh với khung giờ làm việc cố định của bác sĩ.
56+
// 3. Trả về các khung giờ trống (Available Slots).
57+
58+
// Trả về dữ liệu giả (mock data) để thể hiện chức năng:
59+
return List.of("09:00", "11:00", "14:30", "16:00");
1760
}
1861
}

0 commit comments

Comments
 (0)