api.spaceplanner.app

Spaceplanner API
git clone git://jacobedwards.org/api.spaceplanner.app
Log | Files | Refs

commit 22bf6bae578b7daa4c2f7dbb89e6af6023226364
parent 109fd2eb896c4d5d6c05d3de6850b830106b1237
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Fri, 11 Oct 2024 11:27:45 -0700

Add users/:user/services/subscribed endpoint

This endpoint returns the services the user is subscribed to. At
the moment it returns a stripe product ID because there is only
going to be one level of service for the time being and I'm not
going to spend time on that right now.

In the future I expect to have multiple levels of service, at which
time I'll take an hour to implement web hooks for stripe product
and price updates and cache them locally most likely.

Diffstat:
Mcmd/api/main.go | 1+
Mcmd/api/users.go | 19+++++++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/cmd/api/main.go b/cmd/api/main.go @@ -109,6 +109,7 @@ func setAuthenticatedRoutes(env *Env, r *gin.RouterGroup) { user.GET("/settings", env.GetUserSettings) user.POST("/services/checkout", env.CreateCheckout) user.POST("/services/billingportal", env.CreatePortal) + user.GET("/services/subscribed", env.UserService) email := user.Group("/email") email.GET("/code", env.SendUserEmailCode) diff --git a/cmd/api/users.go b/cmd/api/users.go @@ -176,3 +176,22 @@ func (e *Env) UpdateUserSettings(c *gin.Context) { Respond(c, http.StatusOK, settings) } + +// In the future I want to return an array of backend.Service types +func (e *Env) UserService(c *gin.Context) { + type body struct { + Services []string `json:"services"` + } + + service, err := e.backend.UserService(c.Param("user")) + if err != nil { + RespondError(c, 500, "Unable to get service") + } else { + var body body + body.Services = make([]string, 0, 1) + if service != nil { + body.Services = append(body.Services, *service) + } + Respond(c, 200, body) + } +}