Skip to content

Commit

Permalink
Implement update station
Browse files Browse the repository at this point in the history
  • Loading branch information
masayag committed Nov 19, 2023
1 parent 8cd8e48 commit ea727b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
16 changes: 8 additions & 8 deletions pkg/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ paths:
application/json:
schema:
type: object
required:
- properties
properties:
isOpen:
type: boolean
description: New status for station's open status
required:
- isOpen
responses:
"200":
description: OK
Expand Down
25 changes: 24 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"errors"
"fmt"
"github.com/il-blood-donation-info/blood-donation-backend/pkg/api"
"gorm.io/gorm"
Expand Down Expand Up @@ -44,7 +45,29 @@ func (s StrictBloodInfoServer) GetStations(ctx context.Context, request api.GetS

// UpdateStation updates station
func (s StrictBloodInfoServer) UpdateStation(ctx context.Context, request api.UpdateStationRequestObject) (api.UpdateStationResponseObject, error) {
panic("implement me")
var station api.Station
tx := s.db.First(&station, request.Id)
if tx.Error != nil {
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
// Handle the case when no record is found
return api.UpdateStation404JSONResponse{}, tx.Error
} else {
// Handle other errors
return api.UpdateStation500JSONResponse{}, tx.Error
}
}

// add a status to a schedule point
stationStatus := api.StationStatus{
Id: &station.Id,
IsOpen: request.Body.IsOpen,
}
tx = s.db.Create(&stationStatus)
if tx.Error != nil {
return api.UpdateStation500JSONResponse{}, tx.Error
}

return api.UpdateStation200JSONResponse{}, nil
}

// GetUsers get all users
Expand Down

0 comments on commit ea727b8

Please sign in to comment.