12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package service
- import (
- "context"
- "github.com/gin-gonic/gin"
- "github.com/issue9/conv"
- "github.com/sirupsen/logrus"
- "youngee_b_api/db"
- "youngee_b_api/model/common_model"
- "youngee_b_api/model/http_model"
- "youngee_b_api/pack"
- )
- var Selection *selection
- type selection struct {
- }
- func (s *selection) GetAllSelection(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) (*http_model.SelectionData, error) {
- SelectionList, total, err := db.GetSelectionList(ctx, enterpriseID, pageSize, pageNum, conditions)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetAllSelection error,err:%+v", err)
- return nil, err
- }
- SelectionListData := new(http_model.SelectionData)
- SelectionListData.SelectionInfo = pack.MGormSelectionToHttpSelectionPreview(SelectionList)
- SelectionListData.Total = conv.MustString(total)
- return SelectionListData, nil
- }
- func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId, enterpriseID string) (*http_model.SelectionDetail, error) {
- selectionDetail := http_model.SelectionDetail{}
- selectionInfo, err := db.GetSelectionInfo(ctx, selectionId)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionInfo error,err:%+v", err)
- return nil, err
- }
- selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionBriefInfo error,err:%+v", err)
- return nil, err
- }
- selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionExampleInfo error,err:%+v", err)
- return nil, err
- }
- productInfo, err := db.GetProductInfo(ctx, selectionId)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetProductInfo error,err:%+v", err)
- return nil, err
- }
- productPhotoInfo, err := db.GetProductPhotoInfo(ctx, selectionId)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[selection service] call GetProductPhotoInfo error,err:%+v", err)
- return nil, err
- }
- selectionDetail.SelectionBrief = selectionBriefInfo
- selectionDetail.SelectionInfo = selectionInfo
- selectionDetail.SelectionExample = selectionExampleInfo
- selectionDetail.ProductInfo = productInfo
- selectionDetail.ProductPhotoInfo = productPhotoInfo
- return &selectionDetail, nil
- }
|