mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
Retrieving proposals.
* Added GET /data/proposals endpoint which returns all submitted enhancement proposals. Fix #2
This commit is contained in:
parent
a5d98c2eb7
commit
c1cdd4f904
@ -95,7 +95,7 @@ type PhotoMetadata struct {
|
||||
}
|
||||
|
||||
type Proposal struct {
|
||||
OwnerID int `json:"owner_id"`
|
||||
OwnerID UserID `json:"owner_id"`
|
||||
Description string `json:"description"`
|
||||
How string `json:"how"`
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ const (
|
||||
URIDataPeople = "/data/people"
|
||||
URIDataFeatures = "/data/features"
|
||||
URIDataFeaturesPhoto = "/data/features/:feature/photos/:photo"
|
||||
URIDataProposals = "/data/proposals"
|
||||
URITileserverRoot = "/tileserver"
|
||||
URITileserver = URITileserverRoot + "/*x"
|
||||
URITileTemplate = URITileserverRoot + "/map/tiles/{z}/{x}/{y}.pbf"
|
||||
|
@ -105,6 +105,7 @@ func (s *Server) setupRouter() *gin.Engine {
|
||||
router.GET(URIDataPeople, s.handleGETDataPeople)
|
||||
router.GET(URIDataFeatures, s.handleGETDataFeatures)
|
||||
router.GET(URIDataFeaturesPhoto, s.handleGETDataFeaturesPhoto)
|
||||
router.GET(URIDataProposals, s.handleGETDataProposals)
|
||||
|
||||
// tileserver
|
||||
router.GET(URITileserver, gin.WrapH(s.tileserverSvSet.Handler()))
|
||||
@ -354,3 +355,12 @@ func (s *Server) handleGETDataFeaturesPhoto(gc *gin.Context) {
|
||||
|
||||
gc.Data(http.StatusOK, contentType, photoBytes)
|
||||
}
|
||||
|
||||
func (s *Server) handleGETDataProposals(gc *gin.Context) {
|
||||
proposals, err := s.getProposals(nil)
|
||||
if err != nil {
|
||||
internalError(gc, err)
|
||||
return
|
||||
}
|
||||
gc.JSON(http.StatusOK, proposals)
|
||||
}
|
||||
|
@ -971,3 +971,24 @@ func (s *Server) addProposals(conn *sqlite.Conn, proposals []models.Proposal) er
|
||||
s.requestCheckpoint()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) getProposals(conn *sqlite.Conn) ([]models.Proposal, error) {
|
||||
if conn == nil {
|
||||
conn = s.getDbConn()
|
||||
defer s.dbpool.Put(conn)
|
||||
}
|
||||
|
||||
proposals := make([]models.Proposal, 0, 100)
|
||||
err := sqlitex.Exec(conn, "select owner_id, description, how from proposals", func(stmt *sqlite.Stmt) error {
|
||||
proposals = append(proposals, models.Proposal{
|
||||
OwnerID: models.UserID(stmt.ColumnInt(0)),
|
||||
Description: stmt.ColumnText(1),
|
||||
How: stmt.ColumnText(2),
|
||||
})
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get proposals from db: %w", err)
|
||||
}
|
||||
return proposals, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user