-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.example.CQUPT.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import java.util.List; | ||
|
||
public class CourseData { | ||
@SerializedName("course_id") | ||
private String courseId; | ||
|
||
@SerializedName("course_name") | ||
private String courseName; | ||
|
||
@SerializedName("class_id") | ||
private String classId; | ||
|
||
@SerializedName("class_name") | ||
private String className; | ||
|
||
@SerializedName("teacher_name") | ||
private String teacherName; | ||
|
||
@SerializedName("course_type") | ||
private String courseType; | ||
|
||
@SerializedName("exam_type") | ||
private String examType; | ||
|
||
private String seat; | ||
private String qualification; | ||
|
||
@SerializedName("schedule_id") | ||
private String scheduleId; | ||
|
||
private String lecturer; | ||
|
||
@SerializedName("chief_invigilator") | ||
private String chiefInvigilator; | ||
|
||
@SerializedName("deputy_invigilators") | ||
private List<String> deputyInvigilators; | ||
|
||
// Getters | ||
public String getCourseId() { | ||
return courseId; | ||
} | ||
|
||
public String getCourseName() { | ||
return courseName; | ||
} | ||
|
||
public String getClassId() { | ||
return classId; | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public String getTeacherName() { | ||
return teacherName; | ||
} | ||
|
||
public String getCourseType() { | ||
return courseType; | ||
} | ||
|
||
public String getExamType() { | ||
return examType; | ||
} | ||
|
||
public String getSeat() { | ||
return seat; | ||
} | ||
|
||
public String getQualification() { | ||
return qualification; | ||
} | ||
|
||
public String getScheduleId() { | ||
return scheduleId; | ||
} | ||
|
||
public String getLecturer() { | ||
return lecturer; | ||
} | ||
|
||
public String getChiefInvigilator() { | ||
return chiefInvigilator; | ||
} | ||
|
||
public List<String> getDeputyInvigilators() { | ||
return deputyInvigilators; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/example/CQUPT/api/CourseSchedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.example.CQUPT.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import java.util.List; | ||
|
||
public class CourseSchedule { | ||
private String id; | ||
private int type; | ||
|
||
@SerializedName("type_id") | ||
private String typeId; | ||
|
||
private String date; | ||
|
||
@SerializedName("week_nums") | ||
private List<Integer> weekNums; | ||
|
||
@SerializedName("week_num") | ||
private int weekNum; | ||
|
||
@SerializedName("start_time") | ||
private String startTime; | ||
|
||
@SerializedName("end_time") | ||
private String endTime; | ||
|
||
@SerializedName("time_slots") | ||
private List<Integer> timeSlots; | ||
|
||
private String title; | ||
private String location; | ||
private String description; | ||
private CourseData data; | ||
|
||
// Getters | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
public String getTypeId() { | ||
return typeId; | ||
} | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public List<Integer> getWeekNums() { | ||
return weekNums; | ||
} | ||
|
||
public int getWeekNum() { | ||
return weekNum; | ||
} | ||
|
||
public String getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public String getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public List<Integer> getTimeSlots() { | ||
return timeSlots; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public CourseData getData() { | ||
return data; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/example/CQUPT/api/RetrofitClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.CQUPT.api; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
public class RetrofitClient { | ||
private static final String BASE_URL = "http://10.0.2.2:8000/"; | ||
private static RetrofitClient instance; | ||
private final Retrofit retrofit; | ||
|
||
private RetrofitClient() { | ||
// 创建 OkHttpClient,添加日志拦截器 | ||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); | ||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
|
||
OkHttpClient client = new OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build(); | ||
|
||
// 创建 Retrofit 实例 | ||
retrofit = new Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build(); | ||
} | ||
|
||
public static synchronized RetrofitClient getInstance() { | ||
if (instance == null) { | ||
instance = new RetrofitClient(); | ||
} | ||
return instance; | ||
} | ||
|
||
public TimetableApiService getTimetableService() { | ||
return retrofit.create(TimetableApiService.class); | ||
} | ||
|
||
public NewsApiService getNewsService() { | ||
return retrofit.create(NewsApiService.class); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/example/CQUPT/api/TimetableApiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.CQUPT.api; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Path; | ||
|
||
public interface TimetableApiService { | ||
/** | ||
* 获取课程表数据 | ||
* @param studentId 学生学号 | ||
* @return 课程表数据响应 | ||
*/ | ||
@GET("api/timetable/{studentId}") | ||
Call<TimetableResponse> getTimetable(@Path("studentId") String studentId); | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/example/CQUPT/api/TimetableResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.CQUPT.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import java.util.List; | ||
|
||
public class TimetableResponse { | ||
private int status; | ||
private String message; | ||
private DataWrapper data; | ||
|
||
public static class DataWrapper { | ||
private int code; | ||
private String msg; | ||
private CourseData data; | ||
|
||
public static class CourseData { | ||
@SerializedName("course_schedules") | ||
private List<CourseSchedule> courseSchedules; | ||
|
||
public List<CourseSchedule> getCourseSchedules() { | ||
return courseSchedules; | ||
} | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
|
||
public CourseData getData() { | ||
return data; | ||
} | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public DataWrapper getData() { | ||
return data; | ||
} | ||
|
||
// 便捷方法,直接获取课程列表 | ||
public List<CourseSchedule> getCourseSchedules() { | ||
if (data != null && data.getData() != null) { | ||
return data.getData().getCourseSchedules(); | ||
} | ||
return null; | ||
} | ||
|
||
// 检查响应是否成功 | ||
public boolean isSuccessful() { | ||
return status == 200 && data != null && data.getCode() == 0; | ||
} | ||
} |
Oops, something went wrong.