eintopf.info@v0.13.16/service/api/api.go (about)

     1  // Copyright (C) 2022 The Eintopf authors
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  
    16  //go:generate go run github.com/go-swagger/go-swagger/cmd/swagger generate spec -o ./../../api/swagger.json
    17  
    18  // Eintopf Api
    19  //
    20  //	Schemes: http, https
    21  //	BasePath: /api/v1
    22  //	Version: 0.0.1
    23  //
    24  //	Security:
    25  //	- bearer
    26  //
    27  //	SecurityDefinitions:
    28  //	bearer:
    29  //	     type: apiKey
    30  //	     name: Authorization
    31  //	     in: header
    32  //
    33  //	Consumes:
    34  //	- application/json
    35  //
    36  //	Produces:
    37  //	- application/json
    38  //
    39  // swagger:meta
    40  package api
    41  
    42  import (
    43  	"net/http"
    44  
    45  	"github.com/go-chi/chi/v5"
    46  
    47  	apispec "eintopf.info/api"
    48  	"eintopf.info/internal/xhttp"
    49  	"eintopf.info/service/action"
    50  	"eintopf.info/service/auth"
    51  	"eintopf.info/service/event"
    52  	"eintopf.info/service/eventsearch"
    53  	"eintopf.info/service/group"
    54  	"eintopf.info/service/invitation"
    55  	"eintopf.info/service/killswitch"
    56  	"eintopf.info/service/media"
    57  	"eintopf.info/service/notification"
    58  	"eintopf.info/service/osm"
    59  	"eintopf.info/service/passwordrec"
    60  	"eintopf.info/service/place"
    61  	"eintopf.info/service/revent"
    62  	"eintopf.info/service/search"
    63  	"eintopf.info/service/status"
    64  	"eintopf.info/service/user"
    65  )
    66  
    67  var apiFS http.FileSystem = http.Dir("api")
    68  
    69  // Routes returns the http router for the api.
    70  func Routes(
    71  	actionService *action.Service,
    72  	authService auth.Service,
    73  	eventService event.Storer,
    74  	eventsearchService eventsearch.Service,
    75  	groupService group.Service,
    76  	invitationService invitation.Service,
    77  	killswitchService killswitch.Service,
    78  	mediaService media.Service,
    79  	notificationSettingsStore notification.SettingsStorer,
    80  	notificationStore notification.Storer,
    81  	passwordrecService *passwordrec.Service,
    82  	placeService place.Service,
    83  	reventService revent.Service,
    84  	searchService search.Service,
    85  	statusService status.Service,
    86  	userService user.Service,
    87  	osmTiler *osm.Service,
    88  	mediaPath string,
    89  ) func(r chi.Router) {
    90  	return func(r chi.Router) {
    91  		r.Route("/api/v1", func(r chi.Router) {
    92  			r.Use(xhttp.CorsMiddleware)
    93  			r.Use(status.Middleware(statusService))
    94  			r.Use(killswitch.Middleware(killswitchService))
    95  			r.Route("/actions", action.Router(actionService, authService))
    96  			r.Route("/auth", auth.Router(authService))
    97  			r.Route("/events", event.Router(eventService, authService))
    98  			r.Route("/eventsearch", eventsearch.Router(eventsearchService))
    99  			r.Route("/groups", group.Router(groupService, authService))
   100  			r.Route("/invitations", invitation.Router(invitationService, authService))
   101  			r.Route("/killswitch", killswitch.Router(killswitchService))
   102  			r.Route("/media", media.Router(mediaService, authService, mediaPath, "/api"))
   103  			r.Route("/notifications", notification.Router(notificationStore, notificationSettingsStore, authService))
   104  			r.Route("/osm", osm.Router(osmTiler))
   105  			r.Route("/passwordrec", passwordrec.Router(passwordrecService))
   106  			r.Route("/places", place.Router(placeService, authService))
   107  			r.Route("/revents", revent.Router(reventService, authService))
   108  			r.Route("/search", search.Router(searchService))
   109  			r.Route("/status", status.Router(statusService))
   110  			r.Route("/users", user.Router(userService, authService))
   111  
   112  			apispec.AddRoutes(r, "/api/v1")
   113  		})
   114  	}
   115  }