forked from ebhomengo/niki
add cmd and bug fixed
This commit is contained in:
parent
3259a7468e
commit
787f338202
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/patientapp"
|
||||
"git.gocasts.ir/ebhomengo/niki/patientapp/config"
|
||||
"git.gocasts.ir/ebhomengo/niki/patientapp/repository/mysql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db := mysql.DataBase{}
|
||||
|
||||
cfg := config.Config{
|
||||
Port: 8080,
|
||||
Cors: config.Cors{
|
||||
AllowOrigins: []string{"*"},
|
||||
},
|
||||
ShutDownCtxTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
app := patientapp.Setup(cfg, &db)
|
||||
|
||||
app.Start()
|
||||
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ type DataBase struct {
|
|||
patients []entity.Patient
|
||||
}
|
||||
|
||||
func NewPatientRepo( /*conn *mysql.DB*/) *DataBase {
|
||||
func NewPatientRepo( /*conn *mysql.DB*/ ) *DataBase {
|
||||
patients, err := LoadPatientsFromJSON("C:\\Users\\cafel\\Documents\\gocast\\eb\\patientapp\\repository\\mysql\\rawdata.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
@ -36,21 +36,25 @@ func (db *DataBase) CountPatients(ctx context.Context, f analytic.PatientFilter)
|
|||
return len(db.patients), nil
|
||||
}
|
||||
|
||||
func (db *DataBase) SummaryByCity(ctx context.Context, provinceID uint, f analytic.PatientMapFilter) ([]entity.MapSummaryItem, error) {
|
||||
func (db *DataBase) SummaryByCity(ctx context.Context, provinceID uint, f analytic.PatientMapFilter) (map[uint][]entity.MapSummaryItem, error) {
|
||||
|
||||
var out []entity.MapSummaryItem
|
||||
//var out []entity.MapSummaryItem
|
||||
result := make(map[uint][]entity.MapSummaryItem, 0)
|
||||
|
||||
for _, patient := range db.patients {
|
||||
if patient.Address.ProvinceID == provinceID {
|
||||
out = append(out, entity.MapSummaryItem{
|
||||
out := entity.MapSummaryItem{
|
||||
LocationID: int64(patient.Address.ID),
|
||||
Name: patient.Address.Name,
|
||||
CentroidLat: patient.Address.Lat,
|
||||
CentroidLng: patient.Address.Lon,
|
||||
})
|
||||
}
|
||||
result[patient.Address.ProvinceID] = append(result[patient.Address.ProvinceID], out)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return out, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (db *DataBase) SummaryByProvince(ctx context.Context, f analytic.PatientMapFilter) (map[uint][]entity.MapSummaryItem, error) {
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ import (
|
|||
|
||||
type ListPatientAnalyticRequest struct {
|
||||
// All fields are optional
|
||||
MinAge *int `json:"minAge,omitempty"`
|
||||
MaxAge *int `json:"maxAge,omitempty"`
|
||||
Sex *entity.Sex `json:"sex,omitempty"`
|
||||
MinAge *int `query:"minAge,omitempty"`
|
||||
MaxAge *int `query:"maxAge,omitempty"`
|
||||
Sex *entity.Sex `query:"sex,omitempty"`
|
||||
|
||||
City *int64 `json:"city,omitempty"`
|
||||
Province *int64 `json:"province,omitempty"`
|
||||
City *int64 `query:"city,omitempty"`
|
||||
Province *int64 `query:"province,omitempty"`
|
||||
|
||||
Search *string `json:"search,omitempty"`
|
||||
Search *string `query:"search,omitempty"`
|
||||
|
||||
Limit int `json:"limit,omitempty"`
|
||||
Offset int `json:"offset,omitempty"`
|
||||
Limit int `query:"limit,omitempty"`
|
||||
Offset int `query:"offset,omitempty"`
|
||||
}
|
||||
|
||||
type PatientAnalyticItem struct {
|
||||
|
|
@ -53,16 +53,16 @@ func ToPatientResponse(patient entity.Patient) PatientAnalyticItem {
|
|||
// =========================== Map ==================================
|
||||
|
||||
type GetPatientMapSummaryRequest struct {
|
||||
Level entity.MapLevel `json:"level"`
|
||||
ParentID *int `json:"parentID"`
|
||||
Level entity.MapLevel `query:"level"`
|
||||
ParentID *int `query:"parentID"`
|
||||
|
||||
MinAge *int `json:"minAge,omitempty"`
|
||||
MaxAge *int `json:"maxAge,omitempty"`
|
||||
Sex *entity.Sex `json:"sex,omitempty"`
|
||||
Search *string `json:"search,omitempty"`
|
||||
MinAge *int `query:"minAge,omitempty"`
|
||||
MaxAge *int `query:"maxAge,omitempty"`
|
||||
Sex *entity.Sex `query:"sex,omitempty"`
|
||||
Search *string `query:"search,omitempty"`
|
||||
}
|
||||
|
||||
type GetPatientMapSummaryResponse struct {
|
||||
Level entity.MapLevel `json:"level"`
|
||||
Items []entity.MapSummaryItem `json:"items"`
|
||||
Level entity.MapLevel `json:"level"`
|
||||
Items map[uint][]entity.MapSummaryItem `json:"items"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ type Repository interface {
|
|||
GetPatients(ctx context.Context, f PatientFilter) ([]entity.Patient, error)
|
||||
CountPatients(ctx context.Context, f PatientFilter) (int, error)
|
||||
|
||||
SummaryByCity(ctx context.Context, provinceID int, f PatientMapFilter) ([]entity.MapSummaryItem, error)
|
||||
SummaryByProvince(ctx context.Context, countryID int, f PatientMapFilter) ([]entity.MapSummaryItem, error)
|
||||
SummaryByCity(ctx context.Context, provinceID int, f PatientMapFilter) (map[uint][]entity.MapSummaryItem, error)
|
||||
SummaryByProvince(ctx context.Context, f PatientMapFilter) (map[uint][]entity.MapSummaryItem, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
|
@ -106,7 +106,7 @@ func (s Service) GetMapSummary(ctx context.Context, req GetPatientMapSummaryRequ
|
|||
return GetPatientMapSummaryResponse{}, ErrInvalidCountryID
|
||||
}
|
||||
|
||||
items, err := s.repository.SummaryByProvince(ctx, *req.ParentID, filter)
|
||||
items, err := s.repository.SummaryByProvince(ctx, filter)
|
||||
if err != nil {
|
||||
return GetPatientMapSummaryResponse{}, fmt.Errorf("SummaryByProvince: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue