项目作者: ALPhaHoai

项目描述 :
api restful service ứng dụng đọc truyện bằng java jersey
高级语言: Java
项目地址: git://github.com/ALPhaHoai/LongBookApi.git
创建时间: 2018-11-14T04:45:54Z
项目社区:https://github.com/ALPhaHoai/LongBookApi

开源协议:

下载


LongBook

Ứng dụng đọc truyện

Chức năng

  • Người quản trị
    • Có thể thêm mới, chỉnh sửa, xóa truyện
  • Người dùng
    • Xem danh sách truyện
    • Xem chi tiết nội dung từng truyện
    • Tìm kiếm truyện theo tên

Mô tả hệ thống

  1. Backend

    • Xây dựng 1 Web Service để đổ dữ liệu về cho front-end
    • Cơ dữ liệu Mysql
    • Xây dựng API phục vụ cho người quản trị, và người dùng
  2. Front-end

    • Phần mềm quản trị

      • Trang web quản trị để quản lý thêm, sửa, xóa truyện
    • Người dùng cuối

      • Android App xem danh sách truyện
      • Có thể tìm kiếm teo tên
      • Duyệt danh sách truyện theo thể loại
      • Xem chi tiết truyện

    Yêu cầu

    • Dùng Jersey cho web service
    • Chỉ backend mới có thể tương tác với csdl
    • Backend có thể chỉ cần viết trên console

API Restful Service

1. Book Node

1. Get all Book

Lấy thông tin danh sách các truyện

  • URL

    /book

  • Authentication

    No

  • Method:

    GET

  • URL Params

    Optional:

    start=[0-~] unsigned integer default:0

    limit=[1-100] unsigned integer default:10

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "id": 4,
      6. "title": "Khí Phi Hồ Sủng",
      7. "content": "Nội dung truyện Khí Phi Hồ Sủng"
      8. },
      9. {
      10. "id": 5,
      11. "title": "Mê Muội",
      12. "content": "Nội dung truyện Mê Muội"
      13. }
      14. ],
      15. "message": "OK",
      16. "status": 200
      17. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "message": "Empty data",
      3. "status": 400
      4. }
  • Sample Call:

    GET /book

    GET /book?start=1&limit=2

2. Get a specified book

Lấy thông tin của 1 truyện cụ thể

  • URL

    /book/{book_id}

  • Authentication

    No

  • Method:

    GET

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "id": 10,
      5. "title": "Tên truyện",
      6. "content": "Nội dung truyện",
      7. "category":
      8. [
      9. {
      10. "name": "Ngôn Tình",
      11. "id": 1
      12. },
      13. {
      14. "name": "Truyện cười",
      15. "id": 2
      16. },
      17. ],
      18. },
      19. "message": "OK",
      20. "status": 200
      21. }
  • Error Response:

    • Code: 404 Not Found

      Content:

      1. {
      2. "message": "Book not found",
      3. "status": 404
      4. }
  • Sample Call:

    GET /book/1

3. Insert book

Thêm 1 truyện

  • URL

    /book

  • Authentication

    Yes

  • Method:

    POST

  • Data Params

    Required:

    1. {
    2. "title": {Tên truyn},
    3. "content": {Ni dung truyn}
    4. }
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "id": 10,
      5. "title": "Tên truyện",
      6. "content": "Nội dung truyện"
      7. },
      8. "message": "OK",
      9. "status": 200
      10. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Duplicate content with book 2"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Invalid input data"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't insert this book"
      4. }
  • Sample Call:

    POST /book

    1. {
    2. "title": "Con cò",
    3. "content": "Con cò bay lả bay la"
    4. }

4. Update book

Update 1 truyện

  • URL

    /book/{book_id}

  • Authentication

    Yes

  • Method:

    PUT

  • Data Params

    Required:

    1. {
    2. "title": {Tên truyn},
    3. "content": {Ni dung truyn}
    4. }
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "id": 22,
      5. "title": "Đỉnh Luyện Thần Ma 2",
      6. "content": "Nội dung truyện đã chỉnh sửa"
      7. },
      8. "message": "OK",
      9. "status": 200
      10. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Duplicate content with book 2"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Invalid input data"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't update this book"
      4. }
  • Sample Call:

    PUT /book/1

    1. {
    2. "title": "Con cò",
    3. "content": "Con cò bay lả bay la"
    4. }

5. Delete a specified book

Xóa một truyện

  • URL

    /book/{book_id}

  • Authentication

    Yes

  • Method:

    DELETE

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "status": 200,
      3. "message": "Delete this book successful"
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This book doesn't exist"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't delete this book"
      4. }
  • Sample Call:

    DELETE /book/1

6. Show of category of specified book

Xem thông tin các thể loại của một truyện cụ thể

  • URL

    /book/{book_id}/category

  • Method:

    GET

  • Authentication

    No

  • URL Params

    Optional:

    start=[0-~] unsigned integer default:0

    limit=[1-100] unsigned integer default:10

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "name": "Ngôn Tình",
      6. "id": 1
      7. },
      8. {
      9. "name": "Truyện Teen",
      10. "id": 9
      11. }
      12. ],
      13. "message": "OK",
      14. "status": 200
      15. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This book doesn't exist"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Empty data"
      4. }
  • Sample Call:

    GET /book/1/category

    GET /book/1/category?start=0&limit=2

7. Insert a category of specified book

Thêm thể một thể loại cho một truyện cụ thể

  • URL

    /book/{book_id}/category

  • Authentication

    Yes

  • Method:

    POST

  • Data Params

    Required:

    1. {
    2. "category_id": {category_id}
    3. }
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "status": 200,
      3. "message": "Insert this category for this book successful"
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This book is already has this category"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't insert this category for this book"
      4. }
  • Sample Call:

    POST /book/1/category

    1. {
    2. "category_id": 4
    3. }

8. Update all category of specified book

Set tất cả các thể loại của một sách

  • URL

    /book/{book_id}/category

  • Authentication

    Yes

  • Method:

    PUT

  • Data Params

    Optional:
    Danh sách các category id (có thể nhận giá trị rỗng)

    1. [
    2. {
    3. "id": {category_id}
    4. },
    5. {
    6. "id": {category_id}
    7. }
    8. ]
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "name":"Truyện ma",
      6. "id":1
      7. },
      8. {
      9. "name":"Truyện cười",
      10. "id":2
      11. }
      12. ],
      13. "message":"OK",
      14. "status":200
      15. }

      OR

      1. {
      2. "message":"Delete all category of this book successful",
      3. "status":200
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Category not found: 70"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't insert this category for this book"
      4. }
  • Sample Call:

    PUT /book/1/category

    1. [
    2. {
    3. "id": 4
    4. },
    5. {
    6. "id": 5
    7. }
    8. ]

9. Delete all category of specified book

Xóa tất cả các thể loại của một truyện cụ thể

  • URL

    /book/{book_id}/category

  • Authentication

    Yes

  • Method:

    DELETE

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "status": 200,
      3. "message": "Delete all category of this book successful"
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This book has no category"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't delete all category of this book"
      4. }
  • Sample Call:

    DELETE /book/1/category

10. Delete a category of specified book

Xóa một thể loại của một truyện cụ thể

  • URL

    /book/{book_id}/category/{category_id}

  • Authentication

    Yes

  • Method:

    DELETE

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "status": 200,
      3. "message": "Delete this category of this book successful"
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This book is not has this category"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't delete this category for this book"
      4. }
  • Sample Call:

    DELETE /book/1/category/2

11. Search book

Tìm kiếm truyện theo tên, nội dung hoặc thể loại

  • URL

    /book/search

  • Authentication

    No

  • Method:

    GET

  • URL Params

    Optional:

    title = {tên truyện}

    content = {nội dung truyện}

    categories = {thể loại 1},{thể loại 2},{thể loại 3}

    start=[0-~] unsigned integer default:0

    limit=[1-100] unsigned integer default:10

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "id":1,
      6. "title":"Tên truyện 1",
      7. "content":"Nội dung truyện 1"
      8. },
      9. {
      10. "id":2,
      11. "title":"Tên truyện 2",
      12. "content":"Nội dung truyện 3"
      13. }
      14. ],
      15. "message":"OK",
      16. "status":200
      17. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Empty data"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Invalid input data"
      4. }
  • Sample Call:

    GET /book/search?title=truyen&content=noidung&categories=1,2,3

2. Category Node

1. Get all category

Lấy thông tin tất cả các thể loại

  • URL

    /category

  • Authentication

    No

  • Method:

    GET

  • URL Params

    Optional:

    start=[0-~] unsigned integer default:0

    limit=[1-100] unsigned integer default:10

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "name": "Ngôn Tình",
      6. "id": 1
      7. },
      8. {
      9. "name": "Xuyên Không",
      10. "id": 2
      11. }
      12. ],
      13. "message": "OK",
      14. "status": 200
      15. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Empty data"
      4. }
  • Sample Call:

    GET /category

    GET /category?start=1&limit=2

2. Get a specified category

Lấy thông tin cụ thể của 1 thể loại

  • URL

    /book/{category_id}

  • Authentication

    No

  • Method:

    GET

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "name": "Ngôn Tình",
      5. "id": 1
      6. },
      7. "message": "OK",
      8. "status": 200
      9. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This category doesn't exist"
      4. }
  • Sample Call:

    GET /category/1

3. Insert category

Thêm 1 thể loại

  • URL

    /category

  • Authentication

    Yes

  • Method:

    POST

  • Data Params

    Required:

    1. {
    2. "name": {Tên th loi}
    3. }
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "name": "Tên thể loại",
      5. "id": 17
      6. },
      7. "message": "OK",
      8. "status": 200
      9. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Duplicate content with category 2"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Invalid input data"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't insert this category"
      4. }
  • Sample Call:

    POST /category

    1. {
    2. "name": "Truyện cười"
    3. }

4. Update category

Update 1 thể loại

  • URL

    /book/{category_id}

  • Authentication

    Yes

  • Method:

    PUT

  • Data Params

    Required:

    1. {
    2. "name": {Tên th loi mi}
    3. }
  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. {
      4. "name": "Tên thể loại mới",
      5. "id": 2
      6. },
      7. "message": "OK",
      8. "status": 200
      9. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "Duplicate content with category 2"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Invalid input data"
      4. }
  • Sample Call:

    PUT /category/1

    1. {
    2. "name": "Truyện cười"
    3. }

5. Delete a specified category

Xóa một thể loại

  • URL

    /category/{category_id}

  • Authentication

    Yes

  • Method:

    DELETE

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "status": 200,
      3. "message": "Delete this category successful"
      4. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This category doesn't exist"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Can't delete this category"
      4. }
  • Sample Call:

    DELETE /category/1

6. Show all book of specified category

Xem danh sách các truyện thuộc một thể loại cụ thể

  • URL

    /category/{category_id}/book

  • Authentication

    No

  • Method:

    GET

  • URL Params

    Optional:

    start=[0-~] unsigned integer default:0

    limit=[1-100] unsigned integer default:10

  • Success Response:

    • Code: 200

      Content:

      1. {
      2. "result":
      3. [
      4. {
      5. "id": 7,
      6. "title": "Ông Xã Là Trung Khuyển",
      7. "content": "Nội dung truyện Ông Xã Là Trung Khuyển"},
      8. {
      9. "id": 17,
      10. "title": "Gian Nịnh Quốc Sư Yêu Tà Thê",
      11. "content": "Nội dung truyện Gian Nịnh Quốc Sư Yêu Tà Thê"
      12. }
      13. ],
      14. "message": "OK",
      15. "status": 200
      16. }
  • Error Response:

    • Code: 400 Bad Request

      Content:

      1. {
      2. "status": 400,
      3. "message": "This category doesn't exist"
      4. }

      OR

      1. {
      2. "status": 400,
      3. "message": "Empty data"
      4. }
  • Sample Call:

    GET /category/1/book

    GET /category/1/book?start=0&limit=2