Skip to content

API Specification

Forewing edited this page Mar 15, 2021 · 2 revisions

Models

// User hold user info
type User struct {
    ID      uint
    RoomID  uint
    
    Name    string
    Score   int
    
    UserHistorys    []UserHistory   `json:",omitempty"`
}

// UserHistory holds user history
type UserHistory struct {
    UserID      uint
    Round       int
    
    Score       int
    ScoreGet    int
    
    Submit1     float64
    Submit2     float64
}

// Room hold user info
type Room struct {
    ID          uint
    
    RoundNow    int
    RoundTotal  int
    
    Interval    int
    Status      int

    Users           []User
    RoomHistorys    []RoomHistory   `json:",omitempty"`
}

// RoomHistory holds room history
type RoomHistory struct {
    RoomID  uint
    Round   int
    
    GoldenNum   float64
}

User API

  • GET /rooms

    • Get room list
    • Rsp: []Room (without RoomHistorys field)
  • GET /room/{roomid}

    • Get room info of roomid
    • Req: roomid int
    • Rsp: Room (with RoomHistorys field)
  • GET /sync/{roomid}

    • Get room sync info of roomid
    • Req: roomid int
    • Rsp:
      • float with positive value, seconds before room's next tick if room exist and opened.
      • float with negative value, if room stopped.
      • string as error message and 404 if room not found.
  • POST /users/{roomid}

    • Create a user of room roomid

    • Req: roomid int

      • Body:
      type userCreateModel struct {
          Username string `binding:"required"`
          Password string `binding:"required"`
      }
    • Rsp: User if success, with status code 200.

    • Rsp: string as error message if failed, with status code 4xx/5xx.

  • GET /user/{userid}

    • Get user info of userid
    • Req: userid int
    • Rsp: User (with UserHistorys field)
  • POST /user/{userid}

    • Submit numbers of user userid

    • Req: userid int

      • Body:
      type userSubmitModel struct {
          Password string  `binding:"required"`
          Submit1  float64 `binding:"required"`
          Submit2  float64 `binding:"required"`
      }
    • Rsp: empty if success, with status code 200.

    • Rsp: string as error message if failed, with status code 4xx/5xx.

  • PUT /user/:userid

    • Check user userid password

    • Req: userid int

      • Body:
      type userAuthModel struct {
          Password string `binding:"required"`
      }
    • Rsp: User if success, with status code 200.

    • Rsp: string as error message if failed, with status code 4xx/5xx.

Admin API

Please refer to the code.

POST("/room", views.RoomCreate)
DELETE("/room/:roomid", views.RoomStop)
PUT("/room/:roomid", views.RoomStart)
// PATCH("/room/:roomid", views.RoomUpdate) // Not supported now
Clone this wiki locally