@@ -4,15 +4,41 @@ import (
44 "context"
55 "errors"
66 "fmt"
7- "strings"
87
98 api "github.com/sunfmin/shadcn-admin-go/api/gen/admin"
109 "github.com/sunfmin/shadcn-admin-go/internal/models"
1110 "gorm.io/gorm"
1211)
1312
14- // ListApps implements api.Handler.
15- func (s * AdminService ) ListApps (ctx context.Context , params api.ListAppsParams ) (* api.AppListResponse , error ) {
13+ // AppService interface for app operations
14+ type AppService interface {
15+ List (ctx context.Context , params api.ListAppsParams ) (* api.AppListResponse , error )
16+ Connect (ctx context.Context , params api.ConnectAppParams ) (* api.App , error )
17+ Disconnect (ctx context.Context , params api.DisconnectAppParams ) (* api.App , error )
18+ }
19+
20+ // appServiceImpl implements AppService
21+ type appServiceImpl struct {
22+ db * gorm.DB
23+ }
24+
25+ // appServiceBuilder is the builder for AppService
26+ type appServiceBuilder struct {
27+ db * gorm.DB
28+ }
29+
30+ // NewAppService creates a new AppService builder
31+ func NewAppService (db * gorm.DB ) * appServiceBuilder {
32+ return & appServiceBuilder {db : db }
33+ }
34+
35+ // Build creates the AppService
36+ func (b * appServiceBuilder ) Build () AppService {
37+ return & appServiceImpl {db : b .db }
38+ }
39+
40+ // List implements AppService
41+ func (s * appServiceImpl ) List (ctx context.Context , params api.ListAppsParams ) (* api.AppListResponse , error ) {
1642 select {
1743 case <- ctx .Done ():
1844 return nil , ctx .Err ()
@@ -62,8 +88,8 @@ func (s *AdminService) ListApps(ctx context.Context, params api.ListAppsParams)
6288 }, nil
6389}
6490
65- // ConnectApp implements api.Handler.
66- func (s * AdminService ) ConnectApp (ctx context.Context , params api.ConnectAppParams ) (* api.App , error ) {
91+ // Connect implements AppService
92+ func (s * appServiceImpl ) Connect (ctx context.Context , params api.ConnectAppParams ) (* api.App , error ) {
6793 select {
6894 case <- ctx .Done ():
6995 return nil , ctx .Err ()
@@ -87,8 +113,8 @@ func (s *AdminService) ConnectApp(ctx context.Context, params api.ConnectAppPara
87113 return & result , nil
88114}
89115
90- // DisconnectApp implements api.Handler.
91- func (s * AdminService ) DisconnectApp (ctx context.Context , params api.DisconnectAppParams ) (* api.App , error ) {
116+ // Disconnect implements AppService
117+ func (s * appServiceImpl ) Disconnect (ctx context.Context , params api.DisconnectAppParams ) (* api.App , error ) {
92118 select {
93119 case <- ctx .Done ():
94120 return nil , ctx .Err ()
@@ -127,8 +153,3 @@ func appToAPI(a models.App) api.App {
127153
128154 return result
129155}
130-
131- // generateAppID generates a unique app ID
132- func generateAppID (name string ) string {
133- return strings .ToLower (strings .ReplaceAll (name , " " , "-" ))
134- }
0 commit comments