Added create contact ednpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
@@ -8,42 +9,113 @@ import (
|
||||
|
||||
type Invoice struct {
|
||||
gorm.Model
|
||||
BuyerID uint
|
||||
BuyerName string
|
||||
BuyerAddress string
|
||||
BuyerEmail string
|
||||
BuyerPhone string
|
||||
SellerID uint
|
||||
SellerName string
|
||||
SellerAddress string
|
||||
SellerEmail string
|
||||
SellerPhone string
|
||||
PriceCents int64 `gorm:"column:price_cents"`
|
||||
Discount int64
|
||||
Tax int64
|
||||
TermsAndConditions string
|
||||
InvoiceName string
|
||||
InvoiceDate time.Time
|
||||
InvoiceDueDate time.Time
|
||||
ContractID uint
|
||||
InvoiceItem [] InvoiceItem
|
||||
Status string
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
|
||||
BuyerID uint `json:"buyerId"`
|
||||
BuyerName string `json:"buyerName"`
|
||||
BuyerAddress string `json:"buyerAddress"`
|
||||
BuyerEmail string `json:"buyerEmail"`
|
||||
BuyerPhone string `json:"buyerPhone"`
|
||||
SellerID uint `json:"sellerId"`
|
||||
SellerName string `json:"sellerName"`
|
||||
SellerAddress string `json:"sellerAddress"`
|
||||
SellerEmail string `json:"sellerEmail"`
|
||||
SellerPhone string `json:"sellerPhone"`
|
||||
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
|
||||
Discount int64 `json:"discount"`
|
||||
Tax int64 `json:"tax"`
|
||||
TermsAndConditions string `json:"termsAndConditions"`
|
||||
InvoiceName string `json:"invoiceName"`
|
||||
InvoiceDate time.Time `json:"invoiceDate"`
|
||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||
ContractID uint `json:"contractId"`
|
||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type InvoiceResponse struct {
|
||||
BaseModel
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
|
||||
BuyerID uint `json:"buyerId"`
|
||||
BuyerName string `json:"buyerName"`
|
||||
BuyerAddress string `json:"buyerAddress"`
|
||||
BuyerEmail string `json:"buyerEmail"`
|
||||
BuyerPhone string `json:"buyerPhone"`
|
||||
SellerID uint `json:"sellerId"`
|
||||
SellerName string `json:"sellerName"`
|
||||
SellerAddress string `json:"sellerAddress"`
|
||||
SellerEmail string `json:"sellerEmail"`
|
||||
SellerPhone string `json:"sellerPhone"`
|
||||
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
|
||||
Discount int64 `json:"discount"`
|
||||
Tax int64 `json:"tax"`
|
||||
TermsAndConditions string `json:"termsAndConditions"`
|
||||
InvoiceName string `json:"invoiceName"`
|
||||
InvoiceDate time.Time `json:"invoiceDate"`
|
||||
InvoiceDueDate time.Time `json:"invoiceDueDate"`
|
||||
ContractID uint `json:"contractId"`
|
||||
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
|
||||
var invoiceResponses []InvoiceResponse
|
||||
for _, invoice := range invoices {
|
||||
if invoice.InvoiceItem == nil {
|
||||
emptySlice := make([]InvoiceItem, 0)
|
||||
invoice.InvoiceItem = &emptySlice
|
||||
}
|
||||
|
||||
invoiceResponse := InvoiceResponse{
|
||||
BaseModel: BaseModel{
|
||||
ID: invoice.ID,
|
||||
CreatedAt: invoice.CreatedAt,
|
||||
UpdatedAt: invoice.UpdatedAt,
|
||||
},
|
||||
BuyerID: invoice.BuyerID,
|
||||
BuyerName: invoice.BuyerName,
|
||||
BuyerAddress: invoice.BuyerAddress,
|
||||
BuyerEmail: invoice.BuyerEmail,
|
||||
BuyerPhone: invoice.BuyerPhone,
|
||||
SellerID: invoice.SellerID,
|
||||
SellerName: invoice.SellerName,
|
||||
SellerAddress: invoice.SellerAddress,
|
||||
SellerEmail: invoice.SellerEmail,
|
||||
SellerPhone: invoice.SellerPhone,
|
||||
PriceCents: invoice.PriceCents,
|
||||
Discount: invoice.Discount,
|
||||
Tax: invoice.Tax,
|
||||
TermsAndConditions: invoice.TermsAndConditions,
|
||||
InvoiceName: invoice.InvoiceName,
|
||||
InvoiceDate: invoice.InvoiceDate,
|
||||
InvoiceDueDate: invoice.InvoiceDueDate,
|
||||
ContractID: invoice.ContractID,
|
||||
InvoiceItem: invoice.InvoiceItem,
|
||||
Status: invoice.Status,
|
||||
}
|
||||
invoiceResponses = append(invoiceResponses, invoiceResponse)
|
||||
}
|
||||
return invoiceResponses
|
||||
}
|
||||
|
||||
|
||||
|
||||
type ListInvoiceResponse struct {
|
||||
Status KeyValue `json:"Status"`
|
||||
Buyer CompanyShortResponse `json:"Buyer"`
|
||||
ContractID int
|
||||
DateCreated time.Time
|
||||
DueDate time.Time
|
||||
Amount string
|
||||
|
||||
Status KeyValue `json:"status"`
|
||||
Buyer CompanyShortResponse `json:"buyer"`
|
||||
ContractID int `json:"contractId"`
|
||||
DateCreated time.Time `json:"dateCreated"`
|
||||
DueDate time.Time `json:"dueDate"`
|
||||
Amount string `json:"amount"`
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
Key string
|
||||
Value string
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user