Skip to content

Commit 1bde990

Browse files
committed
Refactor: Rename service methods for consistency and clarity
1 parent 6885e57 commit 1bde990

7 files changed

+17
-17
lines changed

service/discordBaseService.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func DiscordBaseService(response http.ResponseWriter, request *http.Request) {
3232

3333
case discordgo.InteractionApplicationCommand:
3434
mainService := CommandService{discordMessage: &message}
35-
mainService.MainService(response, request)
35+
mainService.HandleMessage(response, request)
3636

3737
return
3838

service/helloService.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/bwmarrin/discordgo"
88
)
99

10-
func (s *CommandService) HelloService(response http.ResponseWriter, request *http.Request) {
10+
func (s *CommandService) Hello(response http.ResponseWriter, request *http.Request) {
1111
messageResponse := &discordgo.InteractionResponse{
1212
Type: discordgo.InteractionResponseChannelMessageWithSource,
1313
Data: &discordgo.InteractionResponseData{

service/helloService_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestHelloService(t *testing.T) {
2525
CS := CommandService{
2626
discordMessage: fixtures.HelloCommand,
2727
}
28-
CS.HelloService(w, r)
28+
CS.Hello(w, r)
2929

3030
assert.Equal(t, http.StatusOK, w.Code)
3131
var response discordgo.InteractionResponse

service/listeningService.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/bwmarrin/discordgo"
1212
)
1313

14-
func (s *CommandService) ListeningService(response http.ResponseWriter, request *http.Request) {
14+
func (s *CommandService) Listening(response http.ResponseWriter, request *http.Request) {
1515
options := s.discordMessage.Data.Options[0]
1616
msg := ""
1717
requiresUpdate := false
@@ -50,7 +50,7 @@ func (s *CommandService) ListeningService(response http.ResponseWriter, request
5050
Type: discordgo.InteractionResponseChannelMessageWithSource,
5151
Data: &discordgo.InteractionResponseData{
5252
Content: fmt.Sprintf(msg),
53-
Flags: 64, // Ephemeral message flag
53+
Flags: discordgo.MessageFlags(64), // Ephemeral message flag
5454
},
5555
}
5656
utils.Success.NewDiscordResponse(response, "Success", messageResponse)

service/listeningService_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestListeningService(t *testing.T) {
5858
}
5959

6060
commandService := &CommandService{discordMessage: discordMessage}
61-
commandService.ListeningService(rr, req)
61+
commandService.Listening(rr, req)
6262

6363
assert.Contains(t, rr.Body.String(), "You are already set to listen.")
6464
})
@@ -86,7 +86,7 @@ func TestListeningService(t *testing.T) {
8686
}
8787

8888
commandService := &CommandService{discordMessage: discordMessage}
89-
commandService.ListeningService(rr, req)
89+
commandService.Listening(rr, req)
9090

9191
assert.Contains(t, rr.Body.String(), "Your nickname remains unchanged.")
9292
})
@@ -119,7 +119,7 @@ func TestListeningService(t *testing.T) {
119119
}
120120

121121
commandService := &CommandService{discordMessage: discordMessage}
122-
commandService.ListeningService(rr, req)
122+
commandService.Listening(rr, req)
123123

124124
assert.Contains(t, rr.Body.String(), "Your nickname will be updated shortly.")
125125
})

service/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ type CommandService struct {
1111
discordMessage *dtos.DiscordMessage
1212
}
1313

14-
func (s *CommandService) MainService(response http.ResponseWriter, request *http.Request) {
15-
switch s.discordMessage.Data.Name {
14+
func (service *CommandService) HandleMessage(response http.ResponseWriter, request *http.Request) {
15+
switch service.discordMessage.Data.Name {
1616
case utils.CommandNames.Hello:
17-
s.HelloService(response, request)
17+
service.Hello(response, request)
1818
return
1919
case utils.CommandNames.Listening:
20-
s.ListeningService(response, request)
20+
service.Listening(response, request)
2121
return
2222
case utils.CommandNames.Verify:
23-
s.VerifyService(response, request)
23+
service.VerifyService(response, request)
2424
return
2525
default:
2626
utils.Errors.NewBadRequestError(response, "Invalid Command")

service/main_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestMainService(t *testing.T) {
2020
CS := CommandService{discordMessage: fixtures.HelloCommand}
2121
w := httptest.NewRecorder()
2222
r, _ := http.NewRequest("GET", "/", nil)
23-
CS.MainService(w, r)
23+
CS.HandleMessage(w, r)
2424

2525
assert.Equal(t, http.StatusOK, w.Code)
2626
})
@@ -44,7 +44,7 @@ func TestMainService(t *testing.T) {
4444
CS := CommandService{discordMessage: discordMessage}
4545
w := httptest.NewRecorder()
4646
r, _ := http.NewRequest("GET", "/", nil)
47-
CS.MainService(w, r)
47+
CS.HandleMessage(w, r)
4848
messageResponse := discordgo.InteractionResponse{}
4949
err := json.Unmarshal(w.Body.Bytes(), &messageResponse)
5050
assert.NoError(t, err)
@@ -65,7 +65,7 @@ func TestMainService(t *testing.T) {
6565
CS := CommandService{discordMessage: discordMessage}
6666
w := httptest.NewRecorder()
6767
r, _ := http.NewRequest("GET", "/", nil)
68-
CS.MainService(w, r)
68+
CS.HandleMessage(w, r)
6969
messageResponse := discordgo.InteractionResponse{}
7070
err := json.Unmarshal(w.Body.Bytes(), &messageResponse)
7171
assert.NoError(t, err)
@@ -87,7 +87,7 @@ func TestMainService(t *testing.T) {
8787

8888
w := httptest.NewRecorder()
8989
r, _ := http.NewRequest("GET", "/", nil)
90-
CS.MainService(w, r)
90+
CS.HandleMessage(w, r)
9191

9292
assert.Equal(t, http.StatusBadRequest, w.Code)
9393
})

0 commit comments

Comments
 (0)