news

package
v0.0.0-...-181bd5f Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 6 Imported by: 0

README

Exam

Get all News

  • HTTP Request : GET http://api.com/news

  • Return a list of object in json format as follow

    [
        {
            "id"            :   ObjectId,
            "classid"       :   ObjectId,
            "authorID"      :   ObjectId,
            "authorName"    :   String,
            "admin"         :   Bool,
            "title"         :   String,
            "description"   :   String,
            "tags"          :   []String,
            "createdAT"     :   Time,
            "updatedAT"     :   Time
        }...,
    ]
    

Get all News from a class

  • HTTP Request : GET http://api.com/news/{classID}

  • Return a list of object in json format as follow

        [
    		{
                "id"            :   ObjectId,
                "classid"       :   ObjectId,
                "authorID"      :   ObjectId,
                "authorName"    :   String,
                "admin"         :   Bool,
                "title"         :   String,
                "description"   :   String,
                "tags"          :   []String,
                "createdAT"     :   Time,
                "updatedAT"     :   Time
            }...,
    	]
    

Create News

  • HTTP Request : POST http://api.com/news

  • Send News's data in the request body in the following format

        [
    		{
                "classid"       :   ObjectId,
                "authorID"      :   ObjectId,
                "authorName"    :   String,
                "admin"         :   Bool,
                "title"         :   String,
                "description"   :   String,
                "tags"          :   []String,
    		}...
    	]
    
  • http StatusCreated (201) will be sent if the student has been created correctly

Update News

  • HTTP Request : PUT http://api.com/news

  • Send data in the request body in the following format

        [
    		{
    			"id"           :	ObjectId,
    			"classid"       :	ObjectId,
    			"title"         :	String,
    			"description"   :	String
                "tags"          :   []String
    		}...
    	]
    
  • http StatusCreated (201) will be sent if the student has been updated correctly

Delete News

  • HTTP Request : DELETE http://api.com/news

  • Send data in the request body in the following format

    	[
    		{  
    			"id" : ObjectId
    		},...
    	]
    
  • http StatusOK (200) will be sent if the students have been deleted correctly

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNews

func CreateNews(db *mongo.Client, singleNews NewsCreate, databaseName, collectionName string) error

func DeleteNews

func DeleteNews(db *mongo.Client, news []News, databaseName, collectionName string) error

func UpdateNews

func UpdateNews(db *mongo.Client, singleNews News, databaseName, collectionName string) error

Types

type News

type News struct {
	ID          primitive.ObjectID `bson:"_id,omitempty"`
	ClassID     primitive.ObjectID `bson:"classid,omitempty"`
	AuthorID    primitive.ObjectID `bson:"authorID,omitempty"`
	AuthorName  string             `json:"authorName,omitempty"`
	Admin       bool               `bson:"admin,omitempty"`
	Title       string             `json:"title"`
	Description string             `json:"description"`
	Tags        []string           `json:"tags"`
	CreatedAT   time.Time          `json:"createdat"`
	UpdatedAT   time.Time          `json:"updatedat"`
}

func GetNews

func GetNews(db *mongo.Client, databaseName, collectionName string) ([]News, error)

func GetNewsClass

func GetNewsClass(db *mongo.Client, classID primitive.ObjectID, databaseName, collectionName string) ([]News, error)

type NewsCreate

type NewsCreate struct {
	ClassID     primitive.ObjectID `bson:"classid,omitempty"`
	AuthorID    primitive.ObjectID `bson:"authorID,omitempty"`
	AuthorName  string             `json:"authorName,omitempty"`
	Admin       bool               `bson:"admin,omitempty"`
	Title       string             `json:"title"`
	Description string             `json:"description"`
	Tags        []string           `json:"tags"`
	CreatedAT   time.Time          `json:"createdat"`
	UpdatedAT   time.Time          `json:"updatedat"`
}

Jump to

Keyboard shortcuts

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