Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5746bc9
adding entries handlers and a docker file
Avnermond12344 Dec 4, 2025
c04b00d
adding mock database, SCHEME.rd and a dockerfile
Avnermond12344 Dec 9, 2025
b80975e
adapting the structure of equipment list
Avnermond12344 Dec 9, 2025
407e5d7
adding struct for users
Avnermond12344 Dec 26, 2025
a7bea4a
adding mock data for users & carts
Avnermond12344 Dec 26, 2025
2df1df3
adding login & shopping cart handlers
Avnermond12344 Dec 26, 2025
512ca78
fixing minor bug
Avnermond12344 Dec 26, 2025
abf34ea
Merge branch 'main' of https://github.com/Motzklist/Back-End
Avnermond12344 Dec 30, 2025
a89aee0
Merge branch 'main' of https://github.com/Motzklist/Back-End
Avnermond12344 Jan 7, 2026
e5ea087
adding API for the DB
Avnermond12344 Jan 7, 2026
470f6bf
adding getUsernameFromUserID function
Avnermond12344 Jan 7, 2026
d151079
slight modifications
Avnermond12344 Jan 7, 2026
1e0bb9a
removing timestamp
Avnermond12344 Jan 7, 2026
f2ae997
modifing main.go so it supports the new API file
Avnermond12344 Jan 7, 2026
ca6cc24
modulating the main file
Avnermond12344 Jan 7, 2026
077a932
Refactor DB methods to use actual database queries
roishm Jan 7, 2026
4398c62
Merge pull request #1 from roishm/patch-1
Avnermond12344 Jan 7, 2026
b805658
Merge branch 'main' of https://github.com/Avnermond12344/api-gateway-…
Avnermond12344 Jan 7, 2026
97bdccd
Adding a DB initialization
Avnermond12344 Jan 14, 2026
2de5701
updating the go.mod
Avnermond12344 Jan 14, 2026
65ee997
updating Dockefile
Avnermond12344 Jan 14, 2026
3a376ff
rebuilding the init function
Avnermond12344 Jan 14, 2026
3141955
adding a TODO
Avnermond12344 Jan 27, 2026
891d300
adding payment handlers, and env file and modifications to main.go
Avnermond12344 May 11, 2026
88e2c1c
adding 'Price' field to Equipment
Avnermond12344 May 12, 2026
5382a72
updating getCatItemsFromApply to price field
Avnermond12344 May 12, 2026
207e43e
Merge pull request #36 from Avnermond12344/payment_api
NoamBenShimon May 12, 2026
c489345
Added prices to mock database and updated name of project to motzklis…
NoamBenShimon May 12, 2026
18bca30
Merge branch 'main' into payment-api
NoamBenShimon May 27, 2026
adf37cd
Refactor payment handlers and update database connection string
NoamBenShimon May 27, 2026
d7feafd
Validate input parameters in checkout session creation and ensure FRO…
NoamBenShimon May 27, 2026
aa14a32
Remove old handlers
NoamBenShimon May 27, 2026
c4e38d8
Skip tests that require database for now
NoamBenShimon May 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.idea/
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ LABEL authors="avner"
WORKDIR /app

# Copying the source code into the container
COPY go.mod ./
COPY go.mod go.sum ./

RUN go mod tidy
RUN go mod download

COPY *.go ./

# Building the Go application (
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o motzklist-api-gateway .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o motzklist-backend .

# Creating the final smaller image
FROM alpine:latest
Expand All @@ -22,6 +22,6 @@ EXPOSE 8080
# Set the working directory
WORKDIR /root/
# Copy the built binary from the builder stage
COPY --from=builder /app/motzklist-api-gateway .
COPY --from=builder /app/motzklist-backend .
# Command to run the executable when the container starts
CMD ["./motzklist-api-gateway"]
CMD ["./motzklist-backend"]
51 changes: 51 additions & 0 deletions cart_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
)

func getPostCartHandler(w http.ResponseWriter, r *http.Request) {
userID := r.URL.Query().Get("userid")
if userID == "" {
JSONError(w, "Missing required query parameter: userid", http.StatusBadRequest)
return
}
if _, err := strconv.Atoi(userID); err != nil {
JSONError(w, "userid must be an integer", http.StatusBadRequest)
return
}

// TODO: make sure the front sends a POST request if items were picked
switch r.Method {
case http.MethodGet:
// Return existing cart (now returns []CartEntry)
cart := getCartByUserID(userID)
err := json.NewEncoder(w).Encode(cart)
if err != nil {
log.Printf("Failed to encode cart response: %v", err)
}

case http.MethodPost, http.MethodPut:
// Update the cart (expects []CartEntry)
var newEntries []CartEntry
if err := json.NewDecoder(r.Body).Decode(&newEntries); err != nil {
JSONError(w, "Failed to decode request body", http.StatusBadRequest)
return
}
if err := saveCart(userID, newEntries); err != nil {
JSONError(w, "Failed to save cart", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
if _, err := fmt.Fprintf(w, "Cart updated successfully"); err != nil {
log.Printf("Failed to write cart update response: %v", err)
}

default:
JSONError(w, "Method not allowed", http.StatusMethodNotAllowed)
}
}
95 changes: 95 additions & 0 deletions class_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"encoding/json"
"log"
"net/http"
"strconv"
)

func getSchoolsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

// LATER: connect to database, extract corresponding list and parse it
schools := getSchools()

// Convert to Json
if err := json.NewEncoder(w).Encode(schools); err != nil {
JSONError(w, "Failed to encode schools response", http.StatusInternalServerError)
log.Printf("Error encoding response: %v", err)
return
}
log.Printf("Successfully served /api/schools request")
}

func getGradesHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

// Extract the school_id query parameter
schoolID := r.URL.Query().Get("school_id")

// 1. Input Validation: Check if the required parameter is missing
if schoolID == "" {
JSONError(w, "Missing required query parameter: school_id", http.StatusBadRequest)
return
}
if _, err := strconv.Atoi(schoolID); err != nil {
JSONError(w, "school_id must be an integer", http.StatusBadRequest)
return
}

log.Printf("Received request for grades in school ID: %s", schoolID)

// LATER: The mock data here would be filtered based on schoolID
// For now, we return the full mock list regardless of the ID.

// LATER: connect to database, extract corresponding list and parse it

grades := getGrades(schoolID)

// Convert to Json
if err := json.NewEncoder(w).Encode(grades); err != nil {
JSONError(w, "Failed to encode grades response", http.StatusInternalServerError)
log.Printf("Error encoding response: %v", err)
return
}
log.Printf("Successfully served /api/grades request")
}

func getEquipmentListsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

// Extract the required query parameters (updated)
schoolID := r.URL.Query().Get("school_id")
gradeID := r.URL.Query().Get("grade_id")

// 1. Input Validation (updated)
if schoolID == "" || gradeID == "" {
JSONError(w, "Missing required query parameters: school_id or grade_id", http.StatusBadRequest)
return
}
if _, err := strconv.Atoi(schoolID); err != nil {
JSONError(w, "school_id must be an integer", http.StatusBadRequest)
return
}
if _, err := strconv.Atoi(gradeID); err != nil {
JSONError(w, "grade_id must be an integer", http.StatusBadRequest)
return
}

log.Printf("Received request for equipment list: School=%s, Grade=%s", schoolID, gradeID)

// LATER: connect to database, extract corresponding list and parse it
equipment := getEquipment(schoolID, gradeID)

response := EquipmentListResponse{
Items: equipment,
}

if err := json.NewEncoder(w).Encode(response); err != nil {
JSONError(w, "Failed to encode equipment response", http.StatusInternalServerError)
log.Printf("Error encoding response: %v", err)
return
}
log.Printf("Successfully served /api/equipment request")
}
Loading
Loading