github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/web/api/models/monthly_payment.go (about) 1 package models 2 3 type AddMonthlyPaymentReq struct { 4 BaseRequest 5 6 MonthID uint `json:"month_id" validate:"required" example:"1"` 7 8 Title string `json:"title" validate:"required" example:"Rent"` 9 TypeID uint `json:"type_id"` 10 Notes string `json:"notes"` 11 Cost float64 `json:"cost" validate:"required" example:"1500"` 12 } 13 14 func (req *AddMonthlyPaymentReq) SanitizeAndCheck() error { 15 sanitizeString(&req.Title) 16 sanitizeString(&req.Notes) 17 18 if req.MonthID == 0 { 19 return emptyOrZeroFieldError("month_id") 20 } 21 if req.Title == "" { 22 return emptyFieldError("title") 23 } 24 // Skip Type 25 // Skip Notes 26 if req.Cost <= 0 { 27 return notPositiveFieldError("cost") 28 } 29 return nil 30 } 31 32 type AddMonthlyPaymentResp struct { 33 BaseResponse 34 35 ID uint `json:"id"` 36 } 37 38 type EditMonthlyPaymentReq struct { 39 BaseRequest 40 41 ID uint `json:"id" validate:"required" example:"1"` 42 Title *string `json:"title"` 43 TypeID *uint `json:"type_id"` 44 Notes *string `json:"notes"` 45 Cost *float64 `json:"cost"` 46 } 47 48 func (req *EditMonthlyPaymentReq) SanitizeAndCheck() error { 49 sanitizeString(req.Title) 50 sanitizeString(req.Notes) 51 52 if req.ID == 0 { 53 return emptyOrZeroFieldError("id") 54 } 55 if req.Title != nil && *req.Title == "" { 56 return emptyFieldError("title") 57 } 58 // Skip Type 59 // Skip Notes 60 if req.Cost != nil && *req.Cost <= 0 { 61 return notPositiveFieldError("cost") 62 } 63 return nil 64 } 65 66 type RemoveMonthlyPaymentReq struct { 67 BaseRequest 68 69 ID uint `json:"id" validate:"required" example:"1"` 70 } 71 72 func (req *RemoveMonthlyPaymentReq) SanitizeAndCheck() error { 73 if req.ID == 0 { 74 return emptyOrZeroFieldError("id") 75 } 76 return nil 77 }