feat(navigation): add schedule tab and stack navigator
Add new ScheduleTab to main navigation with ScheduleStackNavigator for managing course schedule screens. Includes CourseDetailScreen with modal presentation. Also exports scheduleService and related types for the new schedule feature. fix(message): add group_id parameter to invite and request handlers Pass group_id from extra_data when calling respondInvite and reviewJoinRequest APIs, as the backend now requires this parameter. refactor(message): extract mergeMessagesById helper method Centralize message merging logic into a reusable private method to avoid duplication and ensure consistent message deduplication behavior.
This commit is contained in:
@@ -88,6 +88,10 @@ export type {
|
||||
CreateAnnouncementRequest,
|
||||
} from './groupService';
|
||||
|
||||
// 课表服务
|
||||
export { scheduleService } from './scheduleService';
|
||||
export type { CreateScheduleCourseRequest } from './scheduleService';
|
||||
|
||||
// 后台保活服务
|
||||
export {
|
||||
backgroundService,
|
||||
|
||||
70
src/services/scheduleService.ts
Normal file
70
src/services/scheduleService.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { api } from './api';
|
||||
import { Course } from '../types/schedule';
|
||||
|
||||
interface ScheduleCourseDTO {
|
||||
id: string;
|
||||
name: string;
|
||||
teacher?: string;
|
||||
location?: string;
|
||||
day_of_week: number;
|
||||
start_section: number;
|
||||
end_section: number;
|
||||
weeks: number[];
|
||||
color?: string;
|
||||
}
|
||||
|
||||
interface ScheduleCourseListResponse {
|
||||
list: ScheduleCourseDTO[];
|
||||
}
|
||||
|
||||
interface CreateScheduleCourseRequest {
|
||||
name: string;
|
||||
teacher?: string;
|
||||
location?: string;
|
||||
day_of_week: number;
|
||||
start_section: number;
|
||||
end_section: number;
|
||||
weeks: number[];
|
||||
color?: string;
|
||||
}
|
||||
|
||||
interface CreateScheduleCourseResponse {
|
||||
course: ScheduleCourseDTO;
|
||||
}
|
||||
|
||||
const toCourse = (dto: ScheduleCourseDTO): Course => ({
|
||||
id: dto.id,
|
||||
name: dto.name,
|
||||
teacher: dto.teacher,
|
||||
location: dto.location,
|
||||
dayOfWeek: dto.day_of_week,
|
||||
startSection: dto.start_section,
|
||||
endSection: dto.end_section,
|
||||
weeks: dto.weeks ?? [],
|
||||
color: dto.color,
|
||||
});
|
||||
|
||||
class ScheduleService {
|
||||
async getCourses(week?: number): Promise<Course[]> {
|
||||
const params = week ? { week } : undefined;
|
||||
const response = await api.get<ScheduleCourseListResponse>('/schedule/courses', params);
|
||||
return response.data.list.map(toCourse);
|
||||
}
|
||||
|
||||
async createCourse(input: CreateScheduleCourseRequest): Promise<Course> {
|
||||
const response = await api.post<CreateScheduleCourseResponse>('/schedule/courses', input);
|
||||
return toCourse(response.data.course);
|
||||
}
|
||||
|
||||
async updateCourse(courseId: string, input: CreateScheduleCourseRequest): Promise<Course> {
|
||||
const response = await api.put<CreateScheduleCourseResponse>(`/schedule/courses/${courseId}`, input);
|
||||
return toCourse(response.data.course);
|
||||
}
|
||||
|
||||
async deleteCourse(courseId: string): Promise<void> {
|
||||
await api.delete(`/schedule/courses/${courseId}`);
|
||||
}
|
||||
}
|
||||
|
||||
export const scheduleService = new ScheduleService();
|
||||
export type { CreateScheduleCourseRequest };
|
||||
Reference in New Issue
Block a user