Adjust GetMessagesByUserAndApplication to GetMessagesByApplication
This commit is contained in:
parent
bbb82bd2b0
commit
b8b15040f9
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
// The MessageDatabase interface for encapsulating database access.
|
||||
type MessageDatabase interface {
|
||||
GetMessagesByUserAndApplication(userID uint, tokenID string) []*model.Message
|
||||
GetMessagesByApplication(tokenID string) []*model.Message
|
||||
GetApplicationByID(id string) *model.Application
|
||||
GetMessagesByUser(userID uint) []*model.Message
|
||||
DeleteMessageByID(id uint) error
|
||||
|
|
@ -43,8 +43,7 @@ func (a *MessageAPI) GetMessages(ctx *gin.Context) {
|
|||
// GetMessagesWithApplication returns all messages from a specific application.
|
||||
func (a *MessageAPI) GetMessagesWithApplication(ctx *gin.Context) {
|
||||
appID := ctx.Param("appid")
|
||||
userID := auth.GetUserID(ctx)
|
||||
messages := a.DB.GetMessagesByUserAndApplication(userID, appID)
|
||||
messages := a.DB.GetMessagesByApplication(appID)
|
||||
ctx.JSON(200, messages)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (s *MessageSuite) Test_GetMessages() {
|
|||
func (s *MessageSuite) Test_GetMessagesWithToken() {
|
||||
auth.RegisterAuthentication(s.ctx, nil, 4, "")
|
||||
t, _ := time.Parse("2006/01/02", "2021/01/02")
|
||||
s.db.On("GetMessagesByUserAndApplication", uint(4), "mytoken").Return([]*model.Message{{ID: 2, ApplicationID: "mytoken", Message: "hi", Title: "hi", Date: t, Priority: 4}})
|
||||
s.db.On("GetMessagesByApplication", "mytoken").Return([]*model.Message{{ID: 2, ApplicationID: "mytoken", Message: "hi", Title: "hi", Date: t, Priority: 4}})
|
||||
s.ctx.Params = gin.Params{{Key: "appid", Value: "mytoken"}}
|
||||
|
||||
s.a.GetMessagesWithApplication(s.ctx)
|
||||
|
|
|
|||
|
|
@ -97,6 +97,22 @@ func (_m *MockMessageDatabase) GetMessageByID(id uint) *model.Message {
|
|||
return r0
|
||||
}
|
||||
|
||||
// GetMessagesByApplication provides a mock function with given fields: tokenID
|
||||
func (_m *MockMessageDatabase) GetMessagesByApplication(tokenID string) []*model.Message {
|
||||
ret := _m.Called(tokenID)
|
||||
|
||||
var r0 []*model.Message
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.Message); ok {
|
||||
r0 = rf(tokenID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Message)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetMessagesByUser provides a mock function with given fields: userID
|
||||
func (_m *MockMessageDatabase) GetMessagesByUser(userID uint) []*model.Message {
|
||||
ret := _m.Called(userID)
|
||||
|
|
@ -112,19 +128,3 @@ func (_m *MockMessageDatabase) GetMessagesByUser(userID uint) []*model.Message {
|
|||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetMessagesByUserAndApplication provides a mock function with given fields: userID, tokenID
|
||||
func (_m *MockMessageDatabase) GetMessagesByUserAndApplication(userID uint, tokenID string) []*model.Message {
|
||||
ret := _m.Called(userID, tokenID)
|
||||
|
||||
var r0 []*model.Message
|
||||
if rf, ok := ret.Get(0).(func(uint, string) []*model.Message); ok {
|
||||
r0 = rf(userID, tokenID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Message)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue