insapp

package module
v0.0.0-...-9ea8f80 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: GPL-3.0 Imports: 33 Imported by: 0

README

insapp-go

Go Report Card

Backend part of Insapp written in Go

Installation

go get
go get github.com/thomas-bouvier/insapp-go/...
API

Check that you have MongoDB running.

insapp-api

The process is listening on 0.0.0.0:9000 by default.

CLI
insapp-cli
Docker
Build
docker build -t insapp-go .
Run
docker run -it insapp-go

To ssh into this container, use the following command:

docker exec -it insapp-go ash

Configuration

Edit the configuration file:

cp config.json.dist config.json
vi config.json

Attributes google_email and google_password refer to the credentials of your Google account. These credentials are used to send emails. mongo_password refers to the MongoDB password. env refers to the environment type and should be set to prod, dev or local. Finally, port refers to the API port.

In a local environment:

  • Cookies are not secure ;
  • Push notifications are not sent.

The FCM HTTP v1 API requires some credentials to send push notifications. The service-account.json file can be downloaded from the Firebase Cloud Messaging dashboard, and should be copied at the root of this directory. This way, it will be included in the Docker container.

The authentication mechanism relies on JWT tokens and thus needs a secret key. Please generate the following keys at the root of this directory:

openssl genrsa -out app.rsa 2048
openssl rsa -in app.rsa -pubout > app.rsa.pub

API Endpoints

Public routes
Type Endpoint calls Description
GET / Index
GET /how-to-post Get the tutorial for posting content
GET /credit Get the credits
GET /legal Get the legal conditions
POST /login/association Log an association in
POST /login/user/{ticket} Log a user in with the ticket {ticket} provided by CAS
User routes
Type Endpoint calls Description
GET /associations Get all associations
GET /associations/{id} Get the association with id {id}
GET /associations/{id}/events Get all events of the association with id {id}
GET /associations/{id}/posts Get all posts of the association with id {id}
GET /events Get all future events
GET /events/{id} Get the event with id {id}
POST /events/{id}/attend/{userID}/status/{status} Post the attendee status {status} for the user with id {userID} on the event with id {id}
DELETE /events/{id}/attend/{userID} Delete the attendee status of the user with id {userID} on the event with id {id}
POST /events/{id}/comment Post a comment on the event with id {id}
DELETE /events/{id}/comment/{commentID} Delete the comment with id {commentID} on the event with id {id}
GET /posts Get all posts. You can provide ?range=[{start},{count}] to get only some posts
GET /posts/{id} Get the post with id {id}
POST /posts/{id}/like/{userID} Post a like for the user with id {userID} on the post with id {id}
DELETE /posts/{id}/like/{userID} Post an unlike for the user with id {userID} on the post with id {id}
POST /posts/{id}/comment Post a comment on the post with id {id}
DELETE /posts/{id}/comment/{commentID} Delete the comment with id {commentID} on the post with id {id}
GET /users/{id} Get the user with id {id}
PUT /users/{id} Update the user with id {id}
DELETE /users/{id} Delete the user with id {id}
POST /notifications Create a notification
GET /notifications/{userID} Get all notifications of the user with id {userID}
DELETE /notifications/{userID}/{id} Delete the notification with id {id} for the user with id {userID}
PUT /report/user/{userID} Report the user with id {userID}
PUT /report/{postID}/comment/{commentID} Report the comment with id {commentID} on the post with id {postID}
POST /search Search for users, associations, events and posts
POST /search/users Search for users
POST /search/associations Search for associations
POST /search/events Search for events
POST /search/posts Search for posts
POST /logout/user Logout the current user
Association routes
Type Endpoint calls Description
GET /association Get the current association
PUT /associations/{id} Update the association with id {id}
POST /events Create an event
PUT /events/{id} Update the event with id {id}
DELETE /events/{id} Delete the event with id {id}
POST /posts Create a post
PUT /posts/{id} Update the post with id {id}
DELETE /posts/{id} Delete the post with id {id}
POST /images Post an image
POST /logout/association Logout the current association user
Super user routes
Type Endpoint calls Description
POST /associations Create an association
DELETE /associations/{id} Delete the association with id {id}
GET /associations/{ownerID}/myassociations Get the associations owned by the association with id {ownerID}
GET /users Get all users

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAssociationController

func AddAssociationController(w http.ResponseWriter, r *http.Request)

AddAssociationController will answer a JSON of the brand new created association (from the JSON Body) Should be protected

func AddAssociationUser

func AddAssociationUser(user AssociationUser)

AddAssociationUser will add the given AssociationUser to the database

func AddAttendeeController

func AddAttendeeController(w http.ResponseWriter, r *http.Request)

func AddAttendeeToGoingList

func AddAttendeeToGoingList(id bson.ObjectId, userID bson.ObjectId) (Event, User)

AddAttendeeToGoingList will add the given userID to the given eventID as an attendee

func AddAttendeeToMaybeList

func AddAttendeeToMaybeList(id bson.ObjectId, userID bson.ObjectId) (Event, User)

func AddAttendeeToNotGoingList

func AddAttendeeToNotGoingList(id bson.ObjectId, userID bson.ObjectId) (Event, User)

func AddEventController

func AddEventController(w http.ResponseWriter, r *http.Request)

AddEventController will answer the JSON of the brand new created Event from the JSON body Should be protected

func AddPostController

func AddPostController(w http.ResponseWriter, r *http.Request)

AddPostController will answer a JSON of the brand new created post (from the JSON Body) Should be protected

func AddUserController

func AddUserController(w http.ResponseWriter, r *http.Request)

AddUserController will answer a JSON of the brand new created user (from the JSON Body)

func ArchiveImage

func ArchiveImage(fileName string) error

ArchiveImage will move images in a subdirectory "archive"

func AuthMiddleware

func AuthMiddleware(next http.HandlerFunc, role string) http.HandlerFunc

AuthMiddleware makes sure the user is authenticated before handling the request.

func ChangeAttendeeStatusController

func ChangeAttendeeStatusController(w http.ResponseWriter, r *http.Request)

AddAttendeeController will answer the JSON of the event with the given attendee added

func CheckAndRefreshStringTokens

func CheckAndRefreshStringTokens(authStringToken string, refreshStringToken string, role string) (*jwt.Token, *jwt.Token, error)

CheckAndRefreshStringTokens renews the auth token, if needed.

func CommentEventController

func CommentEventController(w http.ResponseWriter, r *http.Request)

CommentEventController will answer a JSON of the event

func CommentPostController

func CommentPostController(w http.ResponseWriter, r *http.Request)

CommentPostController will answer a JSON of the post

func ContainsString

func ContainsString(slice []string, element string) bool

ContainsString returns true if slice contains element

func CreateNewTokens

func CreateNewTokens(ID bson.ObjectId, role string) (*jwt.Token, *jwt.Token)

CreateNewTokens creates auth and refresh tokens.

func CreateOrUpdateNotificationUser

func CreateOrUpdateNotificationUser(user NotificationUser)

func Credit

func Credit(w http.ResponseWriter, r *http.Request)

Credit show a credit page

func DeleteAssociationController

func DeleteAssociationController(w http.ResponseWriter, r *http.Request)

DeleteAssociationController will answer a JSON of an empty association if the deletion has succeed Should be protected

func DeleteCommentsForUser

func DeleteCommentsForUser(userID bson.ObjectId)

func DeleteCommentsForUserOnEvents

func DeleteCommentsForUserOnEvents(userID bson.ObjectId)

func DeleteEventController

func DeleteEventController(w http.ResponseWriter, r *http.Request)

DeleteEventController will answer an empty JSON if the deletion has succeed Should be protected

func DeleteImage

func DeleteImage(fileName string) error

DeleteImage will permanently delete an image

func DeleteNotificationController

func DeleteNotificationController(w http.ResponseWriter, r *http.Request)

func DeleteNotificationTokenForUser

func DeleteNotificationTokenForUser(id bson.ObjectId)

func DeleteNotificationsForComment

func DeleteNotificationsForComment(id bson.ObjectId)

func DeleteNotificationsForEvent

func DeleteNotificationsForEvent(id bson.ObjectId)

func DeleteNotificationsForPost

func DeleteNotificationsForPost(id bson.ObjectId)

func DeleteNotificationsForUser

func DeleteNotificationsForUser(id bson.ObjectId)

func DeletePostController

func DeletePostController(w http.ResponseWriter, r *http.Request)

DeletePostController will answer a JSON of an empty post if the deletion has succeed Should be protected

func DeleteTagsForUser

func DeleteTagsForUser(userID bson.ObjectId)

func DeleteTagsForUserOnEvents

func DeleteTagsForUserOnEvents(userID bson.ObjectId)

func DeleteTokenCookies

func DeleteTokenCookies(w *http.ResponseWriter, r *http.Request)

DeleteTokenCookies deletes the cookies

func DeleteUserController

func DeleteUserController(w http.ResponseWriter, r *http.Request)

DeleteUserController will answer a JSON of an empty user if the deletion succeeded. Should be protected

func DislikePostController

func DislikePostController(w http.ResponseWriter, r *http.Request)

DislikePostController will answer a JSON of the post and the user that disliked the post

func DislikePostWithUser

func DislikePostWithUser(id bson.ObjectId, userID bson.ObjectId) (Post, User)

DislikePostWithUser will remove the user to the list of users that liked the post (cf. Likes field)

func GeneratePassword

func GeneratePassword() string

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string.

func GetAllAssociationsController

func GetAllAssociationsController(w http.ResponseWriter, r *http.Request)

GetAllAssociationsController will answer a JSON of all associations

func GetAllPostsController

func GetAllPostsController(w http.ResponseWriter, r *http.Request)

GetAllPostsController will answer a JSON of the N latest posts. Here N = 50.

func GetAllUserController

func GetAllUserController(w http.ResponseWriter, r *http.Request)

func GetAssociationController

func GetAssociationController(w http.ResponseWriter, r *http.Request)

GetAssociationController will answer a JSON of the association linked to the given id in the URL

func GetAssociationUserController

func GetAssociationUserController(w http.ResponseWriter, r *http.Request)

func GetEventController

func GetEventController(w http.ResponseWriter, r *http.Request)

GetEventController will answer a JSON of the event from the given "id" in the URL. (cf Routes in routes.go)

func GetEventsForAssociationController

func GetEventsForAssociationController(w http.ResponseWriter, r *http.Request)

func GetFutureEventsController

func GetFutureEventsController(w http.ResponseWriter, r *http.Request)

GetFutureEventsController will answer a JSON containing all future events from "NOW"

func GetImageColors

func GetImageColors(fileName string) [][]int

GetImageColors will return a palette of colors found in the image

func GetImageDimension

func GetImageDimension(fileName string) (int, int)

GetImageDimension will return image dimention in pixels

func GetImagesNames

func GetImagesNames() ([]string, error)

GetImagesNames will return a string of all images in cdn

func GetMD5Hash

func GetMD5Hash(text string) string

func GetMongoSession

func GetMongoSession() *mgo.Session

GetMongoSession creates a new session. If there is an active mongo session it will return a Clone.

func GetMyAssociationController

func GetMyAssociationController(w http.ResponseWriter, r *http.Request)

GetMyAssociationController will answer a JSON of the associations owned by the applicant master association

func GetMyAssociations

func GetMyAssociations(id bson.ObjectId) []bson.ObjectId

GetMyAssociations will return an array of all ID from owned existing Association

func GetNotificationController

func GetNotificationController(w http.ResponseWriter, r *http.Request)

func GetPostController

func GetPostController(w http.ResponseWriter, r *http.Request)

GetPostController will answer a JSON of the post linked to the given id in the URL

func GetPostsForAssociationController

func GetPostsForAssociationController(w http.ResponseWriter, r *http.Request)

GetPostsForAssociationController will answer a JSON of the post owned by the given association

func GetUserController

func GetUserController(w http.ResponseWriter, r *http.Request)

GetUserController will answer a JSON of the user linked to the given id in the URL

func GetUserFromRequest

func GetUserFromRequest(r *http.Request) (bson.ObjectId, error)

GetUserFromRequest returns the User or AssociationUser ID from the auth cookie.

func HowToPost

func HowToPost(w http.ResponseWriter, r *http.Request)

HowToPost show a page explaining how to post for associations

func Index

func Index(w http.ResponseWriter, r *http.Request)

Index is just a test actually

func InitJWT

func InitJWT() error

InitJWT reads the key files before starting http handlers

func Legal(w http.ResponseWriter, r *http.Request)

Legal show a legal page

func LikePostController

func LikePostController(w http.ResponseWriter, r *http.Request)

LikePostController will answer a JSON of the post and the user that liked the post

func LikePostWithUser

func LikePostWithUser(id bson.ObjectId, userID bson.ObjectId) (Post, User)

LikePostWithUser will add the user to the list of user that liked the post (cf. Likes field)

func LoginAssociationController

func LoginAssociationController(w http.ResponseWriter, r *http.Request)

LoginAssociationController logs an association in.

func LoginUserController

func LoginUserController(w http.ResponseWriter, r *http.Request)

LoginUserController logs a user in using CAS. If the ticket is valid, auth and refresh tokens are generated.

func LogoutAssociationController

func LogoutAssociationController(w http.ResponseWriter, r *http.Request)

LogoutAssociationController logs an association out.

func LogoutUserController

func LogoutUserController(w http.ResponseWriter, r *http.Request)

LogoutUserController logs a user out.

func NewRouter

func NewRouter() *mux.Router

NewRouter is the constructor of the Router It will create every routes from the routes variable just above

func RandomString

func RandomString(strlen int) string

func RemoveAttendee

func RemoveAttendee(id bson.ObjectId, userID bson.ObjectId, list string) (Event, User)

RemoveAttendee remove the given userID from the given eventID as a participant

func RemoveAttendeeController

func RemoveAttendeeController(w http.ResponseWriter, r *http.Request)

RemoveAttendeeController will answer the JSON of the event without the given attendee added

func ReportComment

func ReportComment(id bson.ObjectId, commentID bson.ObjectId, reporterID bson.ObjectId)

func ReportCommentController

func ReportCommentController(w http.ResponseWriter, r *http.Request)

func ReportUser

func ReportUser(id bson.ObjectId, reporterID bson.ObjectId)

func ReportUserController

func ReportUserController(w http.ResponseWriter, r *http.Request)

func ResizeImage

func ResizeImage(imageName string, newWidth uint, newHeight uint) (string, error)

ResizeImage will resize an image as jpeg and response its new name Put 0 to newWidth or newHeight to make it automatically calculate to keep aspect ratio.

func ResponseHandler

func ResponseHandler(w *http.ResponseWriter, fileName string, err error)

ResponseHandler will response to the client

func RevokeRefreshStringToken

func RevokeRefreshStringToken(refreshStringToken string) error

RevokeRefreshStringToken deletes the given token from the database, if valid.

func SearchAssociationController

func SearchAssociationController(w http.ResponseWriter, r *http.Request)

func SearchEventController

func SearchEventController(w http.ResponseWriter, r *http.Request)

func SearchPostController

func SearchPostController(w http.ResponseWriter, r *http.Request)

func SearchUniversalController

func SearchUniversalController(w http.ResponseWriter, r *http.Request)

func SearchUserController

func SearchUserController(w http.ResponseWriter, r *http.Request)

func SendAssociationEmailForCommentOnEvent

func SendAssociationEmailForCommentOnEvent(email string, event Event, comment Comment, user User) error

SendAssociationEmailForCommentOnEvent sends an email indicating a new comment has been added on an event

func SendAssociationEmailForCommentOnPost

func SendAssociationEmailForCommentOnPost(email string, post Post, comment Comment, user User) error

SendAssociationEmailForCommentOnPost sends an email indicating a new comment has been added on a post

func SendAssociationEmailSubscription

func SendAssociationEmailSubscription(email string, password string) error

SendAssociationEmailSubscription sends a subscription email containing the credentials.

func SendEmail

func SendEmail(to string, subject string, body string)

SendEmail sends an email to the given recipient.

func TriggerNotificationForEvent

func TriggerNotificationForEvent(event Event, sender bson.ObjectId, content bson.ObjectId, message string)

TriggerNotificationForEvent sends a notification and a push notification to users targeted by the promotion. Push notifications are not sent in a local environment.

func TriggerNotificationForPost

func TriggerNotificationForPost(post Post, sender bson.ObjectId, content bson.ObjectId, message string)

TriggerNotificationForPost sends a notification and a push notification to users targeted by the promotion. Push notifications are not sent in a local environment.

func TriggerNotificationForUserFromEvent

func TriggerNotificationForUserFromEvent(sender bson.ObjectId, receiver bson.ObjectId, content bson.ObjectId, message string, comment Comment, tagType string)

TriggerNotificationForUserFromEvent sends a notification and a push notification to the given user. Push notifications are not sent in a local environment.

func TriggerNotificationForUserFromPost

func TriggerNotificationForUserFromPost(sender bson.ObjectId, receiver bson.ObjectId, content bson.ObjectId, message string, comment Comment, tagType string)

TriggerNotificationForUserFromPost sends a notification and a push notification to the given user. Push notifications are not sent in a local environment.

func UncommentEventController

func UncommentEventController(w http.ResponseWriter, r *http.Request)

UncommentEventController will answer a JSON of the event

func UncommentPostController

func UncommentPostController(w http.ResponseWriter, r *http.Request)

UncommentPostController will answer a JSON of the post Should be protected

func UpdateAssociationController

func UpdateAssociationController(w http.ResponseWriter, r *http.Request)

UpdateAssociationController will answer the JSON of the modified association (from the JSON Body) Should be protected

func UpdateEventController

func UpdateEventController(w http.ResponseWriter, r *http.Request)

UpdateEventController will answer the JSON of the modified Event from the JSON body Should be protected

func UpdateNotificationUserController

func UpdateNotificationUserController(w http.ResponseWriter, r *http.Request)

func UpdatePostController

func UpdatePostController(w http.ResponseWriter, r *http.Request)

UpdatePostController will answer the JSON of the modified post (from the JSON Body) Should be protected

func UpdateUserController

func UpdateUserController(w http.ResponseWriter, r *http.Request)

UpdateUserController will answer the JSON of the modified user (from the JSON Body) Should be protected

func UploadImage

func UploadImage(r *http.Request) (string, error)

UploadImage will give a random name and upload the image

func UploadImageController

func UploadImageController(w http.ResponseWriter, r *http.Request)

UploadImageController will upload a new image in the cdn

func UploadImageWithName

func UploadImageWithName(r *http.Request, name string) (string, error)

UploadImageWithName will manage the upload image from a POST request

func UploadNewImageController

func UploadNewImageController(w http.ResponseWriter, r *http.Request)

UploadNewImageController will upload a new image in the cdn

func VerifyEmail

func VerifyEmail(email string) bool

VerifyEmail return true if email is not already used

Types

type Association

type Association struct {
	ID              bson.ObjectId   `bson:"_id,omitempty"`
	Name            string          `json:"name"`
	Email           string          `json:"email"`
	Description     string          `json:"description"`
	Events          []bson.ObjectId `json:"events"`
	Posts           []bson.ObjectId `json:"posts"`
	Palette         [][]int         `json:"palette"`
	SelectedColor   int             `json:"selectedcolor"`
	Profile         string          `json:"profile"`
	ProfileUploaded string          `json:"profileuploaded"`
	Cover           string          `json:"cover"`
	BgColor         string          `json:"bgcolor"`
	FgColor         string          `json:"fgcolor"`
}

Association defines the model of a Association

func AddAssociation

func AddAssociation(association Association) Association

AddAssociation will add the given Association to the database

func AddEventToAssociation

func AddEventToAssociation(id bson.ObjectId, event bson.ObjectId) Association

AddEventToAssociation will add the given event ID to the given association

func AddPostToAssociation

func AddPostToAssociation(id bson.ObjectId, post bson.ObjectId) Association

func DeleteAssociation

func DeleteAssociation(id bson.ObjectId) Association

DeleteAssociation will delete the given association from the database

func GetAssociation

func GetAssociation(id bson.ObjectId) Association

GetAssociation will return an Association object from the given ID

func GetAssociationFromEmail

func GetAssociationFromEmail(email string) Association

GetAssociationFromEmail will return an Association object from the given email

func RemoveEventFromAssociation

func RemoveEventFromAssociation(id bson.ObjectId, event bson.ObjectId) Association

RemoveEventFromAssociation will remove the given event ID from the given association

func RemovePostFromAssociation

func RemovePostFromAssociation(id bson.ObjectId, post bson.ObjectId) Association

func UpdateAssociation

func UpdateAssociation(id bson.ObjectId, association Association) Association

UpdateAssociation will update the given Association link to the given ID, with the field of the given Association, in the database

type AssociationLogin

type AssociationLogin struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

AssociationLogin is the data provided by an association to authenticate.

type AssociationUser

type AssociationUser struct {
	ID          bson.ObjectId `bson:"_id,omitempty"`
	Username    string        `json:"username"`
	Association bson.ObjectId `json:"association" bson:"association"`
	Password    string        `json:"-"`
	Master      bool          `json:"master"`
	Owner       bson.ObjectId `json:"owner" bson:"owner,omitempty"`
}

AssociationUser defines how to model an AssociationUser

func GetAssociationUser

func GetAssociationUser(id bson.ObjectId) AssociationUser

GetAssociationUser return the AssociationUser object with the given ID.

type Associations

type Associations []Association

Associations is an array of Association

func GetAllAssociations

func GetAllAssociations() Associations

GetAllAssociations will return an array of all the existing Association, hidding "Menu" association and sort by name asc

func SearchAssociation

func SearchAssociation(name string) Associations

SearchAssociation return an array of all Association found with the given search string.

type Comment

type Comment struct {
	ID      bson.ObjectId `bson:"_id,omitempty"`
	User    bson.ObjectId `json:"user"`
	Content string        `json:"content"`
	Date    time.Time     `json:"date"`
	Tags    Tags          `json:"tags"`
}

Comment defines how to model a Comment of a Post

func GetComment

func GetComment(postID bson.ObjectId, id bson.ObjectId) (Comment, error)

func GetCommentForEvent

func GetCommentForEvent(eventID bson.ObjectId, id bson.ObjectId) (Comment, error)

type Comments

type Comments []Comment

Comments is an array of Comment

type Config

type Config struct {
	Domain           string `json:"domain"`
	Environment      string `json:"env"`
	GoogleEmail      string `json:"google_email"`
	GooglePassword   string `json:"google_password"`
	FirebaseKey      string `json:"firebase_key"`
	DatabaseName     string `json:"mongo_database_name"`
	DatabaseSource   string `json:"mongo_database_source"`
	DatabaseUsername string `json:"mongo_database_username"`
	DatabasePassword string `json:"mongo_database_password"`
	PrivateKeyPath   string `json:"private_key_path"`
	PublicKeyPath    string `json:"public_key_path"`
	Port             string `json:"port"`
}

Config defines how to model a Config

func InitConfig

func InitConfig() *Config

InitConfig loads the configuration from the filesystem.

func (Config) GetCDN

func (config Config) GetCDN() string

GetCDN returns the CDN address depending the configuration.

type Event

type Event struct {
	ID             bson.ObjectId   `bson:"_id,omitempty"`
	Name           string          `json:"name"`
	Association    bson.ObjectId   `json:"association" bson:"association"`
	Description    string          `json:"description"`
	Participants   []bson.ObjectId `json:"participants" bson:"participants,omitempty"`
	Maybe          []bson.ObjectId `json:"maybe" bson:"maybe,omitempty"`
	NotGoing       []bson.ObjectId `json:"notgoing" bson:"notgoing,omitempty"`
	Comments       Comments        `json:"comments"`
	Status         string          `json:"status"`
	Palette        [][]int         `json:"palette"`
	SelectedColor  int             `json:"selectedcolor"`
	DateStart      time.Time       `json:"dateStart"`
	DateEnd        time.Time       `json:"dateEnd"`
	Image          string          `json:"image"`
	Promotions     []string        `json:"promotions"`
	Plateforms     []string        `json:"plateforms"`
	BgColor        string          `json:"bgColor"`
	FgColor        string          `json:"fgColor"`
	NoNotification bool            `json:"nonotification"`
}

Event defines what an Event is

func AddEvent

func AddEvent(event Event) Event

AddEvent will add the Event event to the database

func CommentEvent

func CommentEvent(id bson.ObjectId, comment Comment) Event

func DeleteEvent

func DeleteEvent(event Event) Event

DeleteEvent will delete the given Event

func GetEvent

func GetEvent(id bson.ObjectId) Event

GetEvent returns an Event object from the given ID

func UncommentEvent

func UncommentEvent(id bson.ObjectId, commentID bson.ObjectId) Event

func UpdateEvent

func UpdateEvent(id bson.ObjectId, event Event) Event

UpdateEvent will update the Event event in the database

type Events

type Events []Event

Events is an array of Event

func GetEvents

func GetEvents() Events

GetEvents returns an array of Events

func GetEventsForAssociation

func GetEventsForAssociation(id bson.ObjectId) Events

GetEventsForAssociation returns an array of all Events from the given association ID

func GetFutureEvents

func GetFutureEvents() Events

GetFutureEvents returns an array of Event that will happen after "NOW"

func SearchEvent

func SearchEvent(name string) Events

type Middleware

type Middleware func(http.HandlerFunc, string) http.HandlerFunc

Middleware is the type wrapping http handlers.

type Notification

type Notification struct {
	ID       bson.ObjectId `bson:"_id,omitempty"`
	Sender   bson.ObjectId `json:"sender"`
	Receiver bson.ObjectId `json:"receiver"`
	Content  bson.ObjectId `json:"content"`
	Comment  Comment       `json:"comment,omitempty" bson:",omitempty"`
	Message  string        `json:"message"`
	Seen     bool          `json:"seen"`
	Date     time.Time     `json:"date"`
	Type     string        `json:"type"`
}

Notification defines how to model a Notification

func AddNotification

func AddNotification(notification Notification) Notification

type NotificationUser

type NotificationUser struct {
	ID     bson.ObjectId `bson:"_id,omitempty"`
	UserId bson.ObjectId `json:"userid"`
	Token  string        `json:"token" bson:",omitempty"`
	Os     string        `json:"os"`
}

NotificationUser defines how to model a NotificationUser

func GetNotificationUserForUser

func GetNotificationUserForUser(userID bson.ObjectId) NotificationUser

type Notifications

type Notifications []Notification

func GetNotificationsForUser

func GetNotificationsForUser(userID bson.ObjectId) Notifications

func GetUnreadNotificationsForUser

func GetUnreadNotificationsForUser(userID bson.ObjectId) Notifications

func ReadNotificationForUser

func ReadNotificationForUser(userID bson.ObjectId, notifID bson.ObjectId) Notifications

type Post

type Post struct {
	ID             bson.ObjectId   `bson:"_id,omitempty"`
	Title          string          `json:"title"`
	Association    bson.ObjectId   `json:"association"`
	Description    string          `json:"description"`
	Date           time.Time       `json:"date"`
	Likes          []bson.ObjectId `json:"likes"`
	Comments       Comments        `json:"comments"`
	Promotions     []string        `json:"promotions"`
	Plateforms     []string        `json:"plateforms"`
	Image          string          `json:"image"`
	ImageSize      bson.M          `json:"imageSize"`
	NoNotification bool            `json:"nonotification"`
}

Post defines how to model a Post

func AddPost

func AddPost(post Post) Post

AddPost will add the given Post to the database

func CommentPost

func CommentPost(id bson.ObjectId, comment Comment) Post

CommentPost will add the given comment object to the list of comments of the post linked to the given id

func DeletePost

func DeletePost(post Post) Post

DeletePost will delete the given Post from the database

func GetPost

func GetPost(id bson.ObjectId) Post

GetPost will return a Post object from the given ID

func UncommentPost

func UncommentPost(id bson.ObjectId, commentID bson.ObjectId) Post

UncommentPost will remove the given comment object from the list of comments of the post linked to the given id

func UpdatePost

func UpdatePost(id bson.ObjectId, post Post) Post

UpdatePost will update the post linked to the given ID, with the field of the given post, in the database

type Posts

type Posts []Post

Posts is an array of Post

func GetLatestPosts

func GetLatestPosts(number int) Posts

GetLatestPosts will return an array of the last N Posts

func GetPosts

func GetPosts() Posts

GetPosts will return an array of Posts

func GetPostsForAssociation

func GetPostsForAssociation(id bson.ObjectId) Posts

GetPostsForAssociation returns an array of Posts from the given association ID

func SearchPost

func SearchPost(name string) Posts

type Route

type Route struct {
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route type is used to define a route of the API

type Routes

type Routes []Route

Routes type is an array of Route

type Search struct {
	Terms string `json:"terms"`
}

type Tag

type Tag struct {
	ID   bson.ObjectId `bson:"_id,omitempty"`
	User string        `json:"user"`
	Name string        `json:"name"`
}

type Tags

type Tags []Tag

type TokenClaims

type TokenClaims struct {
	ID   bson.ObjectId `json:"id"`
	Role string        `json:"role"`
	jwt.StandardClaims
}

TokenClaims is the JWT encoding format.

type TokenJTI

type TokenJTI struct {
	ID  bson.ObjectId `bson:"_id,omitempty"`
	JTI string        `json:"jti"`
}

TokenJTI models JTI keeping track of tokens.

type User

type User struct {
	ID          bson.ObjectId   `bson:"_id,omitempty"`
	Name        string          `json:"name"`
	Username    string          `json:"username"`
	Description string          `json:"description"`
	Email       string          `json:"email"`
	EmailPublic bool            `json:"emailpublic"`
	Promotion   string          `json:"promotion"`
	Gender      string          `json:"gender"`
	Events      []bson.ObjectId `json:"events"`
	PostsLiked  []bson.ObjectId `json:"postsliked"`
}

User defines how to model a User

func AddEventToUser

func AddEventToUser(id bson.ObjectId, eventID bson.ObjectId) User

AddEventToUser will add the eventID to the list of the user's event linked to the given id

func AddUser

func AddUser(user *User) User

AddUser will add the given user from JSON body to the database

func DeleteUser

func DeleteUser(user User) User

DeleteUser will delete the given user from the database

func DislikePost

func DislikePost(id bson.ObjectId, postID bson.ObjectId) User

DislikePost will remove the postID from the list of liked post of the user linked to the given id

func GetUser

func GetUser(id bson.ObjectId) User

GetUser return the User object with the given ID.

func LikePost

func LikePost(id bson.ObjectId, postID bson.ObjectId) User

LikePost will add the postID to the list of liked post of the user linked to the given id

func NewUser

func NewUser(username string) *User

NewUser creates a new User

func RemoveEventFromUser

func RemoveEventFromUser(id bson.ObjectId, eventID bson.ObjectId) User

RemoveEventFromUser will remove the eventID from the list of the user's event linked to the given ID.

func UpdateUser

func UpdateUser(id bson.ObjectId, user User) User

UpdateUser will update the user link to the given ID, with the field of the given user, in the database

type Users

type Users []User

Users is an array of User

func GetAllUser

func GetAllUser() Users

GetAllUser will return an User object from the given ID

func SearchUser

func SearchUser(name string) Users

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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