main
parent
bc8ee2e5b1
commit
43f0c9a5c4
@ -1 +1 @@ |
|||||||
Subproject commit 99e1ea7c8fe539c2c6d942b0b32a7d4445298f4f |
Subproject commit a18aa81d71123f54e959866e93c7ceb56b03ade4 |
@ -0,0 +1,36 @@ |
|||||||
|
package cn.wustlinghang.wusthelper.internal.library.api.http; |
||||||
|
|
||||||
|
import cn.wustlinghang.mywust.data.library.parsed.BookHolding; |
||||||
|
import cn.wustlinghang.wusthelper.internal.library.services.BookHoldingService; |
||||||
|
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
|
import jakarta.enterprise.context.ApplicationScoped; |
||||||
|
import jakarta.validation.constraints.NotNull; |
||||||
|
import jakarta.ws.rs.GET; |
||||||
|
import jakarta.ws.rs.Path; |
||||||
|
import jakarta.ws.rs.QueryParam; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Path("/holdings") |
||||||
|
@ApplicationScoped |
||||||
|
public class BookHoldingApi { |
||||||
|
private final BookHoldingService service; |
||||||
|
|
||||||
|
public BookHoldingApi(BookHoldingService service) { |
||||||
|
this.service = service; |
||||||
|
} |
||||||
|
|
||||||
|
@GET |
||||||
|
@Path("/") |
||||||
|
public List<BookHolding> get(@QueryParam("id") @NotNull String id) |
||||||
|
throws RpcException { |
||||||
|
return this.agent(id); |
||||||
|
} |
||||||
|
|
||||||
|
@GET |
||||||
|
@Path("/agent") |
||||||
|
public List<BookHolding> agent(@QueryParam("id") @NotNull String id) |
||||||
|
throws RpcException { |
||||||
|
return service.getHoldings(id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
package cn.wustlinghang.wusthelper.internal.library.services; |
||||||
|
|
||||||
|
import cn.wustlinghang.mywust.core.request.service.library.BookHoldingApiService; |
||||||
|
import cn.wustlinghang.mywust.data.library.parsed.BookHolding; |
||||||
|
import cn.wustlinghang.mywust.exception.ApiException; |
||||||
|
import cn.wustlinghang.mywust.exception.ParseException; |
||||||
|
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; |
||||||
|
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
|
import jakarta.enterprise.context.ApplicationScoped; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@ApplicationScoped |
||||||
|
public class BookHoldingService extends BaseService { |
||||||
|
private final BookHoldingApiService api; |
||||||
|
|
||||||
|
public BookHoldingService(BookHoldingApiService api) { |
||||||
|
this.api = api; |
||||||
|
} |
||||||
|
|
||||||
|
public List<BookHolding> getHoldings(String id) |
||||||
|
throws RpcException { |
||||||
|
try { |
||||||
|
return api.getHoldingList(id); |
||||||
|
} catch (ApiException e) { |
||||||
|
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new LibraryRpcException( |
||||||
|
LibraryRpcException.TypeCode.NETWORK_EXCEPTION, |
||||||
|
LibraryRpcException.SubModuleCode.PERSONAL_API, |
||||||
|
LibraryRpcException.ErrorCode.NETWORK_ERROR |
||||||
|
); |
||||||
|
} catch (ParseException e) { |
||||||
|
throw new LibraryRpcException( |
||||||
|
LibraryRpcException.TypeCode.PARSE_EXCEPTION, |
||||||
|
LibraryRpcException.SubModuleCode.PERSONAL_API, |
||||||
|
LibraryRpcException.ErrorCode.PARSE_ERROR |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue