models

package
v0.0.0-...-6bfafd3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContactListingPoster is the email to the owner of a listing when a reader is interesting in buying
	ContactListingPoster MailTemplate = "b53ead7f-c9d7-4c17-9dcf-f59105b6eb65"
	// ContactListingReader is the email to confirm to a reader that they have contacted a listing's owner
	ContactListingReader = "d3adbb24-4445-43f8-a026-ec4b013b5850"
	// ContactSeekPoster is the email to the owner of a seek when a reader is interesting in selling
	ContactSeekPoster = "3bb3590f-04a3-4381-a79b-25a86afb4a6f"
	// ContactSeekReader is the email to confirm to a reader that they have contacted a seek's owner
	ContactSeekReader = "7bb4322d-f98d-417b-b148-90826fe212ab"
	// ContactSearchWatcher is the email to notify a user when their watched search has a new matching listing
	ContactSearchWatcher = "c6388de5-deb7-416b-9527-c5017513ed91"
)
View Source
const (
	// ListingsCreationDateDesc is creation date descending
	ListingsCreationDateDesc ListingsOrder = "listings.creation_date DESC"
	// ListingsCreationDateAsc is creation date ascending
	ListingsCreationDateAsc = "listings.creation_date ASC"
	// ListingsExpirationDateDesc is expiration date descending
	ListingsExpirationDateDesc = "listings.expiration_date DESC"
	// ListingsExpirationDateAsc is expiration date ascending
	ListingsExpirationDateAsc = "listings.expiration_date ASC"
	// ListingsPriceDesc is price descending
	ListingsPriceDesc = "listings.price DESC"
	// ListingsPriceAsc is price ascending
	ListingsPriceAsc = "listings.price ASC"
)

Variables

This section is empty.

Functions

func DeleteListing

func DeleteListing(db *sql.DB, id string, userID int) (int, error)

DeleteListing deletes the listing in the database with the given id

func DeleteSavedSearch

func DeleteSavedSearch(db *sql.DB, id string, userID int) (int, error)

DeleteSavedSearch deletes the saved search in the database with the given id

func DeleteSeek

func DeleteSeek(db *sql.DB, id string, userID int) (int, error)

DeleteSeek deletes the seek in the database with the given id

func SendConfirmationEmail

func SendConfirmationEmail(input *EmailInput) (int, error)

SendConfirmationEmail sends an email to the sender of an EmailInput

func SendNotificationEmail

func SendNotificationEmail(input *EmailInput) (int, error)

SendNotificationEmail sends an email to the recipient of an EmailInput

func SetStar

func SetStar(db *sql.DB, add bool, listingID string, userID int) (int, error)

SetStar adds or removes a star, depending on whether add is set to true

func UpdateListing

func UpdateListing(db *sql.DB, id string, listing Listing, userID int) (int, error)

UpdateListing overwrites the listing in the database with the given id with the given listing

func UpdateSavedSearch

func UpdateSavedSearch(db *sql.DB, id string, savedSearch SavedSearch, userID int) (int, error)

UpdateSavedSearch overwrites the saved search in the database with the given id with the given saved search

func UpdateSeek

func UpdateSeek(db *sql.DB, id string, seek Seek, userID int) (int, error)

UpdateSeek overwrites the seek in the database with the given id with the given seek

Types

type EmailInput

type EmailInput struct {
	Sender    string
	Recipient string
	Subject   string
	Body      string `json:"body"`
	Template  MailTemplate
}

An EmailInput contains the necessary parameters for the creation of an email

func NewEmailInput

func NewEmailInput(db *sql.DB, id string, read PostReader) (*EmailInput, int, error)

NewEmailInput creates a new EmailInput with the appropriate default values

type IsStarred

type IsStarred struct {
	IsStarred bool `json:"isStarred"`
}

An IsStarred is the body of a request to SetStar

type Listing

type Listing struct {
	KeyID                int            `json:"keyId"`
	CreationDate         null.Time      `json:"creationDate"`
	LastModificationDate null.Time      `json:"lastModificationDate"`
	Title                string         `json:"title"`
	Description          null.String    `json:"description"`
	UserID               int            `json:"userId"`
	Username             null.String    `json:"username"`
	Price                null.Int       `json:"price"`
	Status               null.String    `json:"status"`
	ExpirationDate       null.Time      `json:"expirationDate"`
	Thumbnail            null.String    `json:"thumbnail"`
	Photos               pq.StringArray `json:"photos"`
	IsStarred            bool           `json:"isStarred"`
	IsActive             bool           `json:"isActive"`
	Keywords             pq.StringArray
}

A Listing is a record type storing a row of the listings table

func CreateListing

func CreateListing(db *sql.DB, listing Listing, userID int) (Listing, int, error)

CreateListing inserts the given listing (belonging to userID) into the database. Returns the listing with its new KeyID added

func ReadListing

func ReadListing(db *sql.DB, id string, userID int) (Listing, int, error)

ReadListing returns the listing with the given ID

func ReadListings

func ReadListings(db *sql.DB, query *ListingQuery) ([]*Listing, int, error)

ReadListings performs a customizable request for a collection of listings, as specified by a ListingQuery

func (Listing) GetCreationDate

func (l Listing) GetCreationDate() null.Time

GetCreationDate returns the CreationDate of the Listing

func (Listing) GetDescription

func (l Listing) GetDescription() null.String

GetDescription returns the Description of the Listing

func (Listing) GetIsActive

func (l Listing) GetIsActive() bool

GetIsActive returns the IsActive of the Listing

func (Listing) GetLastModificationDate

func (l Listing) GetLastModificationDate() null.Time

GetLastModificationDate returns the LastModificationDate of the Listing

func (Listing) GetStatus

func (l Listing) GetStatus() null.String

GetStatus returns the Status of the Listing

func (Listing) GetTitle

func (l Listing) GetTitle() string

GetTitle returns the Title of the Listing

func (Listing) GetUserID

func (l Listing) GetUserID() int

GetUserID returns the UserID of the Listing

func (Listing) GetUsername

func (l Listing) GetUsername() null.String

GetUsername returns the Username of the Listing

type ListingQuery

type ListingQuery struct {
	Query         string
	OnlyStarred   bool
	OnlyMine      bool
	OnlyPhotos    bool
	OnlyActive    bool
	Order         ListingsOrder
	Limit         uint64 // maximum number of listings to return
	Offset        uint64 // offset in search results to send
	UserID        int
	MinPrice      int
	MaxPrice      int
	MinExpDate    time.Time
	MaxExpDate    time.Time
	MinCreateDate time.Time
	MaxCreateDate time.Time
}

A ListingQuery contains the necessary parameters for a parametrized query of the listings table

func NewListingQuery

func NewListingQuery() *ListingQuery

NewListingQuery creates a LisitngQuery with the appropriate default values

type ListingsOrder

type ListingsOrder string

A ListingsOrder is a legal string for a reading SQL query to order by

type MailTemplate

type MailTemplate string

MailTemplate indicates what SendGrid template to use on the email

type Post

type Post interface {
	GetCreationDate() null.Time
	GetLastModificationDate() null.Time
	GetTitle() string
	GetDescription() null.String
	GetUserID() int
	GetUsername() null.String
	GetStatus() null.String
	GetIsActive() bool
}

A Post is made by a User and contains

func ReadListingAsPost

func ReadListingAsPost(db *sql.DB, id string) (Post, int, error)

ReadListingAsPost is a PostReader for Listings

func ReadSeekAsPost

func ReadSeekAsPost(db *sql.DB, id string) (Post, int, error)

ReadSeekAsPost is a PostReader for Seek

type PostReader

type PostReader (func(*sql.DB, string) (Post, int, error))

A PostReader is a function which queries the appropriate table for the post with the given ID

type SavedSearch

type SavedSearch struct {
	KeyID                 int         `json:"keyId"`
	CreationDate          null.Time   `json:"creationDate"`
	LastModificationDate  null.Time   `json:"lastModificationDate"`
	Query                 null.String `json:"query"`
	MinPrice              null.Int    `json:"minPrice"`
	MaxPrice              null.Int    `json:"maxPrice"`
	ListingExpirationDate null.Time   `json:"listingExpirationDate"`
	SearchExpirationDate  null.Time   `json:"searchExpirationDate"`
	IsActive              bool        `json:"isActive"`
}

A SavedSearch is a record type storing a row of the saved searches table

func CreateSavedSearch

func CreateSavedSearch(db *sql.DB, savedSearch SavedSearch, userID int) (SavedSearch, int, error)

CreateSavedSearch inserts the given saved search (belonging to userID) into the database. Returns the Saved Search with its new KeyID added

func ReadSavedSearch

func ReadSavedSearch(db *sql.DB, id string, userID int) (SavedSearch, int, error)

ReadSavedSearch returns the listing with the given ID

func ReadSavedSearches

func ReadSavedSearches(db *sql.DB, query *SavedSearchQuery) ([]*SavedSearch, int, error)

ReadSavedSearches performs a customizable request for a collection of saved searches, as specified by a SavedSearchQuery

type SavedSearchQuery

type SavedSearchQuery struct {
	Limit  uint64 // maximum number of listings to return
	Offset uint64 // offset in search results to send
	UserID int
}

A SavedSearchQuery contains the necessary parameters for a parametrized query of the saved searches table

func NewSavedSearchQuery

func NewSavedSearchQuery() *SavedSearchQuery

NewSavedSearchQuery makes a new SavedSearchQuery with the appropriate default values

type Seek

type Seek struct {
	KeyID                int         `json:"keyId"`
	CreationDate         null.Time   `json:"creationDate"`
	LastModificationDate null.Time   `json:"lastModificationDate"`
	Title                string      `json:"title"`
	Description          null.String `json:"description"`
	UserID               int         `json:"userId"`
	Username             null.String `json:"username"`
	SavedSearchID        null.Int    `json:"watchId"`
	NotifyEnabled        null.Bool   `json:"notifyEnabled"`
	Status               null.String `json:"status"`
	IsActive             bool        `json:"isActive"`
}

A Seek is a record type storing a row of the seeks table

func CreateSeek

func CreateSeek(db *sql.DB, seek Seek, userID int) (Seek, int, error)

CreateSeek inserts the given seek (belonging to userID) into the database. Returns the seek with its new KeyID added

func ReadSeek

func ReadSeek(db *sql.DB, id string) (Seek, int, error)

ReadSeek returns the seek with the given ID

func ReadSeeks

func ReadSeeks(db *sql.DB, query *SeekQuery) ([]*Seek, int, error)

ReadSeeks performs a customizable request for a collection of seeks, as specified by a SeekQuery

func (Seek) GetCreationDate

func (s Seek) GetCreationDate() null.Time

GetCreationDate returns the CreationDate of the Seek

func (Seek) GetDescription

func (s Seek) GetDescription() null.String

GetDescription returns the Description of the Seek

func (Seek) GetIsActive

func (s Seek) GetIsActive() bool

GetIsActive returns the IsActive of the Seek

func (Seek) GetLastModificationDate

func (s Seek) GetLastModificationDate() null.Time

GetLastModificationDate returns the LastModificationDate of the Seek

func (Seek) GetStatus

func (s Seek) GetStatus() null.String

GetStatus returns the Status of the Seek

func (Seek) GetTitle

func (s Seek) GetTitle() string

GetTitle returns the Title of the Seek

func (Seek) GetUserID

func (s Seek) GetUserID() int

GetUserID returns the UserID of the Seek

func (Seek) GetUsername

func (s Seek) GetUsername() null.String

GetUsername returns the Username of the Seek

type SeekQuery

type SeekQuery struct {
	Query      string
	OnlyMine   bool
	OnlyActive bool
	Limit      uint64 // maximum number of listings to return
	Offset     uint64 // offset in search results to send
	UserID     int
}

A SeekQuery contains the necessary parameters for a parametrized query of the seeks table

func NewSeekQuery

func NewSeekQuery() *SeekQuery

NewSeekQuery creates a SeekQuery with the appropriate default values

type User

type User struct {
	KeyID                int       `json:"keyId"`
	CreationDate         null.Time `json:"creationDate"`
	LastModificationDate null.Time `json:"lastModificationDate"`
	NetID                string    `json:"netId"`
}

A User is a record type storing a row of the users table

func GetOrCreateUser

func GetOrCreateUser(db *sql.DB, netID string) (*User, error)

GetOrCreateUser makes sure the netID exists in the db, creating it if it doesn't already. Security Note: DO NOT allow user-generated data into this function. This assumes the netID is from CAS

func GetUser

func GetUser(db *sql.DB, netID string) (*User, error)

GetUser gets the specified user. If user does not exist, returns an error

func GetUserByID

func GetUserByID(db *sql.DB, id int) (*User, error)

GetUserByID gets the specified user. If user does not exist, returns an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL