package
0.0.0-20230509074126-181bd5fcb334
Repository: https://github.com/apc-unb/apc-api.git
Documentation: pkg.go.dev

# 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/TURMA2019/2/A
    160140000Thiago Veras Machado
    160140000Giovanni Guidini
    160140000Vitor 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 
    }
    

# Functions

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.
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).
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.
No description provided by the author
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.
No description provided by the author
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).
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.

# Structs

Admin contains all admin data.
AdminCreate contais all admin data except from ID.
AdminInfo contais all admin data except from Password.
AdminUpdate contais all data that admin can update.
AdminUpdateStudent all data of a student to be updated.