• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / servicecomb-kie / 712

28 Dec 2020 - 13:08 coverage: 59.642% (-2.1%) from 61.776%
712

Pull #168

travis-ci

web-flow
Merge 591fdf42c into 9d4a4e07f
Pull Request #168: #79 消息轨迹推送跟踪

8 of 12 new or added lines in 2 files covered. (66.67%)

2 existing lines in 1 file now uncovered.

1033 of 1732 relevant lines covered (59.64%)

3.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.97
/server/resource/v1/history_resource.go
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
package v1
19

20
import (
21
        "github.com/apache/servicecomb-kie/pkg/common"
22
        "github.com/apache/servicecomb-kie/pkg/model"
23
        "github.com/apache/servicecomb-kie/server/service"
24
        "net/http"
25

26
        goRestful "github.com/emicklei/go-restful"
27
        "github.com/go-chassis/go-chassis/v2/server/restful"
28
        "github.com/go-chassis/openlog"
29
)
30

31
//HistoryResource TODO
32
type HistoryResource struct {
33
}
34

35
//GetRevisions search key only by label
36
func (r *HistoryResource) GetRevisions(context *restful.Context) {
2×
37
        var err error
2×
38
        kvID := context.ReadPathParameter(common.PathParamKVID)
2×
39
        offsetStr := context.ReadQueryParameter(common.QueryParamOffset)
2×
40
        limitStr := context.ReadQueryParameter(common.QueryParamLimit)
2×
41
        offset, limit, err := checkPagination(offsetStr, limitStr)
2×
42
        if err != nil {
2×
43
                WriteErrResponse(context, http.StatusBadRequest, err.Error())
!
44
                return
!
45
        }
!
46
        if kvID == "" {
2×
47
                openlog.Error("kv id is nil")
!
48
                WriteErrResponse(context, http.StatusForbidden, "kv_id must not be empty")
!
49
                return
!
50
        }
!
51
        revisions, err := service.HistoryService.GetHistory(context.Ctx, kvID,
2×
52
                service.WithOffset(offset),
2×
53
                service.WithLimit(limit))
2×
54
        if err != nil {
2×
55
                if err == service.ErrRevisionNotExist {
!
56
                        WriteErrResponse(context, http.StatusNotFound, err.Error())
!
57
                        return
!
58
                }
!
59
                WriteErrResponse(context, http.StatusInternalServerError, err.Error())
!
60
                return
!
61
        }
62
        err = writeResponse(context, revisions)
2×
63
        if err != nil {
2×
64
                openlog.Error(err.Error())
!
65
        }
!
66
}
67

68
//GetPollingData get the record of the get or list history
69
func (r *HistoryResource) GetPollingData(context *restful.Context) {
1×
70
        query := &model.PollingDetail{}
1×
71
        sessionID := context.ReadQueryParameter(common.QueryParamSessionID)
1×
72
        if sessionID != "" {
2×
73
                query.SessionID = sessionID
1×
74
        }
1×
75
        sessionCroup := context.ReadQueryParameter(common.QueryParamSessionGroup)
1×
76
        if sessionCroup != "" {
1×
NEW
77
                query.SessionGroup = sessionCroup
!
NEW
78
        }
!
79
        revision := context.ReadQueryParameter(common.QueryParamRev)
1×
80
        if revision != "" {
1×
NEW
81
                query.Revision = revision
!
NEW
82
        }
!
83
        ip := context.ReadQueryParameter(common.QueryParamIP)
1×
84
        if ip != "" {
1×
85
                query.IP = ip
!
86
        }
!
87
        urlPath := context.ReadQueryParameter(common.QueryParamURLPath)
1×
88
        if urlPath != "" {
1×
89
                query.URLPath = urlPath
!
90
        }
!
91
        userAgent := context.ReadQueryParameter(common.QueryParamUserAgent)
1×
92
        if userAgent != "" {
1×
93
                query.UserAgent = userAgent
!
94
        }
!
95
        domain := ReadDomain(context.Ctx)
1×
96
        if domain == "" {
1×
97
                WriteErrResponse(context, http.StatusInternalServerError, common.MsgDomainMustNotBeEmpty)
!
98
                return
!
99
        }
!
100
        query.Domain = domain
1×
101
        records, err := service.TrackService.GetPollingDetail(context.Ctx, query)
1×
102
        if err != nil {
1×
103
                if err == service.ErrRecordNotExists {
!
104
                        WriteErrResponse(context, http.StatusNotFound, err.Error())
!
105
                        return
!
106
                }
!
107
                WriteErrResponse(context, http.StatusInternalServerError, err.Error())
!
108
                return
!
109
        }
110
        resp := &model.PollingDataResponse{}
1×
111
        resp.Data = records
1×
112
        resp.Total = len(records)
1×
113
        err = writeResponse(context, resp)
1×
114
        if err != nil {
1×
115
                openlog.Error(err.Error())
!
116
        }
!
117
}
118

119
//URLPatterns defined config operations
120
func (r *HistoryResource) URLPatterns() []restful.Route {
3×
121
        return []restful.Route{
3×
122
                {
3×
123
                        Method:       http.MethodGet,
3×
124
                        Path:         "/v1/{project}/kie/revision/{kv_id}",
3×
125
                        ResourceFunc: r.GetRevisions,
3×
126
                        FuncDesc:     "get all revisions by key id",
3×
127
                        Parameters: []*restful.Parameters{
3×
128
                                DocPathProject, DocPathKeyID,
3×
129
                        },
3×
130
                        Returns: []*restful.Returns{
3×
131
                                {
3×
132
                                        Code:  http.StatusOK,
3×
133
                                        Model: model.DocResponseGetKey{},
3×
134
                                },
3×
135
                        },
3×
136
                        Consumes: []string{goRestful.MIME_JSON},
3×
137
                        Produces: []string{goRestful.MIME_JSON},
3×
138
                },
3×
139

3×
140
                {
3×
141
                        Method:       http.MethodGet,
3×
142
                        Path:         "/v1/{project}/kie/track",
3×
143
                        ResourceFunc: r.GetPollingData,
3×
144
                        FuncDesc:     "get polling tracks of clients of kie server",
3×
145
                        Parameters: []*restful.Parameters{
3×
146
                                DocPathProject, DocQuerySessionIDParameters, DocQueryIPParameters, DocQueryURLPathParameters, DocQueryUserAgentParameters,
3×
147
                        },
3×
148
                        Returns: []*restful.Returns{
3×
149
                                {
3×
150
                                        Code:    http.StatusOK,
3×
151
                                        Message: "true",
3×
152
                                        Model:   []model.PollingDataResponse{},
3×
153
                                },
3×
154
                        },
3×
155
                        Consumes: []string{goRestful.MIME_JSON},
3×
156
                        Produces: []string{goRestful.MIME_JSON},
3×
157
                },
3×
158
        }
3×
159
}
3×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc