Skip to content

Commit

Permalink
Merge pull request #30 from uug-ai/ui-feature-dashboard
Browse files Browse the repository at this point in the history
UI feature dashboard
  • Loading branch information
KilianBoute authored Jun 4, 2024
2 parents 4bc114a + 3191aef commit 665f0e7
Show file tree
Hide file tree
Showing 49 changed files with 3,441 additions and 1,338 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ml/scripts/utils/__pycache__
ml/data/face_inference.mp4
ml/data/test_images
node_modules
ui/out
ui/out
__debug_bin*
Empty file added api/.env
Empty file.
20 changes: 20 additions & 0 deletions api/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": ["-action", "run"],
"envFile": "${workspaceFolder}/.env",
"buildFlags": "--tags dynamic"
}
]
}
Empty file added api/__debug_bin141116329
Empty file.
Empty file added api/__debug_bin383952432
Empty file.
Binary file added api/__debug_bin783398833
Binary file not shown.
Empty file added api/__debug_bin825136468
Empty file.
119 changes: 119 additions & 0 deletions api/controllers/locations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package controllers

import (
"strconv"

"github.com/gin-gonic/gin"
"github.com/uug-ai/facial-access-control/api/database"
"github.com/uug-ai/facial-access-control/api/models"
)

// Locations godoc
// @Router /api/locations [get]
// @ID getLocations
// @Tags locations
// @Summary Get all locations
// @Description Get all locations
// @Success 200 {object} []models.Location
func GetLocations(c *gin.Context) []models.Location {
locations := database.GetLocations()
c.JSON(200, gin.H{
"data": locations,
})
return nil;
}

// Location godoc
// @Router /api/locations/{id} [get]
// @ID getLocation
// @Tags locations
// @Summary Get location by ID
// @Description Get location by ID
// @Param id path int true "Location ID"
// @Success 200 {object} models.Location
func GetLocation(c *gin.Context) models.Location {
id := c.Param("id")

locationID, err := strconv.Atoi(id)
if err != nil {
c.JSON(400, gin.H{
"error": "Invalid location ID",
})
return models.Location{}
}

location := database.GetLocation(locationID)

c.JSON(200, gin.H{
"data": location,
})
return location
}


// location godoc
// @Router /api/locations [post]
// @ID addLocation
// @Tags locations
// @Summary Create location
// @Description Create location
// @Accept json
// @Produce json
// @Param location body models.Location true "Location"
// @Success 200 {object} models.Location
func AddLocation(c *gin.Context) error {
var location models.Location
if err := c.ShouldBindJSON(&location); err != nil {
c.JSON(400, gin.H{
"error": "Invalid location data",
})
return err
}

if err := database.AddLocation(location); err != nil {
c.JSON(500, gin.H{
"error": "Failed to add location",
})
return err
}

c.JSON(201, gin.H{
"message": "Location added successfully",
"location": location,
})
return nil
}

// location godoc
// @Router /api/locations/{id} [delete]
// @ID deleteLocation
// @Tags locations
// @Summary Delete location
// @Description Delete location
// @Param id path int true "Location ID"
// @Success 200
func DeleteLocation(c *gin.Context) error {
id := c.Param("id")
locationID, err := strconv.Atoi(id)

if err != nil {
c.JSON(400, gin.H{
"error": "Invalid location ID",
})
return err
}

if err := database.DeleteLocation(locationID); err != nil {
c.JSON(500, gin.H{
"error": "Failed to delete location",
})
return err
}

c.JSON(200, gin.H{
"message": "Location deleted successfully",
})
return nil
}


116 changes: 116 additions & 0 deletions api/controllers/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package controllers

import (
"strconv"

"github.com/gin-gonic/gin"
"github.com/uug-ai/facial-access-control/api/database"
"github.com/uug-ai/facial-access-control/api/models"
)

// user godoc
// @Router /api/users [get]
// @ID getUsers
// @Tags users
// @Summary Get all users
// @Description Get all users
// @Success 200 {array} models.User
func GetUsers(c *gin.Context) []models.User {
users := database.GetUsers()
c.JSON(200, gin.H{
"data": users,
})
return nil;
}

// user godoc
// @Router /api/users/{id} [get]
// @ID getUser
// @Tags users
// @Summary Get user
// @Description Get user
// @Param id path int true "User ID"
// @Success 200 {object} models.User
func GetUser(c *gin.Context) models.User {
id := c.Param("id")

userID, err := strconv.Atoi(id)
if err != nil {
c.JSON(400, gin.H{
"error": "Invalid user ID",
})
return models.User{}
}

user := database.GetUser(userID)

c.JSON(200, gin.H{
"data": user,
})
return user
}

// user godoc
// @Router /api/users [post]
// @ID addUser
// @Tags users
// @Summary Add user
// @Description Add user
// @Accept json
// @Produce json
// @Param user body models.User true "User data"
// @Success 201 {object} models.User
func AddUser(c *gin.Context) error {
var user models.User
if err := c.ShouldBindJSON(&user); err != nil {
c.JSON(400, gin.H{
"error": "Invalid user data",
})
return err
}

if err := database.AddUser(user); err != nil {
c.JSON(500, gin.H{
"error": "Failed to add user",
})
return err
}

c.JSON(201, gin.H{
"message": "User added successfully",
"user": user,
})
return nil
}

// user godoc
// @Router /api/users/{id} [delete]
// @ID deleteUser
// @Tags users
// @Summary Delete user
// @Description Delete user
// @Param id path int true "User ID"
// @Success 200
func DeleteUser(c *gin.Context) error {
id := c.Param("id")

userID, err := strconv.Atoi(id)
if err != nil {
c.JSON(400, gin.H{
"error": "Invalid user ID",
})
return err
}

if err := database.DeleteUser(userID); err != nil {
c.JSON(500, gin.H{
"error": "Failed to delete user",
})
return err
}

c.JSON(200, gin.H{
"message": "User deleted successfully",
})
return nil
}
27 changes: 27 additions & 0 deletions api/data/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package data

import "github.com/uug-ai/facial-access-control/api/models"

var Users = []models.User{
{Id: 0, FirstName: "admin", LastName: "admin", Email: "[email protected]", Password: "admin", Role: "admin", Language: "en"},
{Id: 1, FirstName: "user", LastName: "user", Email: "[email protected]", Password: "user", Role: "user", Language: "en"},
{Id: 2, FirstName: "Kilian", LastName: "Smith", Email: "[email protected]", Password: "Kilian", Role: "admin", Language: "en"},
{Id: 3, FirstName: "Cedric", LastName: "Johnson", Email: "[email protected]", Password: "Cedric", Role: "admin", Language: "en"},
{Id: 4, FirstName: "Johann", LastName: "Brown", Email: "[email protected]", Password: "Johann", Role: "admin", Language: "en"},
{Id: 5, FirstName: "Romain", LastName: "Davis", Email: "[email protected]", Password: "Romain", Role: "admin", Language: "en"},
{Id: 6, FirstName: "Alex", LastName: "Wilson", Email: "[email protected]", Password: "Alex", Role: "admin", Language: "en"},
{Id: 7, FirstName: "Mickael", LastName: "Taylor", Email: "[email protected]", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 8, FirstName: "Mickael", LastName: "Thomas", Email: "[email protected]", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 9, FirstName: "Mickael", LastName: "Robinson", Email: "[email protected]", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 10, FirstName: "Mickael", LastName: "Clark", Email: "[email protected]", Password: "Mickael", Role: "admin", Language: "en"},
}

var Locations = []models.Location{
{Id: 1, Name: "Location 1", Address: "Address 1", Lat: 1.0, Lng: 1.0},
{Id: 2, Name: "Location 2", Address: "Address 2", Lat: 2.0, Lng: 2.0},
{Id: 3, Name: "Location 3", Address: "Address 3", Lat: 3.0, Lng: 3.0},
{Id: 4, Name: "Location 4", Address: "Address 4", Lat: 4.0, Lng: 4.0},
}



99 changes: 99 additions & 0 deletions api/database/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package database

import (
"errors"

"github.com/uug-ai/facial-access-control/api/data"
"github.com/uug-ai/facial-access-control/api/models"
)


func GetUsersFromFile() []models.User {
users := data.Users
return users
}

func GetUserFromFile(id int) models.User {
users := data.Users
for _, user := range users {
if user.Id == id {
return user
}
}
return models.User{}
}


func AddUserToFile(user models.User) error {
users := data.Users

// Find the maximum ID in the current user list
maxID := 0
for _, u := range users {
if u.Id > maxID {
maxID = u.Id
}
}

// Assign the new user an ID that is one greater than the current maximum
user.Id = maxID + 1

data.Users = append(data.Users, user)
return nil
}

func DeleteUserFromFile(id int) error {
users := data.Users
for i, user := range users {
if user.Id == id {
data.Users = append(users[:i], users[i+1:]...)
return nil
}
}
return errors.New("user not found")
}


func GetLocationsFromFile() []models.Location {
locations := data.Locations
return locations
}

func GetLocationFromFile(id int) models.Location {
locations := data.Locations
for _, location := range locations {
if location.Id == id {
return location
}
}
return models.Location{}
}

func AddLocationToFile(location models.Location) error {
locations := data.Locations

// Find the maximum ID in the current user list
maxID := 0
for _, location := range locations {
if location.Id > maxID {
maxID = location.Id
}
}

// Assign the new user an ID that is one greater than the current maximum
location.Id = maxID + 1

data.Locations = append(data.Locations, location)
return nil
}

func DeleteLocationFromFile(id int) error {
locations := data.Locations
for i, location := range locations {
if location.Id == id {
data.Locations = append(locations[:i], locations[i+1:]...)
return nil
}
}
return errors.New("location not found")
}
Loading

0 comments on commit 665f0e7

Please sign in to comment.