diff --git a/contracts/http/mocks/Response.go b/contracts/http/mocks/Response.go index 8ec9659a0..867d04000 100644 --- a/contracts/http/mocks/Response.go +++ b/contracts/http/mocks/Response.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -71,6 +71,22 @@ func (_m *Response) Redirect(code int, location string) { _m.Called(code, location) } +// Status provides a mock function with given fields: code +func (_m *Response) Status(code int) http.ResponseStatus { + ret := _m.Called(code) + + var r0 http.ResponseStatus + if rf, ok := ret.Get(0).(func(int) http.ResponseStatus); ok { + r0 = rf(code) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(http.ResponseStatus) + } + } + + return r0 +} + // String provides a mock function with given fields: code, format, values func (_m *Response) String(code int, format string, values ...interface{}) { var _ca []interface{} @@ -111,13 +127,12 @@ func (_m *Response) Writer() nethttp.ResponseWriter { return r0 } -type mockConstructorTestingTNewResponse interface { +// NewResponse creates a new instance of Response. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewResponse(t interface { mock.TestingT Cleanup(func()) -} - -// NewResponse creates a new instance of Response. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewResponse(t mockConstructorTestingTNewResponse) *Response { +}) *Response { mock := &Response{} mock.Mock.Test(t) diff --git a/contracts/http/mocks/ResponseOrigin.go b/contracts/http/mocks/ResponseOrigin.go index 9aa62653f..09fa33362 100644 --- a/contracts/http/mocks/ResponseOrigin.go +++ b/contracts/http/mocks/ResponseOrigin.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -75,13 +75,12 @@ func (_m *ResponseOrigin) Status() int { return r0 } -type mockConstructorTestingTNewResponseOrigin interface { +// NewResponseOrigin creates a new instance of ResponseOrigin. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewResponseOrigin(t interface { mock.TestingT Cleanup(func()) -} - -// NewResponseOrigin creates a new instance of ResponseOrigin. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewResponseOrigin(t mockConstructorTestingTNewResponseOrigin) *ResponseOrigin { +}) *ResponseOrigin { mock := &ResponseOrigin{} mock.Mock.Test(t) diff --git a/contracts/http/mocks/ResponseStatus.go b/contracts/http/mocks/ResponseStatus.go new file mode 100644 index 000000000..6a7964916 --- /dev/null +++ b/contracts/http/mocks/ResponseStatus.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.30.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// ResponseStatus is an autogenerated mock type for the ResponseStatus type +type ResponseStatus struct { + mock.Mock +} + +// Data provides a mock function with given fields: contentType, data +func (_m *ResponseStatus) Data(contentType string, data []byte) { + _m.Called(contentType, data) +} + +// Json provides a mock function with given fields: obj +func (_m *ResponseStatus) Json(obj interface{}) { + _m.Called(obj) +} + +// String provides a mock function with given fields: format, values +func (_m *ResponseStatus) String(format string, values ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, values...) + _m.Called(_ca...) +} + +// NewResponseStatus creates a new instance of ResponseStatus. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewResponseStatus(t interface { + mock.TestingT + Cleanup(func()) +}) *ResponseStatus { + mock := &ResponseStatus{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/contracts/http/mocks/ResponseSuccess.go b/contracts/http/mocks/ResponseSuccess.go index 2710c3154..572f7a764 100644 --- a/contracts/http/mocks/ResponseSuccess.go +++ b/contracts/http/mocks/ResponseSuccess.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -27,13 +27,12 @@ func (_m *ResponseSuccess) String(format string, values ...interface{}) { _m.Called(_ca...) } -type mockConstructorTestingTNewResponseSuccess interface { +// NewResponseSuccess creates a new instance of ResponseSuccess. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewResponseSuccess(t interface { mock.TestingT Cleanup(func()) -} - -// NewResponseSuccess creates a new instance of ResponseSuccess. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewResponseSuccess(t mockConstructorTestingTNewResponseSuccess) *ResponseSuccess { +}) *ResponseSuccess { mock := &ResponseSuccess{} mock.Mock.Test(t) diff --git a/contracts/http/response.go b/contracts/http/response.go index 11e864d53..35860fa61 100644 --- a/contracts/http/response.go +++ b/contracts/http/response.go @@ -18,9 +18,17 @@ type Response interface { Redirect(code int, location string) String(code int, format string, values ...any) Success() ResponseSuccess + Status(code int) ResponseStatus Writer() http.ResponseWriter } +//go:generate mockery --name=ResponseStatus +type ResponseStatus interface { + Data(contentType string, data []byte) + Json(obj any) + String(format string, values ...any) +} + //go:generate mockery --name=ResponseSuccess type ResponseSuccess interface { Data(contentType string, data []byte) diff --git a/http/gin_response.go b/http/gin_response.go index 2fe5a78db..f3a6cc087 100644 --- a/http/gin_response.go +++ b/http/gin_response.go @@ -56,6 +56,10 @@ func (r *GinResponse) Success() httpcontract.ResponseSuccess { return NewGinSuccess(r.instance) } +func (r *GinResponse) Status(code int) httpcontract.ResponseStatus { + return NewGinStatus(r.instance, code) +} + func (r *GinResponse) Writer() http.ResponseWriter { return r.instance.Writer } @@ -80,6 +84,27 @@ func (r *GinSuccess) String(format string, values ...any) { r.instance.String(http.StatusOK, format, values...) } +type GinStatus struct { + instance *gin.Context + status int +} + +func NewGinStatus(instance *gin.Context, code int) httpcontract.ResponseSuccess { + return &GinStatus{instance, code} +} + +func (r *GinStatus) Data(contentType string, data []byte) { + r.instance.Data(r.status, contentType, data) +} + +func (r *GinStatus) Json(obj any) { + r.instance.JSON(r.status, obj) +} + +func (r *GinStatus) String(format string, values ...any) { + r.instance.String(r.status, format, values...) +} + func GinResponseMiddleware() httpcontract.Middleware { return func(ctx httpcontract.Context) { blw := &BodyWriter{body: bytes.NewBufferString("")}