Documentation ¶
Overview ¶
Package model describes an internal architecture of application.
Two main data types of service are User and AdItem - they represents content of the service. Clients operates with this two data types through the server, that's core idea of the service.
Internal architecture of API ¶
This package contains several data types and interfaces that are used by other packages. API uses Model struct to access database and session manager not directly but through setted interface. It helps to make application with different technologies used in session manager and database without changing api package.
So, both db and sessionmanager packages must contain structure that implements interfaces from this package.
Data types ¶
User - a human that can sign up, sign in, logout, create ads and etc. Characteristics:
id unique identificator of user in database first name first name of user last name last name of user email email of user that must be unique password password of user that stored in database in hashed state telephone number telephone number of user about some additional information about user
Ad - main content of application Characteristics:
id unique identificator of ad in database title title of ad price price of ad country country where ad is situated city city where ad is situated subway station station where ad is situated images images of ad owner user which created this ad description additional information about this ad creation time time when this ad was created
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdItem ¶
type AdItem struct { ID int64 `db:"idad" json:"id" schema:"id,optional" valid:"-"` Title string `db:"title" json:"title" schema:"title,optional" valid:",optional"` // required in DB Price zero.Int `db:"price" json:"price,omitempty" schema:"price,optional" valid:"-"` Country zero.String `db:"country" json:"country,omitempty" schema:"country,optional" valid:"-"` // consists of printable ASCII City string `db:"city" json:"city,omitempty" schema:"city,optional" valid:",optional"` // required in DB SubwayStation zero.String `db:"subway_station" json:"subway_station,omitempty" schema:"subway_station,optional" valid:"-"` // consists of printable ASCII AdImages []string `db:"-" json:"ad_images," schema:"ad_images,optional" valid:"-"` AdImagesStr zero.String `db:"ad_images" json:"-" schema:"-" valid:"-"` // for database UserID int64 `db:"owner_ad" json:"-" schema:"-" valid:"-"` // for database User `json:"owner_ad" schema:"-" valid:"-"` Description string `db:"description_ad" json:"description_ad" schema:"description_ad,optional" valid:",optional"` // requiered in DB CreationTime time.Time `db:"creation_time" json:"creation_time" schema:"-" valid:"-"` }
AdItem struct describes ad which users are supposed to create, watch and etc.
type DB ¶
type DB interface { GetAd(adID int64) (*AdItem, error) GetAds(sp *SearchParams) ([]*AdItem, error) GetAdsOfUser(userID int64) ([]*AdItem, error) GetUserWithID(userID int64) (*User, error) GetUserWithEmail(email string) (*User, error) NewUser(user *User) (int64, error) NewAd(ad *AdItem) (int64, error) EditUser(user *User) (int64, error) EditAd(ad *AdItem) (int64, error) RemoveUser(userID int64) (int64, error) RemoveAd(adID int64) (int64, error) }
DB describes interface of database needed by API to communicate with it
type IM ¶
type IM interface { IsExist(key string) bool UploadImage(key string, body io.Reader) (string, error) DeleteImage(key string) error DownloadImage(key string) error }
IM interface describes interface for interaction with amazon s3
type Model ¶
Model is a struct that contains DB, IM and SM interfaces. Such project model allows to use different database and session manager implementation without changing business-logic. Model is used by API handlers.
type SM ¶
type SM interface { CreateSession(in *Session, expires bool) (*SessionID, error) CheckSession(in *SessionID) (*Session, error) DeleteSession(in *SessionID) error TryReconnect() error IsConnected() bool }
SM describes interface of session manager.
type SearchParams ¶
type SearchParams struct { Query string `db:"query" schema:"query,optional"` Limit int `db:"limit" schema:"limit,optional"` Offset int `db:"offset" schema:"offset,optional"` }
SearchParams is a struct that has information about filtering ads for client.
type SessionID ¶
type SessionID struct {
ID string
}
SessionID is used as identificator of user's session
type User ¶
type User struct { ID int64 `db:"id" json:"id" schema:"id,optional" valid:"-"` FirstName string `db:"first_name" json:"first_name" schema:"first_name,optional" valid:"utfletter,optional"` // required in DB LastName string `db:"last_name" json:"last_name" schema:"last_name,optional" valid:"utfletter,optional"` // required in DB Email string `db:"email" json:"email" schema:"email,optional" valid:"email,optional"` // required in DB Password string `db:"password_hash" json:"-" schema:"password,optional" valid:"printableascii,optional"` // required in DB TelNumber zero.String `db:"telephone" json:"tel_number,omitempty" schema:"tel_number,optional" valid:"-"` // consists of digits 1-9 About zero.String `db:"about" json:"about,omitempty" schema:"about,optional" valid:"-"` // consists of ASCII AvatarAddress zero.String `db:"avatar_address" json:"avatar_address,omitempty" schema:"avatar_address,optional" valid:"-"` RegTime time.Time `db:"reg_time" json:"reg_time" schema:"-" valid:"-"` }
User struct describes user of service