-
Notifications
You must be signed in to change notification settings - Fork 1
/
search-price.go
90 lines (79 loc) · 2.5 KB
/
search-price.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package handlersmap
import (
"bitmap-usage/misc"
"bitmap-usage/model"
"encoding/json"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
"github.com/valyala/fasthttp"
"net/http"
)
func (as *MapAggregateService) FindPriceByX(rw http.ResponseWriter, r *http.Request) {
dec := json.NewDecoder(r.Body)
var findPriceRequest model.FindPriceRequest
err := dec.Decode(&findPriceRequest)
if err != nil {
misc.HandleDecodeError(rw, err)
return
}
price, err, _ := as.Index.FindPriceBy(findPriceRequest.OfferingId, findPriceRequest.GroupId,
findPriceRequest.PriceSpecId, findPriceRequest.CharValues)
if err != nil {
http.Error(rw, err.Error(), http.StatusNotFound)
return
}
encoder := json.NewEncoder(rw)
err = encoder.Encode(price)
if err != nil {
log.Err(err).Msg("Unable to encode object")
http.Error(rw, "Internal server error", http.StatusInternalServerError)
return
}
}
func (as *MapAggregateService) FindPriceByX_FastHttp(ctx *fasthttp.RequestCtx) {
var findPriceRequest model.FindPriceRequest
err := json.Unmarshal(ctx.Request.Body(), &findPriceRequest)
if err != nil {
ctx.Response.SetStatusCode(http.StatusInternalServerError)
//misc.HandleDecodeError(ctx, err) TODO
return
}
price, err, _ := as.Index.FindPriceBy(findPriceRequest.OfferingId, findPriceRequest.GroupId,
findPriceRequest.PriceSpecId, findPriceRequest.CharValues)
if err != nil {
ctx.Response.SetStatusCode(http.StatusNotFound)
ctx.Response.SetBodyString(err.Error())
return
}
encoder := json.NewEncoder(ctx.Response.BodyWriter())
err = encoder.Encode(price)
if err != nil {
log.Err(err).Msg("Unable to encode object")
ctx.Response.SetStatusCode(http.StatusInternalServerError)
return
}
}
func (as *MapAggregateService) FindPriceByX_Fiber(c *fiber.Ctx) error {
var findPriceRequest model.FindPriceRequest
err := json.Unmarshal(c.Body(), &findPriceRequest)
if err != nil {
c.Response().SetStatusCode(http.StatusInternalServerError)
//misc.HandleDecodeError(ctx, err) TODO
return nil
}
price, err, _ := as.Index.FindPriceBy(findPriceRequest.OfferingId, findPriceRequest.GroupId,
findPriceRequest.PriceSpecId, findPriceRequest.CharValues)
if err != nil {
c.Response().SetStatusCode(http.StatusNotFound)
c.Response().SetBodyString(err.Error())
return nil
}
encoder := json.NewEncoder(c.Response().BodyWriter())
err = encoder.Encode(price)
if err != nil {
log.Err(err).Msg("Unable to encode object")
c.Response().SetStatusCode(http.StatusInternalServerError)
return nil
}
return nil
}