fix the get method
This commit is contained in:
parent
1dbd96eebd
commit
128bc30680
|
|
@ -57,6 +57,8 @@ backend_nam/
|
||||||
go run main.go # Local dev
|
go run main.go # Local dev
|
||||||
go build -o main . # Build binary
|
go build -o main . # Build binary
|
||||||
docker build -t nam-backend . # Docker build
|
docker build -t nam-backend . # Docker build
|
||||||
|
go test ./... # Run all tests
|
||||||
|
go test -v ./usecase/... # Run usecase tests
|
||||||
```
|
```
|
||||||
|
|
||||||
## NOTES
|
## NOTES
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func (c *NearestDeviceController) Route() {
|
||||||
nearestDevices.POST("/towers/search", c.getNearestTowers)
|
nearestDevices.POST("/towers/search", c.getNearestTowers)
|
||||||
nearestDevices.GET("/towers/:id", c.getNearestTowerByID)
|
nearestDevices.GET("/towers/:id", c.getNearestTowerByID)
|
||||||
|
|
||||||
nearestDevices.POST("/odp/search", c.getNearestODPDevices)
|
nearestDevices.GET("/odp/search", c.getNearestODPDevices)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,14 +176,44 @@ func (c *NearestDeviceController) getNearestDeviceByID(ctx *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NearestDeviceController) getNearestODPDevices(ctx *gin.Context) {
|
func (c *NearestDeviceController) getNearestODPDevices(ctx *gin.Context) {
|
||||||
var request req.NearestDeviceDTO
|
latStr := ctx.Query("latitude")
|
||||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
lngStr := ctx.Query("longitude")
|
||||||
common.ErrorResponses(ctx, http.StatusBadRequest, err.Error())
|
radiusStr := ctx.Query("radius")
|
||||||
|
|
||||||
|
if latStr == "" || lngStr == "" {
|
||||||
|
common.ErrorResponses(ctx, http.StatusBadRequest, "latitude and longitude are required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
latitude, err := strconv.ParseFloat(latStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(ctx, http.StatusBadRequest, "invalid latitude")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
longitude, err := strconv.ParseFloat(lngStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResponses(ctx, http.StatusBadRequest, "invalid longitude")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
radius := 0.3
|
||||||
|
if radiusStr != "" {
|
||||||
|
radius, err = strconv.ParseFloat(radiusStr, 64)
|
||||||
|
if err != nil || radius <= 0 {
|
||||||
|
common.ErrorResponses(ctx, http.StatusBadRequest, "invalid radius")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
odpType := "ODP"
|
odpType := "ODP"
|
||||||
request.DeviceType = &odpType
|
request := req.NearestDeviceDTO{
|
||||||
|
Latitude: latitude,
|
||||||
|
Longitude: longitude,
|
||||||
|
Radius: radius,
|
||||||
|
DeviceType: &odpType,
|
||||||
|
Limit: 10,
|
||||||
|
}
|
||||||
|
|
||||||
devices, err := c.nearestDeviceUC.GetNearestDevices(request)
|
devices, err := c.nearestDeviceUC.GetNearestDevices(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -195,13 +225,11 @@ func (c *NearestDeviceController) getNearestODPDevices(ctx *gin.Context) {
|
||||||
"devices": devices,
|
"devices": devices,
|
||||||
"total": len(devices),
|
"total": len(devices),
|
||||||
"search_params": gin.H{
|
"search_params": gin.H{
|
||||||
"latitude": request.Latitude,
|
"latitude": latitude,
|
||||||
"longitude": request.Longitude,
|
"longitude": longitude,
|
||||||
"radius": request.Radius,
|
"radius": radius,
|
||||||
"device_type": "ODP",
|
"device_type": "ODP",
|
||||||
"province": request.Province,
|
"unit": "kilometers",
|
||||||
"city": request.City,
|
|
||||||
"district": request.District,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ CONVENTIONS
|
||||||
- Validation uses validator.New() inside use cases
|
- Validation uses validator.New() inside use cases
|
||||||
- GeocodingService is injected via dependency injection (not instantiated in use cases)
|
- GeocodingService is injected via dependency injection (not instantiated in use cases)
|
||||||
- File naming uses snake_case; interfaces named {Entity}UseCase / {Entity}Repo
|
- File naming uses snake_case; interfaces named {Entity}UseCase / {Entity}Repo
|
||||||
- Tests follow existing project patterns and naming
|
- Test file: `{name}_test.go` with mock implementations
|
||||||
|
|
||||||
ANTI-PATTERNS
|
ANTI-PATTERNS
|
||||||
- Do not skip validation in use cases; always validate inputs via validator
|
- Do not skip validation in use cases; always validate inputs via validator
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue