Skip to content

Commit fd13c02

Browse files
committed
Move db to sdk conversions to db2sdk.go
1 parent 8035333 commit fd13c02

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

coderd/database/db2sdk/db2sdk.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,20 @@ func templateVersionParameterOptions(rawOptions json.RawMessage) ([]codersdk.Tem
217217
}
218218
return options, nil
219219
}
220+
221+
func OAuth2ProviderApp(dbApp database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
222+
return codersdk.OAuth2ProviderApp{
223+
ID: dbApp.ID,
224+
Name: dbApp.Name,
225+
CallbackURL: dbApp.CallbackURL,
226+
Icon: dbApp.Icon,
227+
}
228+
}
229+
230+
func OAuth2ProviderApps(dbApps []database.OAuth2ProviderApp) []codersdk.OAuth2ProviderApp {
231+
apps := []codersdk.OAuth2ProviderApp{}
232+
for _, dbApp := range dbApps {
233+
apps = append(apps, OAuth2ProviderApp(dbApp))
234+
}
235+
return apps
236+
}

enterprise/coderd/oauth2.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,14 @@ import (
77
"github.com/google/uuid"
88

99
"github.com/coder/coder/v2/coderd/database"
10+
"github.com/coder/coder/v2/coderd/database/db2sdk"
1011
"github.com/coder/coder/v2/coderd/database/dbtime"
1112
"github.com/coder/coder/v2/coderd/httpapi"
1213
"github.com/coder/coder/v2/coderd/httpmw"
1314
"github.com/coder/coder/v2/codersdk"
1415
"github.com/coder/coder/v2/cryptorand"
1516
)
1617

17-
func convertApp(app database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
18-
return codersdk.OAuth2ProviderApp{
19-
ID: app.ID,
20-
Name: app.Name,
21-
CallbackURL: app.CallbackURL,
22-
Icon: app.Icon,
23-
}
24-
}
25-
2618
// @Summary Get OAuth2 applications.
2719
// @ID get-oauth2-applications
2820
// @Security CoderSessionToken
@@ -37,11 +29,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
3729
httpapi.InternalServerError(rw, err)
3830
return
3931
}
40-
apps := []codersdk.OAuth2ProviderApp{}
41-
for _, app := range dbApps {
42-
apps = append(apps, convertApp(app))
43-
}
44-
httpapi.Write(ctx, rw, http.StatusOK, apps)
32+
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(dbApps))
4533
}
4634

4735
// @Summary Get OAuth2 application.
@@ -55,7 +43,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
5543
func (*API) oAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
5644
ctx := r.Context()
5745
app := httpmw.OAuth2ProviderApp(r)
58-
httpapi.Write(ctx, rw, http.StatusOK, convertApp(app))
46+
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
5947
}
6048

6149
// @Summary Create OAuth2 application.
@@ -88,7 +76,7 @@ func (api *API) postOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
8876
})
8977
return
9078
}
91-
httpapi.Write(ctx, rw, http.StatusCreated, convertApp(app))
79+
httpapi.Write(ctx, rw, http.StatusCreated, db2sdk.OAuth2ProviderApp(app))
9280
}
9381

9482
// @Summary Update OAuth2 application.
@@ -122,7 +110,7 @@ func (api *API) putOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
122110
})
123111
return
124112
}
125-
httpapi.Write(ctx, rw, http.StatusOK, convertApp(app))
113+
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
126114
}
127115

128116
// @Summary Delete OAuth2 application.

0 commit comments

Comments
 (0)