initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
const (
|
||||
host = "202.46.28.160"
|
||||
port = 45432
|
||||
user = "5803024003"
|
||||
password = "pw5803024003"
|
||||
dbname = "5803024003_db"
|
||||
)
|
||||
|
||||
func InitDB() {
|
||||
// connection string
|
||||
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
|
||||
|
||||
// open database
|
||||
db, err := sql.Open("postgres", psqlconn)
|
||||
CheckError(err)
|
||||
|
||||
// close database
|
||||
defer db.Close()
|
||||
|
||||
// check db
|
||||
err = db.Ping()
|
||||
CheckError(err)
|
||||
|
||||
fmt.Println("Connected!")
|
||||
}
|
||||
|
||||
func CheckError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Region represents a geographical region (e.g., "West Campus", "Downtown")
|
||||
type Groups struct {
|
||||
GroupID int `json:"regionId" db:"region_id"`
|
||||
GroupName string `json:"name" db:"name"`
|
||||
}
|
||||
|
||||
// Building represents a building within a region
|
||||
type Tasks struct {
|
||||
TaskID int `json:"buildingId" db:"building_id"`
|
||||
TaskName string `json:"name" db:"name"`
|
||||
TaskDescription int `json:"floorCount,omitempty" db:"floor_count"`
|
||||
GroupID int `json:"regionId" db:"region_id"`
|
||||
IsDone bool `json:"isDone" db:"is_done"`
|
||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func CreateGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte("Group Created"))
|
||||
}
|
||||
|
||||
func RemoveGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupID := vars["groupId"]
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Group ID " + groupID + " Removed"))
|
||||
}
|
||||
|
||||
func GetGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupID := vars["groupId"]
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Displaying Group ID: " + groupID))
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func CreateTaskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte("Task Created"))
|
||||
}
|
||||
|
||||
func DisplayTasksHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Displaying All Tasks"))
|
||||
}
|
||||
|
||||
func DisplayTasksByGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupID := vars["groupId"]
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Displaying Tasks for Group ID: " + groupID))
|
||||
}
|
||||
|
||||
func GetTaskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
taskID := vars["taskId"]
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Displaying Task ID: " + taskID))
|
||||
}
|
||||
|
||||
func MarkTaskDoneHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
taskID := vars["taskId"]
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Task ID " + taskID + " Marked as Done"))
|
||||
}
|
||||
|
||||
func RemoveTaskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
taskID := vars["taskId"]
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Task ID " + taskID + " Removed"))
|
||||
}
|
||||
|
||||
func UpdateTaskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
taskID := vars["taskId"]
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Task ID " + taskID + " Updated"))
|
||||
}
|
||||
Reference in New Issue
Block a user