rest

package
v0.0.0-...-58fcb86 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DebugFilePath = "/vol/files/.debug"

DebugFilePath to where a .debug file lies

View Source
const Port = 8080

Port is the port this api will listen to

Variables

This section is empty.

Functions

func AuthWall

func AuthWall() gin.HandlerFunc

AuthWall drops every token which doesnt provide a valid token

func CreateApplication

func CreateApplication(con *gin.Context)

CreateApplication represents the create applications endpoint @Summary Creates a new application @Description Creates the provided application in the system @ID create-application @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param application body db.Application true "The Application Data" @Success 200 {object} Information @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /createApplication [post]

func DeleteApplication

func DeleteApplication(con *gin.Context)

DeleteApplication represents the delete applications endpoint @Summary Deletes an existing application @Description Deletes an application identified by a uuid @ID delete-application @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to delete" @Success 200 {object} Information @Failure 401 {object} Error @Failure 404 {object Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /deleteApplication [delete]

func DeleteToken

func DeleteToken(uuid string)

DeleteToken deletes a token

func ExtractToken

func ExtractToken(r *http.Request) string

ExtractToken parses the token string out of a request

func GetAbsenceFormForClasses

func GetAbsenceFormForClasses(con *gin.Context)

GetAbsenceFormForClasses represents get absence form for classes endpoint @Summary Generates an absence form for classes @Description Generates an absence form for classes and returns it @ID get-absence-form-for-classes @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the pdf from" @Param classes query []string false "Filter for classes" @Success 200 {object} PDF @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getAbsenceFormForClasses [get]

func GetAbsenceFormForTeacher

func GetAbsenceFormForTeacher(con *gin.Context)

GetAbsenceFormForTeacher represents get absence form for teacher endpoint @Summary Generates an absence form for a teacher @Description Generates an absence form for a teacher and returns it @ID get-absence-form-for-teacher @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the pdf from" @Param teacher query string false "short name of the teacher, if not provided logged in teacher will be used" @Success 200 {object} PDF @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getAbsenceFormForTeacher [get]

func GetActiveApplications

func GetActiveApplications(con *gin.Context)

GetActiveApplications represents the get active applications endpoint @Summary Returns all active applications @Description Returns all active applications as a list of applications @ID get-all-active-applications @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param username query string false "Filter to only show applications of this teacher" @Success 200 {array} db.Application @Failure 401 {object} Error @Failure 500 {object} Error @Router /getActiveApplications [get]

func GetAdminApplications

func GetAdminApplications(con *gin.Context)

GetAdminApplications represents the get admin applications endpoint @Summary Returns all admin applications @Description Returns all applications currently needing a review by an admin @ID get-admin-applications @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Success 200 {array} db.Application @Failure 401 {object} Error @Failure 500 {object} Error @Router /getAdminApplication [get]

func GetAllApplications

func GetAllApplications(con *gin.Context)

GetAllApplications represents the get all applications endpoint @Summary Returns all applications @Description Returns all applications as a list of applications @ID get-all-applications @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param username query string false "Filter to only show applications of this teacher" @Success 200 {array} db.Application @Failure 401 {object} Error @Failure 500 {object} Error @Router /getAllApplications [get]

func GetApplication

func GetApplication(con *gin.Context)

GetApplication represents the get application endpoint @Summary Returns an Application @Description Returns the Application matching the given UUID @ID get-application @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "The UUID of the specifying Application" @Success 200 {object} db.Application @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getApplication [get]

func GetBusinessTripApplicationExcel

func GetBusinessTripApplicationExcel(con *gin.Context)

GetBusinessTripApplicationExcel represents get business application excel endpoint @Summary Generates a business trip application excel for a teacher @Description Generates a business trip application excel for a teacher and returns it @ID get-business-trip-application-excel @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the excel from" @Param short query string true "Short name of the teacher this should be generated for" @Param bta_id query int true "ID of the Business Trip Application data" @Success 200 {object} Excel @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getBusinessTripApplicationExcel [get]

func GetBusinessTripApplicationForm

func GetBusinessTripApplicationForm(con *gin.Context)

GetBusinessTripApplicationForm represents get business application form endpoint @Summary Generates a business trip application form for a teacher @Description Generates a business trip application form for a teacher and returns it @ID get-business-trip-application-form @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the form from" @Param short query string true "Short name of the teacher this should be generated for" @Param bta_id query int true "ID of the Business Trip Application data" @Success 200 {object} PDF @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getBusinessTripApplicationForm [get]

func GetCompensationForEducationalSupportForm

func GetCompensationForEducationalSupportForm(con *gin.Context)

GetCompensationForEducationalSupportForm represents get compensation for educational support form endpoint @Summary Generates a compensation for educational support form for all teachers @Description Generates a compensation for educational support form for all teachers and returns it @ID get-compensation-for-educational-support-form @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the pdf from" @Success 200 {object} PDF @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getCompensationForEducationalSupportForm [get]

func GetNews

func GetNews(con *gin.Context)

GetNews represents the get news endpoint @Summary Returns the news @Description Returns the 10 last changed applications @ID get-news @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Success 200 {array} News @Failure 401 {object} Error @Failure 500 {object} Error @Router /getNews [get]

func GetTeacher

func GetTeacher(con *gin.Context)

GetTeacher represents the get teacher endpoint @Summary Returns a teacher with the specified UUID @Description Searches for the Teacher with the specified uuid and returns the data @ID get-teacher @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "UUID of Teacher" @Success 200 {object} db.Teacher @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getTeacher [get]

func GetTeacherByShort

func GetTeacherByShort(con *gin.Context)

GetTeacherByShort represents the get teacher by short name endpoint @Summary Returns a teacher with the specified short name @Description Searches for the Teacher with the specified name and returns the data @ID get-teacher-by-short @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param name query string true "Short Name of Teacher" @Success 200 {object} db.Teacher @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getTeacherByShort [get]

func GetTeacherByUntis

func GetTeacherByUntis(con *gin.Context)

GetTeacherByUntis represents the get teacher by untis endpoint @Summary Returns a teacher with the specified untis abbrevation @Description Searches for the Teacher with the specified untis abbrevation and returns the data @ID get-teacher-by-untis @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param untis query string true "Untis abbrevation of Teacher" @Success 200 {object} db.Teacher @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getTeacherByUntis [get]

func GetTravelInvoiceExcel

func GetTravelInvoiceExcel(con *gin.Context)

GetTravelInvoiceExcel represents get travel invoice excel endpoint @Summary Generates a travel invoice excel for a teacher @Description Generates a travel invoice excel for a teacher and returns it @ID get-travel-invoice-excel @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the excel from" @Param short query string true "Short name of the teacher this should be generated for" @Param ti_id query int true "ID of the Travel Invoice data" @Success 200 {object} Excel @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getTravelInvoiceExcel [get]

func GetTravelInvoiceForm

func GetTravelInvoiceForm(con *gin.Context)

GetTravelInvoiceForm represents get travel invoice form endpoint @Summary Generates a travel invoice for a teacher @Description Generates a travel invoice form for a teacher and returns it @ID get-travel-invoice-form @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the pdf from" @Param short query string true "Short name of the teacher this should be generated for" @Param ti_id query int true "ID of the Travel Invoice data" @Param receipts query bool false "If provided the pdf will include all receipt" @Success 200 {object} PDF @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /getTravelInvoiceForm [get]

func InitTokenManager

func InitTokenManager()

InitTokenManager initializes the token manager it reads or generates both secrets, creates the map of active tokens, and starts the thread to remove expired tokens

func Login

func Login(con *gin.Context)

Login represents the login endpoint @Summary Login a user @Description Login a user using username and password @ID login @Accept json @Produce json @Param user body User true "Account Information" @Success 200 {object} TokenPair @Failure 401 {object} Error @Failure 422 {object} Error @Router /login [post]

func Logout

func Logout(con *gin.Context)

Logout represents the logout endpoint @Summary Logs out a user @Description Destroys the session of a user @ID logout @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Success 200 {object} Information @Failure 401 {object} Error @Router /logout [post]

func Refresh

func Refresh(con *gin.Context)

Refresh represents the refresh endpoint @Summary Refreshes the token pair of a session @Description Creates a new token pair when a valid refresh token is provided @ID refresh @Accept json @Produce json @Param token body RefreshToken true "Refresh Token" @Success 201 {object} TokenPair @Failure 401 {object} Error @Failure 403 {object} Error @Failure 422 {object} Error @Router /login/refresh [post]

func SaveBillingReceipt

func SaveBillingReceipt(con *gin.Context)

SaveBillingReceipt represents get save billing receipt endpoint @Summary Saves a billing receipt @Description Saves a billing receipt in the context of an application @ID save-billing-receipt @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param uuid query string true "Identifier of the application to generate the excel from" @Param short query string true "Short name of the teacher this should be generated for" @Param files body PDFs true "The files to save as an array of the base64 decoded file contents" @Success 200 {object} Information @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /saveBillingReceipt [post]

func SaveToken

func SaveToken(username string, token *Token)

SaveToken saves a token in the active token map with its corresponding username as key

func SetTeacherPermissions

func SetTeacherPermissions(con *gin.Context)

SetTeacherPermissions represents the set teacher permissions endpoint @Summary Sets the permissions of a Teacher @Description Sets the permissions of a Teacher to update their access rights @ID set-teacher-permissions @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param perm body Permissions true "Permission data of the teacher" @Param uuid query string true "UUID of the teacher whos permissions will be changed" @Success 200 {object} db.Teacher @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /setTeacherPermissions [post]

func StartService

func StartService()

StartService starts the rest service @title Refundable @version 1.1 @description This REST-API provides the backend of Refundable @contact.name Michael Beier - Entwickler @contact.url https://mbeier.at @contact.email admin@mbeier.at @securityDefinitions.apikey ApiKeyAuth @in header @name Authorization @license.name MIT License @license.url https://github.com/refundable-tgm/huginn/blob/master/LICENSE @host localhost:8080 @BasePath /api @query.collection.format multi

func TokenValid

func TokenValid(r *http.Request) (bool, error)

TokenValid checks whether a token is still valid, therefore also verifies it

func UpdateApplication

func UpdateApplication(con *gin.Context)

UpdateApplication represents the update applications endpoint @Summary Updates an existing application @Description Updates an application identified by a uuid with the data in the body in the system @ID update-application @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param application body db.Application true "The application data to update" @Param uuid query string true "Identifier of the application to update" @Success 200 {object} Information @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /updateApplication [put]

func UpdateTeacherInformation

func UpdateTeacherInformation(con *gin.Context)

UpdateTeacherInformation represents the update teacher information endpoint @Summary Updates the information of an existing teacher @Description Updates a teacher identified by a uuid with the data in the body in the system @ID update-teacher-information @Accept json @Produce json @Param Authorization header string true "Access Token" default(Bearer <Add access token here>) @Param teacher_information body rest.TeacherInformation true "The teacher information data to set" @Param uuid query string true "Identifier of the teacher to update" @Success 200 {object} Information @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Router /updateTeacherInformation [put]

func VerifyToken

func VerifyToken(r *http.Request) (*jwt.Token, error)

VerifyToken verifies that the token provided in the request originates from this API

Types

type AccessToken

type AccessToken struct {
	// AccessUUID is the uuid of the access token
	AccessUUID string
	// Username is the username of the user this token belongs to
	Username string
}

AccessToken represents the further information about an access token

func ExtractTokenMeta

func ExtractTokenMeta(r *http.Request) (*AccessToken, error)

ExtractTokenMeta extracts the meta information encoded in the token and returns both uuid and username

type EntityInformation

type EntityInformation struct {
	// Username identifies the user this token belongs to
	Username string
	// ExpiresAt marks the time the token expires at
	ExpiresAt time.Time
}

EntityInformation represents information about tokens

type Error

type Error struct {
	// the message that should be sent
	Message string `json:"error" example:"couldn't convert token"`
}

Error maps an error message

type Excel

type Excel struct {
	// Content is the content of the excel file
	Content string `json:"excel" example:"<base64>"`
}

Excel represents an excel output

type Information

type Information struct {
	// the message that should be sent
	Message string `json:"info" example:"updated teacher successfully"`
}

Information maps an information message

type News

type News struct {
	// UUID of the application
	UUID string `json:"uuid" example:"3fcf7f67-e0ed-4339-99b4-a6765aaa3dc4"`
	// Title of the application
	Title string `json:"title" example:"Sommersportwoche"`
	// State of the application
	State int `json:"state" example:"3"`
	// LastChanged is the date of last changes of the application
	LastChanged string `json:"last_changed" example:"2009-11-10 23:00:00 +0000 UTC m=+0.000000001"`
}

News is a news object for applications

type PDF

type PDF struct {
	// Content is the content of this file
	Content string `json:"pdf" example:"<base64>"`
}

PDF represents a pdf file

type PDFs

type PDFs struct {
	Files []PDF `json:"files"`
}

PDFs is a wrapper for a single pdf

type Permissions

type Permissions struct {
	// SuperUser permission
	SuperUser bool `json:"super_user" example:"true"`
	// Administration permission
	Administration bool `json:"administration" example:"true"`
	// AV permission
	AV bool `json:"av" example:"true"`
	// PEK permission
	PEK bool `json:"pek" example:"true"`
}

Permissions lists the permissions of a teacher

type RefreshToken

type RefreshToken struct {
	// Token is the refresh token
	Token string `json:"refresh_token" example:"<jwt-token>"`
}

RefreshToken maps an refresh token

type TeacherInformation

type TeacherInformation struct {
	// Degree of the Teacher
	Degree string `json:"degree" example:"DI"`
	// Title of the Teacher
	Title string `json:"title" example:"Prof"`
	// The Staffnr of the regarding teacher
	Staffnr int `json:"staffnr" example:"938503154"`
	// The Group number
	Group int `json:"group" example:"1"`
	// The StartingAddresses of the teacher
	StartingAddresses []string `json:"starting_addresses" example:"Zuhause 1,Zuhause 2"`
	// The TripGoals the teacher visited before
	TripGoals []string `json:"trip_goals" example:"Karl Hönck Heim,PH Wien,Landesgericht St. Pölten"`
	// The Departments this teacher belongs to
	Departments []string `json:"departments" example:"HIT,HBG"`
	// The Untis abbrevation of the teacher
	Untis string `json:"untis" example:"ZAKS"`
}

TeacherInformation contains changeable information of the teacher

type Token

type Token struct {
	// AccessToken is the access token itself
	AccessToken string
	// RefreshToken is the refresh token itself
	RefreshToken string
	// AccessUUID is the uuid the access token is referenced by
	AccessUUID string
	// RefreshUUID is the uuid the refresh token is referenced by
	RefreshUUID string
	// AccessExpires is the date the access tokens expires at
	AccessExpires int64
	// RefreshExpires is the date the refresh tokens expires at
	RefreshExpires int64
}

Token represents a token pair

func CreateToken

func CreateToken(username string) (*Token, error)

CreateToken creates a token pair based on a username

type TokenPair

type TokenPair struct {
	// the access token
	AccessToken string `json:"access_token" example:"<jwt-token>"`
	// the refresh token
	RefreshToken string `json:"refresh_token" example:"<jwt-token>"`
}

TokenPair consists of an access and a refresh token

type User

type User struct {
	// Username of the user
	Username string `json:"username" example:"lehrer1234"`
	// Password of the user
	Password string `json:"password" example:"password1234"`
}

User data input

Jump to

Keyboard shortcuts

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