Documentation
¶
Index ¶
- Constants
- func DeleteListing(db *sql.DB, id string, userID int) (int, error)
- func DeleteSavedSearch(db *sql.DB, id string, userID int) (int, error)
- func DeleteSeek(db *sql.DB, id string, userID int) (int, error)
- func SendConfirmationEmail(input *EmailInput) (int, error)
- func SendNotificationEmail(input *EmailInput) (int, error)
- func SetStar(db *sql.DB, add bool, listingID string, userID int) (int, error)
- func UpdateListing(db *sql.DB, id string, listing Listing, userID int) (int, error)
- func UpdateSavedSearch(db *sql.DB, id string, savedSearch SavedSearch, userID int) (int, error)
- func UpdateSeek(db *sql.DB, id string, seek Seek, userID int) (int, error)
- type EmailInput
- type IsStarred
- type Listing
- func (l Listing) GetCreationDate() null.Time
- func (l Listing) GetDescription() null.String
- func (l Listing) GetIsActive() bool
- func (l Listing) GetLastModificationDate() null.Time
- func (l Listing) GetStatus() null.String
- func (l Listing) GetTitle() string
- func (l Listing) GetUserID() int
- func (l Listing) GetUsername() null.String
- type ListingQuery
- type ListingsOrder
- type MailTemplate
- type Post
- type PostReader
- type SavedSearch
- type SavedSearchQuery
- type Seek
- func (s Seek) GetCreationDate() null.Time
- func (s Seek) GetDescription() null.String
- func (s Seek) GetIsActive() bool
- func (s Seek) GetLastModificationDate() null.Time
- func (s Seek) GetStatus() null.String
- func (s Seek) GetTitle() string
- func (s Seek) GetUserID() int
- func (s Seek) GetUsername() null.String
- type SeekQuery
- type User
Constants ¶
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" )
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 ¶
DeleteListing deletes the listing in the database with the given id
func DeleteSavedSearch ¶
DeleteSavedSearch deletes the saved search in the database with the given id
func DeleteSeek ¶
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 UpdateListing ¶
UpdateListing overwrites the listing in the database with the given id with the given listing
func UpdateSavedSearch ¶
UpdateSavedSearch overwrites the saved search in the database with the given id with the given saved search
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 ¶
CreateListing inserts the given listing (belonging to userID) into the database. Returns the listing with its new KeyID added
func ReadListing ¶
ReadListing returns the listing with the given ID
func ReadListings ¶
ReadListings performs a customizable request for a collection of listings, as specified by a ListingQuery
func (Listing) GetCreationDate ¶
GetCreationDate returns the CreationDate of the Listing
func (Listing) GetDescription ¶
GetDescription returns the Description of the Listing
func (Listing) GetIsActive ¶
GetIsActive returns the IsActive of the Listing
func (Listing) GetLastModificationDate ¶
GetLastModificationDate returns the LastModificationDate of the Listing
func (Listing) GetUsername ¶
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 ¶
ReadListingAsPost is a PostReader for Listings
type PostReader ¶
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 ¶
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 ¶
CreateSeek inserts the given seek (belonging to userID) into the database. Returns the seek with its new KeyID added
func ReadSeeks ¶
ReadSeeks performs a customizable request for a collection of seeks, as specified by a SeekQuery
func (Seek) GetCreationDate ¶
GetCreationDate returns the CreationDate of the Seek
func (Seek) GetDescription ¶
GetDescription returns the Description of the Seek
func (Seek) GetIsActive ¶
GetIsActive returns the IsActive of the Seek
func (Seek) GetLastModificationDate ¶
GetLastModificationDate returns the LastModificationDate of the Seek
func (Seek) GetUsername ¶
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 ¶
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