|
@@ -1,71 +1,92 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
- "resource-server/common"
|
|
|
- "resource-server/dto"
|
|
|
- "resource-server/models"
|
|
|
+ "context"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
-func GetConfigList() ([]*dto.ConfigResp, error) {
|
|
|
- res := []*dto.ConfigResp{}
|
|
|
- var items []*models.ConfigItem
|
|
|
- query := models.DB.Model(&models.ConfigItem{})
|
|
|
- err := query.Order("id").Find(&items).Error
|
|
|
- if err != nil {
|
|
|
- return res, err
|
|
|
- }
|
|
|
- for _, c := range items {
|
|
|
- res = append(res, &dto.ConfigResp{
|
|
|
- Key: c.Key,
|
|
|
- Value: c.Value,
|
|
|
- OptionKey: c.OptionKey,
|
|
|
- ValueType: c.ValueType,
|
|
|
- Description: c.Description,
|
|
|
- Order: c.Order,
|
|
|
- IsEnabled: c.IsEnabled,
|
|
|
- Uri: c.Uri,
|
|
|
- })
|
|
|
- }
|
|
|
- return res, nil
|
|
|
+import (
|
|
|
+ "google.golang.org/grpc/codes"
|
|
|
+ "google.golang.org/grpc/metadata"
|
|
|
+ "google.golang.org/grpc/status"
|
|
|
+)
|
|
|
+
|
|
|
+import (
|
|
|
+ pb "resource-server/rpc_idl/dr_resource_pb"
|
|
|
+)
|
|
|
+
|
|
|
+type ConfigServer struct {
|
|
|
+ pb.UnimplementedConfigServer
|
|
|
}
|
|
|
|
|
|
-func GetConfigOptionList(flag string, enable bool) ([]*dto.ConfigOptionResp, error) {
|
|
|
- res := []*dto.ConfigOptionResp{}
|
|
|
- switch flag {
|
|
|
+func (s *ConfigServer) ConfigOptionList(ctx context.Context, in *pb.ConfigOptionListRequest) (*pb.ConfigOptionListReply, error) {
|
|
|
+ md, ok := metadata.FromIncomingContext(ctx)
|
|
|
+ if ok {
|
|
|
+ fmt.Printf("Received metadata: %v\n", md)
|
|
|
+ }
|
|
|
+ res := pb.ConfigOptionListReply{}
|
|
|
+ switch in.GetFlag() {
|
|
|
case "TimeFormat":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "HH:mm:ss", Value: "HH:mm:ss", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "HH:mm", Value: "HH:mm", Order: 2, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "HH-mm-ss", Value: "HH-mm-ss", Order: 3, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "HHmmss", Value: "HHmmss", Order: 4, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "hh:mm:ss tt", Value: "hh:mm:ss tt", Order: 5, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "TimeFormat", Text: "h:mm:ss tt", Value: "h:mm:ss tt", Order: 6, Enable: true})
|
|
|
+ //res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm:ss", Value: "HH:mm:ss", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm", Value: "HH:mm", Order: 2, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH-mm-ss", Value: "HH-mm-ss", Order: 3, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HHmmss", Value: "HHmmss", Order: 4, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "hh:mm:ss tt", Value: "hh:mm:ss tt", Order: 5, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "h:mm:ss tt", Value: "h:mm:ss tt", Order: 6, IsEnabled: true})
|
|
|
case "DateFormat":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy.MM.dd", Value: "yyyy.MM.dd", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy/M/d", Value: "yyyy/M/d", Order: 2, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "M-d-yyyy", Value: "M-d-yyyy", Order: 3, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy/M/dd", Value: "yyyy/M/dd", Order: 4, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy-MM-dd", Value: "yyyy-MM-dd", Order: 5, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "M-dd-yyyy", Value: "M-dd-yyyy", Order: 6, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy.M.dd", Value: "yyyy.M.dd", Order: 7, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy/MM/dd", Value: "yyyy/MM/dd", Order: 8, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "MMM-dd-yyyy", Value: "MMM-dd-yyyy", Order: 9, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "yyyy-MMM-dd", Value: "yyyy-MMM-dd", Order: 10, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "dd-MMM-yyyy", Value: "dd-MMM-yyyy", Order: 11, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DateFormat", Text: "dd.MM.yyyy", Value: "dd.MM.yyyy", Order: 12, Enable: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.MM.dd", Value: "yyyy.MM.dd", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/d", Value: "yyyy/M/d", Order: 2, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-d-yyyy", Value: "M-d-yyyy", Order: 3, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/dd", Value: "yyyy/M/dd", Order: 4, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MM-dd", Value: "yyyy-MM-dd", Order: 5, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-dd-yyyy", Value: "M-dd-yyyy", Order: 6, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.M.dd", Value: "yyyy.M.dd", Order: 7, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/MM/dd", Value: "yyyy/MM/dd", Order: 8, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "MMM-dd-yyyy", Value: "MMM-dd-yyyy", Order: 9, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MMM-dd", Value: "yyyy-MMM-dd", Order: 10, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd-MMM-yyyy", Value: "dd-MMM-yyyy", Order: 11, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd.MM.yyyy", Value: "dd.MM.yyyy", Order: 12, IsEnabled: true})
|
|
|
case "DoseUnit":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DoseUnit", Text: "rad", Value: "rad", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "DoseUnit", Text: "mGy", Value: "mGy", Order: 2, Enable: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "rad", Value: "rad", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "mGy", Value: "mGy", Order: 2, IsEnabled: true})
|
|
|
case "WeightUnit":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "WeightUnit", Text: "kg", Value: "kg", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "WeightUnit", Text: "pound", Value: "pound", Order: 2, Enable: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "kg", Value: "kg", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "pound", Value: "pound", Order: 2, IsEnabled: true})
|
|
|
case "LengthUnit":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "LengthUnit", Text: "cm", Value: "cm", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "LengthUnit", Text: "inch", Value: "inch", Order: 2, Enable: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "cm", Value: "cm", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "inch", Value: "inch", Order: 2, IsEnabled: true})
|
|
|
case "FontFamily":
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "FontFamily", Text: "Arial Unicode MS", Value: "Arial Unicode MS", Order: 1, Enable: true})
|
|
|
- res = append(res, &dto.ConfigOptionResp{Flag: "FontFamily", Text: "Arial", Value: "Arial", Order: 2, Enable: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial Unicode MS", Value: "Arial Unicode MS", Order: 1, IsEnabled: true})
|
|
|
+ res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial", Value: "Arial", Order: 2, IsEnabled: true})
|
|
|
default:
|
|
|
- return res, common.NotExists
|
|
|
+ return &res, status.Errorf(codes.NotFound, "flag %s not found", in.GetFlag())
|
|
|
}
|
|
|
- return res, nil
|
|
|
+ return &res, nil
|
|
|
}
|
|
|
+func (s *ConfigServer) ConfigList(ctx context.Context, in *pb.ConfigListRequest) (*pb.ConfigListResponse, error) {
|
|
|
+ return nil, status.Errorf(codes.Unimplemented, "method ConfigList not implemented")
|
|
|
+}
|
|
|
+
|
|
|
+//func GetConfigList() ([]*dto.ConfigResp, error) {
|
|
|
+// res := []*dto.ConfigResp{}
|
|
|
+// var items []*models.ConfigItem
|
|
|
+// query := models.DB.Model(&models.ConfigItem{})
|
|
|
+// err := query.Order("id").Find(&items).Error
|
|
|
+// if err != nil {
|
|
|
+// return res, err
|
|
|
+// }
|
|
|
+// for _, c := range items {
|
|
|
+// res = append(res, &dto.ConfigResp{
|
|
|
+// Key: c.Key,
|
|
|
+// Value: c.Value,
|
|
|
+// OptionKey: c.OptionKey,
|
|
|
+// ValueType: c.ValueType,
|
|
|
+// Description: c.Description,
|
|
|
+// Order: c.Order,
|
|
|
+// IsEnabled: c.IsEnabled,
|
|
|
+// Uri: c.Uri,
|
|
|
+// })
|
|
|
+// }
|
|
|
+// return res, nil
|
|
|
+//}
|