84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package service
|
|
|
|
import "github.com/rogeecn/wxapp-kouqiang-guahao/backend/internal/db"
|
|
|
|
type ProjectView struct {
|
|
ID string `json:"id"`
|
|
CategoryID string `json:"category_id"`
|
|
Name string `json:"name"`
|
|
Subtitle string `json:"subtitle"`
|
|
PriceText string `json:"price_text"`
|
|
Image string `json:"image"`
|
|
}
|
|
|
|
type CategoryView struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Projects []ProjectView `json:"projects"`
|
|
}
|
|
|
|
type BookingView struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type BookingDayView struct {
|
|
Date string `json:"date"`
|
|
}
|
|
|
|
type BookingDetailView struct {
|
|
Booking BookingView `json:"booking"`
|
|
Project ProjectView `json:"project"`
|
|
Day BookingDayView `json:"day"`
|
|
Slot TimeSlotView `json:"slot"`
|
|
}
|
|
|
|
func ToProjectView(project db.Project) ProjectView {
|
|
return ProjectView{
|
|
ID: project.ID,
|
|
CategoryID: project.CategoryID,
|
|
Name: project.Name,
|
|
Subtitle: project.Subtitle,
|
|
PriceText: project.PriceText,
|
|
Image: project.Image,
|
|
}
|
|
}
|
|
|
|
func CategoryViews(categories []CategoryWithProjects) []CategoryView {
|
|
views := make([]CategoryView, 0, len(categories))
|
|
for _, category := range categories {
|
|
projects := make([]ProjectView, 0, len(category.Projects))
|
|
for _, project := range category.Projects {
|
|
projects = append(projects, ToProjectView(project))
|
|
}
|
|
views = append(views, CategoryView{
|
|
ID: category.ID,
|
|
Name: category.Name,
|
|
Projects: projects,
|
|
})
|
|
}
|
|
return views
|
|
}
|
|
|
|
func BookingDetailToView(detail BookingDetail) BookingDetailView {
|
|
return BookingDetailView{
|
|
Booking: BookingView{
|
|
ID: detail.Booking.ID,
|
|
Status: detail.Booking.Status,
|
|
},
|
|
Project: ToProjectView(detail.Project),
|
|
Day: BookingDayView{
|
|
Date: detail.Day.Date,
|
|
},
|
|
Slot: detail.Slot,
|
|
}
|
|
}
|
|
|
|
func BookingDetailsToViews(details []BookingDetail) []BookingDetailView {
|
|
views := make([]BookingDetailView, 0, len(details))
|
|
for _, detail := range details {
|
|
views = append(views, BookingDetailToView(detail))
|
|
}
|
|
return views
|
|
}
|