Add PostgreSQL database option and more booking flow functionalities

This commit is contained in:
2023-05-08 01:29:59 +02:00
parent d8346a20be
commit e2e6759dc0
40 changed files with 1594 additions and 907 deletions

View File

@@ -3,6 +3,11 @@ package ocss
import (
"bytes"
"encoding/json"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
type PriceType int64
@@ -32,6 +37,10 @@ func (s PriceType) MarshalJSON() ([]byte, error) {
return buffer.Bytes(), nil
}
func (s PriceType) MarshalBSONValue() (bsontype.Type, []byte, error) {
return bson.MarshalValue(priceTypeToString[s])
}
func (bs *PriceType) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
@@ -43,8 +52,20 @@ func (bs *PriceType) UnmarshalJSON(b []byte) error {
return nil
}
type Price struct {
Type *PriceType `json:"type,omitempty"`
Amount *float64 `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
func (bs *PriceType) UnmarshalBSONValue(t bsontype.Type, b []byte) error {
if t == bsontype.Null || len(b) == 0 {
return nil
}
j, _, ok := bsoncore.ReadString(b)
if !ok {
return fmt.Errorf("cannot parse status")
}
*bs = priceTypeToID[j]
return nil
}
type Price struct {
Type *PriceType `json:"type,omitempty" bson:"type,omitempty"`
Amount *float64 `json:"amount,omitempty" bson:"amount,omitempty"`
Currency *string `json:"currency,omitempty" bson:"currency,omitempty"`
}