workday

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

[[https://www.gnu.org/licenses/gpl-3.0][https://img.shields.io/badge/License-GPLv3-blue.svg]] [[https://travis-ci.com/iris-garcia/workday][https://travis-ci.com/iris-garcia/workday.svg?branch=master]] [[https://github.com/iris-garcia/workday/actions][https://github.com/iris-garcia/workday/workflows/Unit%20tests/badge.svg]]

* Workday
** What's the idea?
Since last May 12, 2019 every Spanish company is required to provide
their employees a process to record their working hours.

This process can be as simple as signing in a paper the checks in and
checks out for every single workday; but any other process can be used
and this is the reason for which I decided to develop this project.

Initially the idea is to provide a RESTful API which could be used in
any company to register those checks in and checks out, and allow the
"administrators" to retrieve the data at any time they are requested
to.

** How is it going to be developed?
- RESTful API design.
- Test-driven development.
- Isolated development environment (probably using Docker containers).
- Continuous Integration.
- Gitflow workflow.
- Storing persistent data in a relational database.
- Logging services.
- Authentication

** Which tools will be used?
*** [[https://golang.org/][Go]]
The open source programming language Go will be used, mainly because I
want to try a new language and this one is becoming quite popular
nowadays.

*** [[https://iris-go.com/][Iris]]
Iris is an easy to use web framework which claims to be one of the
[[https://github.com/kataras/iris/wiki/Benchmarks][fastest]] web frameworks ever crafted.

This web framework will be used to build the HTTP server among all
the API endpoints and some kind of authentication.

*** [[https://mariadb.com/][MariaDB]]
The relational database engine MariaDB has been choosen to persist the
data, it is OpenSource and fulfills the requirements.

*** [[https://www.elastic.co/products/beats/filebeat][Filebeat]] / [[https://www.elastic.co/products/logstash][Logstash]]
I am not sure yet if the final version will use Filebeat for shipping
the logs or a Go package to ship directly to Logstash.

*** Test-driven development (TDD & BDD)
Go has support for testing built in to its toolchain which will be used to cover
unit and integration tests with the help of [[https://github.com/stretchr/testify][testify]] for the assertions.

The framework [[https://github.com/gavv/httpexpect][httpexpect]] will be used for end-to-end tests.

*** Continuous Integration
**** [[https://travis-ci.org/][Travis CI]]
Travis CI is an open source hosted continuous integration and
deployment system which plays nicely with GitHub, for these reasons we
will use it in this project.

**** [[https://github.com/features/actions][Github Actions]]
GitHub Actions is the new continuous integration and deployment system
developed by GitHub, we will use it to run the same tests as Travis
and probably some extra workflows to automate the generation of the
documentation.

*** [[https://github.com/OAI/OpenAPI-Specification/][OpenAPI]]
This project will follow the OpenAPI Specification to document its API
endpoints, probably using swagger to parse the specifications and
generate a static site.

** Documentation
The extended documentation is hosted [[https://iris-garcia.github.io/workday/][here]].

* How to contribute
** Setup the environment
2. Fork the repository.
3. Clone your forked repository.
4. Run ~go get~.

** Add your contribution
1. Create a new branch:
   - ~bug/short-description~
   - ~feature/short-description~
2. Write tests to cover your changes.
3. Run the tests.
   #+begin_src bash
     go test -cover -v
   #+end_src
4. Build and run the binary
   #+begin_src bash
     go build cmd/workday/workday.go
     ./workday
   #+end_src
5. Push the branch to your fork once you think everything works as
   expected.

** Request the integration
1. Create a Pull Request from your branch to ~master~.


* To be removed
[![Build Status](https://travis-ci.com/iris-garcia/workday.svg?branch=master)](https://travis-ci.com/iris-garcia/workday)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ENV_VARS = []string{"WORKDAY_DB_HOST", "WORKDAY_DB_NAME", "WORKDAY_DB_USER", "WORKDAY_DB_PASSWORD"}

Functions

func ConnectDB

func ConnectDB(config DBConfig) (*sql.DB, error)

ConnectDB returns a sql.DB connection using a given DBConfig.

func CreateEmployee

func CreateEmployee(db *sql.DB, employee Employee) (id uint, rows uint, err error)

CreateEmployee saves a new employee in DB.

func IrisHTTPServer

func IrisHTTPServer(db *sql.DB) *iris.Application

Creates and returns an Iris HTTP server

Types

type DBConfig

type DBConfig struct {
	Host     string
	Database string
	User     string
	Password string
}

Represents database parameters

func LoadDBConfig

func LoadDBConfig(filepath string) (DBConfig, error)

Read and parse DB configuration; environment variables have precedence over config file.

type Employee

type Employee struct {
	ID        uint   `json:"id"`
	Firstname string `json:"firstname"`
	Lastname  string `json:"lastname"`
	Role      uint   `json:role`
	Password  string `json:password`
}

Represents an employee

func GetAllEmployees

func GetAllEmployees(db *sql.DB) (employees []Employee, err error)

GetAllEmployees retrieves all employees from DB.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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