ref: 图书馆:分散各接口为独立的类,而不是挤在一起

main
lensfrex 1 year ago
parent e186a0d9f0
commit 5fd5099181
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 4
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BaseLibraryApiService.java
  2. 23
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookCoverImageUrlApiService.java
  3. 24
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookDetailApiService.java
  4. 24
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/CurrentLoanApiService.java
  5. 66
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LibraryApiService.java
  6. 23
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LoanHistoryApiService.java
  7. 23
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/OverdueSoonApiService.java
  8. 24
      mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/SearchApiService.java

@ -4,10 +4,10 @@ import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
public abstract class LibraryApiServiceBase {
public abstract class BaseLibraryApiService {
protected final Requester requester;
public LibraryApiServiceBase(Requester requester) {
public BaseLibraryApiService(Requester requester) {
this.requester = requester;
}

@ -0,0 +1,23 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class BookCoverImageUrlApiService extends BaseLibraryApiService {
public BookCoverImageUrlApiService(Requester requester) {
super(requester);
}
public String getBookCoverImageUrl(String isbn) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbn);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -0,0 +1,24 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class BookDetailApiService extends BaseLibraryApiService {
public BookDetailApiService(Requester requester) {
super(requester);
}
public String getBookDetail(String bookId) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookInfoRequest(bookId);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -0,0 +1,24 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class CurrentLoanApiService extends BaseLibraryApiService {
public CurrentLoanApiService(Requester requester) {
super(requester);
}
public String getCurrentLoan(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.currentLoanRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -1,66 +0,0 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
/**
* 图书馆相关接口由于返回的数据都是json特别好解析所以这里的数据获取到了之后可以直接拿来用自己来解析
*/
public class LibraryApiService extends LibraryApiServiceBase {
public LibraryApiService(Requester requester) {
super(requester);
}
public String search(String keyword, int page, int pageSize) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookSearchRequest(keyword, page, pageSize);
HttpResponse response = requester.post(request);
checkResponse(response);
return response.getStringBody();
}
public String getBookDetail(String bookId) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookInfoRequest(bookId);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
public String getBookCoverImageUrl(String isbn) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbn);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
public String getOverdueSoon(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
public String getCurrentLoan(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.currentLoanRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
public String getLoanHistory(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -0,0 +1,23 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class LoanHistoryApiService extends BaseLibraryApiService {
public LoanHistoryApiService(Requester requester) {
super(requester);
}
public String getLoanHistory(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -0,0 +1,23 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class OverdueSoonApiService extends BaseLibraryApiService {
public OverdueSoonApiService(Requester requester) {
super(requester);
}
public String getOverdueSoon(String cookie) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie);
HttpResponse response = requester.get(request);
checkResponse(response);
return response.getStringBody();
}
}

@ -0,0 +1,24 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
import java.io.IOException;
public class SearchApiService extends BaseLibraryApiService {
public SearchApiService(Requester requester) {
super(requester);
}
public String search(String keyword, int page, int pageSize) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookSearchRequest(keyword, page, pageSize);
HttpResponse response = requester.post(request);
checkResponse(response);
return response.getStringBody();
}
}
Loading…
Cancel
Save