Skip to content

Commit

Permalink
feat: add logic to get info if counter is locked or not
Browse files Browse the repository at this point in the history
  • Loading branch information
mgierada committed Jun 3, 2024
1 parent 4b00561 commit a895715
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/db/get_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ func GetCounter() (Counter, error) {
func GetOhnoCounter() (Counter, error) {
return getCounter("ohno_counter")
}

func GetCounterLocked() bool {
counter, err := GetCounter()
if err != nil {
return false
}
return counter.IsLocked
}

func GetOhnoCounterLocked() bool {
counter, err := GetOhnoCounter()
if err != nil {
return false
}
return counter.IsLocked
}
11 changes: 11 additions & 0 deletions server/handlers/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func IncrementCounter(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
db.UpdateCounter()
isCounterLocked := isCounterLocked()
isOhnoCounterLocked := isOhnoCounterLocked()
log.Printf("🔒 Counter locked: %t, Ohno Counter locked: %t", isCounterLocked, isOhnoCounterLocked)
response := ServerResponse{Message: "Counter incremented successfully"}
MarshalJson(w, http.StatusOK, response)
log.Println("🟢 Counter incremented successfully")
Expand All @@ -56,6 +59,14 @@ func IncrementCounter(w http.ResponseWriter, r *http.Request) {
}
}

func isCounterLocked() bool {
return db.GetCounterLocked()
}

func isOhnoCounterLocked() bool {
return db.GetOhnoCounterLocked()
}

type ManualCouterIncrementRequest struct {
Value int `json:"value"`
}
Expand Down

0 comments on commit a895715

Please sign in to comment.