admin

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: 13 Imported by: 0

README

Admin

Create Admins

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

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

  • PS : Only admin with Professor : True can make this request

    	[
    		{
    			"classid"	:	ObjectId,
    			"firstname"	:	String,
    			"lastname"	: 	String,
    			"matricula"	: 	String
    		},...
    	]
    
  • http StatusCreated (201) will be sent if the admin has been created correctly

Create Admins by CSV file

  • HTTP Request : POST http://api.com/admin/file

  • Send data in the request body in the following format

  • PS : Only admin with Professor : True can make this request

    ANO/SEMESTE/TURMA 2019/2/A
    160140000 Thiago Veras Machado
    160140000 Giovanni Guidini
    160140000 Vitor Dullens
    	{  
    		"file"	: file.csv,
    	},...
    
  • http StatusCreated (201) will be sent if the admin has been created correctly

Get all Admins

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

  • Return a list of object in json format as follow

    	[
    		{
                "id"        :   ObjectId,
                "classid"   :   ObjectId,
                "firstname" :   String,
                "lastname"  :   String,
                "matricula" :   String,
                "photourl"  :   String,
                "email"     :   String,
                "projects"  :   Integer,
                "professor" :   Bool
    		},...
    	]
    

Get all Admins from a specif class

  • HTTP Request : GET http://api.com/admin/{classid}

  • Return a list of object in json format as follow

    	[
    		{
                "id"        :   ObjectId,
                "classid"   :   ObjectId,
                "firstname" :   String,
                "lastname"  :   String,
                "matricula" :   String,
                "photourl"  :   String,
                "email"     :   String,
                "projects"  :   Integer,
                "professor" :   Bool
    		},...
    	]
    

Update Admins

  • HTTP Request : PUT http://api.com/admin
  • Send data in the request body in the following format.

PS: (id and password required)

``` 
[
    {  
        "id"            :   ObjectId,
        "classid"       :   ObjectId,
        "email"         :   String,
        "password"      :   String,
        "newpassword"   :   String,
        "photourl"      :   String
    },...
]
```
  • http StatusCreated (201) will be sent if the admin has been updated correctly

Update Students from Admin request

  • HTTP Request : PUT http://api.com/admin/student

  • Send data in the request body in the following format (stundentid, adminid and adminpassword is required)

        {  
            "adminid"           :   ObjectId,                
            "studentid"         :   ObjectId,
            "classid"           :   ObjectId,
            "adminpassword"     :   String,
            "firstname"         :   String,
            "lastname"          :   String,
            "matricula"         :   String,
            "handles"           :	{
                "codeforces"        :	String,
                "uri"               :	String
            },
            "photourl"          :   String,
            "email"             :   String,
            "grades"            :   StudentGrades {
                "exams"             :   []float64
                "lists"             :   []float64
            }
        }
    
  • http StatusCreated (201) will be sent if the student has been updated correctly by an admin

Delete Admin

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

  • Send data in the request body in the following format

  • PS : Only admin with Professor : True can make this request

        {  
            "id"	:	ObjectId
        }
    
  • http StatusOK (200) will be sent if the Admin have been deleted correctly

Delete Admins

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

  • Send data in the request body in the following format

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

Log in Admin

  • HTTP Request : POST http://api.com/admin/login

    	{
            "matricula"     :   String,
            "password"      :   String,
    	}
    
  • Return a json format as follow with http StatusOK (200) if login was succeeded

    {
        "admin"         :   Admin,
        "class"         :   SchoolClass,
        "news"          :   []News 
    }
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAdmin

func CreateAdmin(db *mongo.Client, api *goforces.Client, admins []AdminCreate, databaseName, collectionName string) ([]user.UserCredentials, error)

CreateAdmin receive a list of students Checks if that list is not null (can't insert null list) Insert each student individually in database @param db pointer to database @param students list of students @param databaseName name of database @param collectionName name of collection @return error function error TODO : Insert all students at the same time (if possible)

func CreateAdminFile

func CreateAdminFile(db *mongo.Client, request, databaseName, collectionName string) ([]user.UserCredentials, error)

CreateAdminFile receive a csv file in that current format : https://github.com/apc-unb/tree/master/components/student calls getAdminFromFile() that return list of AdminCreate and insert into db @param db pointer to database @param request all data to be parsed @param databaseName name of database @param collectionName name of collection @return error function error

func DeleteAdmin

func DeleteAdmin(db *mongo.Client, admin Admin, databaseName, collectionName string) error

func UpdateAdmin

func UpdateAdmin(db *mongo.Client, api *goforces.Client, admin AdminUpdate, databaseName, collectionName string) error

UpdateAdmins receive admin (updated) Checks if admin old password matches with db to update that admin password or email @param db pointer to database (updated) @param api codeforces api @param admin list of admins @param databaseName name of database @param collectionName name of collection @return error function error TODO : Update all students at the same time (if possible)

func UpdateAdminStudent

func UpdateAdminStudent(db *mongo.Client, api *goforces.Client, admin AdminUpdateStudent, databaseName, studentCollectionName, adminLoginCollectionName string) error

UpdateAdminStudent receive update stundets data, receive a student (updated) @param db pointer to database (updated) @param api codeforces api @param admin student to be updated @param databaseName name of database @param collectionName name of collection @return error function error

Types

type Admin

type Admin struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	ClassID   primitive.ObjectID `bson:"classid,omitempty"`
	FirstName string             `json:"firstname"`
	LastName  string             `json:"lastname"`
	Matricula string             `json:"matricula"`
	PhotoURL  string             `json:"photourl"`
	Email     string             `json:"email"`
	Projects  int32              `json:"projects"`
	Professor bool               `json:"professor"`
}

Admin contains all admin data

func GetAdminsClass

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

type AdminCreate

type AdminCreate struct {
	ClassID   primitive.ObjectID `bson:"classid,omitempty"`
	FirstName string             `json:"firstname"`
	LastName  string             `json:"lastname"`
	Matricula string             `json:"matricula"`
	PhotoURL  string             `json:"photourl"`
	Email     string             `json:"email"`
	Projects  int32              `json:"projects"`
	Professor bool               `json:"professor"`
}

AdminCreate contais all admin data except from ID

type AdminInfo

type AdminInfo struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	ClassID   primitive.ObjectID `bson:"classid,omitempty"`
	FirstName string             `json:"firstname"`
	LastName  string             `json:"lastname"`
	Matricula string             `json:"matricula"`
	PhotoURL  string             `json:"photourl"`
	Email     string             `json:"email"`
	Projects  int32              `json:"projects"`
	Professor bool               `json:"professor"`
}

AdminInfo contais all admin data except from Password

func AuthAdmin

func AuthAdmin(db *mongo.Client, admin user.UserCredentials, databaseName, collectionName string) (AdminInfo, error)

AuthAdmin recieve an admin (to be authenticated) Checks if that login and password exist in database @param db pointer to database @param admin admin matricula and password @param databaseName name of database @param collectionName name of collection @return AdminInfo json if exist plus all admin data @return error function error

func GetAdmins

func GetAdmins(db *mongo.Client, databaseName, collectionName string) ([]AdminInfo, error)

GetAdmins return list of all students from Database Get all students at the same time and store inside cursor Decode each student inside student class and append into students array @param db pointer to database @param databaseName name of database @param collectionName name of collection @return []Student list of all students @return error function error

type AdminUpdate

type AdminUpdate struct {
	ID          primitive.ObjectID `bson:"_id,omitempty"`
	ClassID     primitive.ObjectID `bson:"classid,omitempty"`
	FirstName   string             `json:"firstname"`
	LastName    string             `json:"lastname"`
	Matricula   string             `json:"matricula"`
	PhotoURL    string             `json:"photourl"`
	Email       string             `json:"email"`
	Projects    int32              `json:"projects"`
	Password    string             `json:"password"`
	NewPassword string             `json:"newpassword"`
}

AdminUpdate contais all data that admin can update

type AdminUpdateStudent

type AdminUpdateStudent struct {
	AdminID       primitive.ObjectID     `bson:"adminid,omitempty"`
	StudentID     primitive.ObjectID     `bson:"studentid,omitempty"`
	ClassID       primitive.ObjectID     `bson:"classid,omitempty"`
	AdminPassword string                 `json:"adminpassword"`
	FirstName     string                 `json:"firstname"`
	LastName      string                 `json:"lastname"`
	Matricula     string                 `json:"matricula"`
	Handles       student.StudentHandles `json:"handles"`
	PhotoURL      string                 `json:"photourl"`
	Email         string                 `json:"email"`
	Grades        student.StudentGrades  `json:"grades"`
}

AdminUpdateStudent all data of a student to be updated

Jump to

Keyboard shortcuts

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