swagger: '2.0'
info:
  title: Admin API
  description: 管理平台 API 文档
  version: "1.0.0"
# the domain of the service
host: localhost:4000
# array of all schemes that your API supports
schemes:
  - http
# will be prefixed to all paths
# basePath: /v1
produces:
  - application/json
paths:
  /statistics/dashboard:
    get:
      summary: 数据概览
      description: 数据概览
      tags:
        - Statistics
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/Dashboard'
  /users:
    get:
      summary: 获取用户列表
      description: 获取用户列表
      tags:
        - User
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/User'
  /users/{id}:
    get:
      summary: 获取用户信息
      description: 加载用户数据,含名下 apps
      parameters:
        - name: id
          in: path
          description: userid to fetch
          required: true
          type: integer
        - name: apps
          in: query
          description: Owned, associated or both?
          required: false
          type: string
        - name: type
          in: query
          description: conv or xxxx?
          required: false
          type: string
      tags:
        - User
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/UserExtended'
  /users/{id}/quota:
    get:
      summary: 获取配额信息
      description: 获取配额信息
      tags:
        - User
      responses:
        200:
          description: OK
    put:
      summary: 更新用户配额信息
      description: 更新用户配额信息
      parameters:
        - name: NewQuota
          in: body
          description: New quota setting, including planid and endDate
          required: true
          schema:
            $ref: '#/definitions/NewQuota'
      tags:
        - User
      responses:
        200:
          description: OK
    parameters:
      - name: id
        in: path
        description: userid to fetch
        required: true
        type: integer
  /users/{id}/feature:
    put:
      summary: 修改用户权限
      description: 更新功能权限
      parameters:
        - name: NewFeature
          in: body
          description: New features 
          required: true
          schema:
            $ref: '#/definitions/NewFeature'
      tags:
        - User
      responses:
        200:
          description: OK
    parameters:
      - name: id
        in: path
        description: userid to update
        required: true
        type: integer
  /siteusers/{id}:
    delete:
      summary: 删除一个用户-应用授权
      description: 删除一个用户-应用授权
      tags:
        - SiteUser
      responses:
        200:
          description: OK
    parameters:
      - name: id
        in: path
        description: Siteuser id to delete
        required: true
        type: integer
  /apps:
    get:
      summary: 获取 apps 列表
      description: 获取应用列表
      tags:
        - App
      responses:
        200:
          description: OK
  /apps/{type}/{siteId}:
    get:
      summary: 获取 app 详细信息,包括用户,渠道,标签,成员等
      description: 获取应用详情,含更多用户/渠道/标签信息
      tags:
        - App
      responses:
        200:
          description: OK
    parameters:
      - name: type
        in: path
        description: conv or xxxx
        required: true
        type: string
      - name: siteId
        in: path
        description: 应用编号
        required: true
        type: integer
  /apps/{id}:
    get:
      summary: 加载单个 app 的详细信息
      description: 获取应用详情
      parameters:
        - name: userId
          in: query
          description: Use user id to get email ...
          required: true
          type: integer
      tags:
        - App
      responses:
        200:
          description: OK
    parameters:
      - name: id
        in: path
        description: app id
        required: true
        type: integer
  /apps/{type}/{siteId}/tags:
    put:
      summary: 更新应用标签
      description: 更新 app 标签,返回更新后的 app 详情包括用户,渠道,标签,成员等
      parameters:
        - name: tags
          in: body
          description: tag group
          required: true
          schema:
            $ref: '#/definitions/NewTags'
      tags:
        - App
      responses:
        200:
          description: OK
    parameters:
      - name: type
        in: path
        description: conv or xxxx
        required: true
        type: string
      - name: siteId
        in: path
        description: app id
        required: true
        type: string
  /apps/{type}/{siteId}/founder:
    put:
      summary: 创建者转移
      description: 更新应用的创建者信息,返回更新后的应用详情
      parameters:
        - name: founder
          in: body
          description: founder transfer
          schema:
            $ref: '#/definitions/FounderTransfer'
      tags:
        - App
      responses:
        200:
          description: OK
    parameters:
      - name: type
        in: path
        description: conv or xxxx
        required: true
        type: string
      - name: siteId
        in: path
        description: app id
        required: true
        type: integer
definitions:
  SiteUser:
    type: object
    properties:
      id:
        type: integer
      email:
        type: string
      siteId:
        type: integer
      role:
        type: string
      flag:
        type: integer
      inviter:
        type: string
      features:
        type: array
        items:
          type: string
      medias:
        type: array
        items:
          type: string
      createdAt:
        type: string
        format: date-time
      updatedAt:
        type: string
        format: date-time
  App:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
      homepage:
        type: string
      founder:
        type: string
      startDate:
        type: string
        format: date-time
      endDate:
        type: string
        format: date-time
      createdAt:
        type: string
        format: date-time
      updatedAt:
        type: string
        format: date-time
      delStatus:
        type: boolean
      isapp:
        type: integer
      adv:
        type: string
      dbid:
        type: integer
      options:
        type: string
      config:
        type: string
      preCalc:
        type: string
  Plan:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
      appQuota:
        type: integer
      authQuota:
        type: integer
      exportReport:
        type: boolean
      originalLog:
        type: boolean
      isCustom:
        type: boolean
  UserPlan:
    type: object
    properties:
      planId:
        type: integer
      startDate:
        type: string
        format: date-time
      endDate:
        type: string
        format: date-time
      plans:
        type: array
        items:
          $ref: '#/definitions/Plan'
  UserExtended:
    type: object
    properties:
      userInfo:
        $ref: '#/definitions/User'
      planInfo:
        $ref: '#/definitions/UserPlan'
      createdApps:
        type: array
        items:
          $ref: '#/definitions/App'
      invitedApps:
        type: array
        items:
          $ref: '#/definitions/App'
  User:
    type: object
    properties:
      userId:
        type: integer
      phone:
        type: string
      email:
        type: string
      date:
        type: string
        format: date-time
      updatedAt:
        type: string
        format: date-time
      qq:
        type: string
      company:
        type: string
  Dashboard:
    type: object
    properties:
      apps:
        type: array
        items:
          $ref: '#/definitions/Metric'
      users:
        type: array
        items:
          $ref: '#/definitions/Metric'
  Metric:
    type: object
    properties:
      key:
        type: string
        description: Metric index name
      title:
        type: string
        description: Metric title
      definition:
        type: string
        description: Metric definition
      count:
        type: integer
        description: A count value for this metric
      daily:
        type: array
        items:
          $ref: '#/definitions/DateTotal'
  DateTotal:
    type: object
    properties:
      date:
        type: string
        format: date
        description: date string
      total:
        type: integer
        description: count value today
  FounderTransfer:
    type: object
    properties:
      prev:
        type: string
        description: email of previous owner.
      current:
        type: string
        description: target email.
  NewQuota:
    type: object
    properties:
      planId:
        type: integer
        description: plan id for new quota.
      endDate:
        type: string
        format: date
        description: endDate for new quota.
  NewFeature:
    type: object
    properties:
      siteId:
        type: integer
        description: App id to be set.
      features:
        type: string
        description: feature string seperating by comma.
      medias:
        type: string
        description: medias.
      inviter:
        type: string
        description: inviter.
      role:
        type: string
        description: role, either user or admin.
  NewTags:
    type: object
    properties:
      tags:
        type: array
        items:
          type: string
        description: string tags array
  Error:
    type: object
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      fields:
        type: string
