87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.espin.casa/albert/cml04-gdm-int/internal/rspdb"
|
|
"git.espin.casa/albert/cml04-gdm-int/pkg/api"
|
|
)
|
|
|
|
type IService interface {
|
|
BdRollData(ctx context.Context, req *api.BdRollDataReq) (res *api.BdRollDataRes, err error)
|
|
UrRollData(ctx context.Context, req *api.UrRollDataReq) (res *api.UrRollDataRes, err error)
|
|
EdRollData(ctx context.Context, req *api.EdRollDataReq) (res *api.EdRollDataRes, err error)
|
|
UfRollData(ctx context.Context, req *api.UfRollDataReq) (res *api.UfRollDataRes, err error)
|
|
}
|
|
|
|
type service struct {
|
|
db *rspdb.RspDB
|
|
}
|
|
|
|
// BdRollData implements IService.
|
|
func (s *service) BdRollData(ctx context.Context, req *api.BdRollDataReq) (res *api.BdRollDataRes, err error) {
|
|
// gets break down roll data from database
|
|
bdData, err := s.db.GetBreakDownRollData(ctx, req.GetRollId())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// response
|
|
return &api.BdRollDataRes{
|
|
Msg: "data for bd success",
|
|
RollData: bdData,
|
|
TimeStamp: time.Now().UTC().Format(time.RFC3339),
|
|
}, nil
|
|
}
|
|
|
|
// EdRollData implements IService.
|
|
func (s *service) EdRollData(ctx context.Context, req *api.EdRollDataReq) (res *api.EdRollDataRes, err error) {
|
|
// gets edger roll data from database
|
|
edgerData, err := s.db.GetEdgerRollData(ctx, req.GetRollId())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// response
|
|
return &api.EdRollDataRes{
|
|
Msg: "data for ed success",
|
|
RollData: edgerData,
|
|
TimeStamp: time.Now().UTC().Format(time.RFC3339),
|
|
}, nil
|
|
}
|
|
|
|
// UfRollData implements IService.
|
|
func (s *service) UfRollData(ctx context.Context, req *api.UfRollDataReq) (res *api.UfRollDataRes, err error) {
|
|
// gets universal finishing roll data from database
|
|
ufData, err := s.db.GetUniversalFinishingRollData(ctx, req.GetRollId())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// response
|
|
return &api.UfRollDataRes{
|
|
Msg: "data for uf success",
|
|
RollData: ufData,
|
|
TimeStamp: time.Now().UTC().Format(time.RFC3339),
|
|
}, nil
|
|
}
|
|
|
|
// UrRollData implements IService.
|
|
func (s *service) UrRollData(ctx context.Context, req *api.UrRollDataReq) (res *api.UrRollDataRes, err error) {
|
|
// gets universal roll data from database
|
|
ufData, err := s.db.GetUniversalRoughingRollData(ctx, req.GetRollId())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// response
|
|
return &api.UrRollDataRes{
|
|
Msg: "data for ur success",
|
|
RollData: ufData,
|
|
TimeStamp: time.Now().UTC().Format(time.RFC3339),
|
|
}, nil
|
|
}
|
|
|
|
func NewService(db *rspdb.RspDB) IService {
|
|
return &service{
|
|
db: db,
|
|
}
|
|
}
|