common

package
v0.0.0-...-97f70ea Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableInsertionDepartments         = `INSERT INTO departments (code, name) VALUES ($1, $2);`
	TableInsertionFacultyDesignations = `INSERT INTO faculty_designations (designation) VALUES ($1) RETURNING id;`
	TableInsertionFaculty             = `INSERT INTO faculty (name, designation, department) VALUES ($1, $2, $3);`
	TableInsertionCourses             = `INSERT INTO courses (code, name, credits, department) VALUES ($1, $2, $3, $4) RETURNING id;`
	TableInsertionRooms               = `INSERT INTO rooms (room) VALUES ($1) RETURNING id;`
	TableInsertionCourseFaculty       = `INSERT INTO course_faculty (faculty, course) VALUES ($1, $2)`
	TableInsertionCourseSlots         = `INSERT INTO course_slots (slot, course) VALUES ($1, $2)`
	TableInsertionCourseRooms         = `INSERT INTO course_rooms (room, course) VALUES ($1, $2)`
	TableInsertionSlots               = `INSERT INTO slots (slot) VALUES ($1) RETURNING id;`
	TableInsertionTimeSlots           = `INSERT INTO time_slots (time, slot) VALUES ($1, $2);`
)

Table Insertion statements

View Source
const (
	TableReadDepartment  = `SELECT id FROM departments WHERE code=$1;`
	TableReadDesignation = `SELECT id FROM faculty_designations WHERE designation=$1;`
	TableReadFaculty     = `SELECT id FROM faculty WHERE name=$1;`
	TableReadSlots       = `SELECT id FROM slots WHERE slot=$1;`
	TableReadRooms       = `SELECT id FROM rooms WHERE room=$1;`
	TableReadCourses     = `SELECT id FROM courses WHERE code=$1;`
)

Table querying statements given the id

View Source
const VERSION = "/api/v1"

Variables

View Source
var ErrCourseNotFound = errors.New("The specified course was not found in the database.")
View Source
var ErrDataEncoding = errors.New("Unable to encode the data for you")
View Source
var ErrNotImplemented = errors.New("This feature has not yet implemented!")

Functions

func DecodeFromJSON

func DecodeFromJSON(r *http.Request, data interface{}) error

DecodeFromJSON is the common function to be used by all the POST handlers for reading JSON data from the request body and performing input validation.

func NewSubRouter

func NewSubRouter(routes Routes) *mux.Router

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, r *http.Request, status int, data interface{})

RespondWithJSON is the common function to be used by all the handlers while returning JSON data to the caller.

func SendToService

func SendToService(service, method, endpoint string, query url.Values, body interface{}) (*http.Response, error)

Types

type Config

type Config struct {
	Database string `required:"true" desc:"Connection String, for more info see: https://godoc.org/github.com/lib/pq"`
	Port     string `envconfig:"PORT" default:"8080" desc:"Application listen port"`
}

Config represents configuration environment to running application

type Course

type Course struct {
	Name    string `json:"name"`
	Code    string `json:"code"`
	Credits int    `json:"credits"`
}

Course denotes the information related to each course.

func (*Course) GetInfo

func (c *Course) GetInfo(db *sql.DB) error

GetInfo method populates the receiver with id and name for the given code.

type Courses

type Courses []Course

Courses represents the reponse by the CoursesHandler.

type Department

type Department struct {
	ID   string `json:"-"` // DO NOT EXPORT IDs, ever, for now.
	Name string `json:"name"`
	Code string `json:"code"`
}

Department represents the metadata related to a department.

func (*Department) GetInfo

func (d *Department) GetInfo(db *sql.DB) error

GetInfo method populates the receiver with id and name for the given code.

type Departments

type Departments []Department

Departments represents the response returned by the DepartmentsHandler.

type Faculty

type Faculty []FacultyMember

Faculty represents the response returned by the FacultyHandler.

type FacultyDesignation

type FacultyDesignation string

FacultyDesignation represents the designation of a Faculty member.

type FacultyMember

type FacultyMember struct {
	Name        string             `json:"name"`
	Department  Department         `json:"department"`
	Designation FacultyDesignation `json:"designation"`
}

FacultyMember represents the information related to a faculty member at IIT KGP.

type HerculesDB

type HerculesDB interface {
	ConnectDB(databaseURL string) error

	CloseDB() error
}

HerculesDB represents the interface that needs to be satisfied by the database layer in order to work with the application API.

type Room

type Room string

type Rooms

type Rooms []Room

type Route

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

type Routes

type Routes []Route

type Server

type Server interface {
	http.Handler

	HerculesDB

	GetName() string

	GetURL() string
}

Server represents the fundamental components of the API. Every service needs to implement this interface.

type Service

type Service struct {
	Name   string
	URL    string
	Router *mux.Router
}

Service is the implementation of the Server interface.

type Slot

type Slot string

Slot represents a course slot used for allocating a subject.

type Slots

type Slots []Slot

type Time

type Time struct {

	// TODO: Use time.Weekday
	Day string `json:"day"`
	// TODO: Use time.Time
	Time string `json:"time"`
}

Time represents a possible time for scheduling class.

type TimeSlot

type TimeSlot struct {
	Time `json:"time"`
	Slot `json:"slot"`
}

type Timetable

type Timetable struct {
	Monday    TimetableSlots `json:"Monday"`
	Tuesday   TimetableSlots `json:"Tuesday"`
	Wednesday TimetableSlots `json:"Wednesday"`
	Thursday  TimetableSlots `json:"Thursday"`
	Friday    TimetableSlots `json:"Friday"`
}

type TimetableSlot

type TimetableSlot struct {
	Course   `json:"course"`
	TimeSlot `json:"slot"`
	Rooms    `json:"rooms"`
}

type TimetableSlots

type TimetableSlots []TimetableSlot

Jump to

Keyboard shortcuts

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