Skip to content

Commit 2074ada

Browse files
committed
refactor: remove path value check
1 parent 828ecd5 commit 2074ada

File tree

8 files changed

+3
-74
lines changed

8 files changed

+3
-74
lines changed

apps/uno/http/router/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"uno/http/handler"
88

99
"github.com/go-chi/chi/v5"
10+
chiMiddleware "github.com/go-chi/chi/v5/middleware"
1011
"github.com/go-chi/cors"
1112
"github.com/jesperkha/notifier"
1213
)
@@ -22,6 +23,7 @@ type Router struct {
2223
func New(serviceName string, logger port.Logger) *Router {
2324
mux := chi.NewMux()
2425

26+
mux.Use(chiMiddleware.StripSlashes)
2527
mux.Use(Telemetry(serviceName))
2628
mux.Use(RequestLogger(logger))
2729
mux.Use(cors.Handler(cors.Options{

apps/uno/http/routes/api/comment.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ func NewCommentMux(logger port.Logger, commentService *service.CommentService, a
4444
// @Router /comments/{id} [get]
4545
func (c *comments) GetCommentsByIDHandler(ctx *handler.Context) error {
4646
id := ctx.PathValue("id")
47-
if id == "" {
48-
return ctx.Error(errMissingId, http.StatusBadRequest)
49-
}
5047

5148
comments, err := c.commentService.CommentRepo().GetCommentsByID(ctx.Context(), id)
5249
if err != nil {
@@ -98,9 +95,6 @@ func (c *comments) CreateCommentHandler(ctx *handler.Context) error {
9895
// @Router /comments/{id}/reaction [post]
9996
func (c *comments) ReactToCommentHandler(ctx *handler.Context) error {
10097
commentID := ctx.PathValue("id")
101-
if commentID == "" {
102-
return ctx.Error(errMissingId, http.StatusBadRequest)
103-
}
10498

10599
var req dto.ReactToCommentRequest
106100
if err := ctx.ReadJSON(&req); err != nil {

apps/uno/http/routes/api/comment_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,6 @@ func TestReactToCommentHandler(t *testing.T) {
184184
expectedStatus: http.StatusOK,
185185
expectError: false,
186186
},
187-
{
188-
name: "missing comment id",
189-
commentID: "",
190-
requestBody: dto.ReactToCommentRequest{},
191-
setupMocks: func(mockRepo *mocks.CommentRepo) {},
192-
expectedStatus: http.StatusBadRequest,
193-
expectError: false,
194-
},
195187
{
196188
name: "invalid json",
197189
commentID: "comment123",

apps/uno/http/routes/api/degree.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ func (d *degrees) UpdateDegreeHandler(ctx *handler.Context) error {
125125
// @Router /degrees/{id} [delete]
126126
func (d *degrees) DeleteDegreeHandler(ctx *handler.Context) error {
127127
id := ctx.PathValue("id")
128-
if id == "" {
129-
return ctx.Error(errors.New("missing id parameter"), http.StatusBadRequest)
130-
}
131128

132129
if err := d.degreeService.DegreeRepo().DeleteDegree(ctx.Context(), id); err != nil {
133130
return ctx.Error(ErrInternalServer, http.StatusInternalServerError)

apps/uno/http/routes/api/happening.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ func (h *happenings) GetHappeningsHandler(ctx *handler.Context) error {
6868
func (h *happenings) GetHappeningById(ctx *handler.Context) error {
6969
// Extract the happening ID from the URL path
7070
id := ctx.PathValue("id")
71-
if id == "" {
72-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
73-
}
7471

7572
// Fetch the happening from the repository
7673
hap, err := h.happeningService.HappeningRepo().GetHappeningById(ctx.Context(), id)
@@ -97,9 +94,6 @@ func (h *happenings) GetHappeningById(ctx *handler.Context) error {
9794
func (h *happenings) GetHappeningRegistrationsCount(ctx *handler.Context) error {
9895
// Extract the happening ID from the URL path
9996
id := ctx.PathValue("id")
100-
if id == "" {
101-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
102-
}
10397

10498
// Fetch the happening from the repository
10599
hap, err := h.happeningService.HappeningRepo().GetHappeningById(ctx.Context(), id)
@@ -187,9 +181,6 @@ func (h *happenings) GetHappeningRegistrationsCountMany(ctx *handler.Context) er
187181
func (h *happenings) GetHappeningRegistrations(ctx *handler.Context) error {
188182
// Extract the happening ID from the URL path
189183
id := ctx.PathValue("id")
190-
if id == "" {
191-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
192-
}
193184

194185
// Fetch the registrations from the repository
195186
regs, err := h.happeningService.HappeningRepo().GetHappeningRegistrations(ctx.Context(), id)
@@ -216,9 +207,6 @@ func (h *happenings) GetHappeningRegistrations(ctx *handler.Context) error {
216207
func (h *happenings) GetHappeningSpotRanges(ctx *handler.Context) error {
217208
// Extract the happening ID from the URL path
218209
id := ctx.PathValue("id")
219-
if id == "" {
220-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
221-
}
222210

223211
// Fetch the spot ranges from the repository
224212
ranges, err := h.happeningService.HappeningRepo().GetHappeningSpotRanges(ctx.Context(), id)
@@ -244,9 +232,6 @@ func (h *happenings) GetHappeningSpotRanges(ctx *handler.Context) error {
244232
func (h *happenings) GetHappeningQuestions(ctx *handler.Context) error {
245233
// Extract the happening ID from the URL path
246234
id := ctx.PathValue("id")
247-
if id == "" {
248-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
249-
}
250235

251236
// Fetch the questions from the repository
252237
qs, err := h.happeningService.HappeningRepo().GetHappeningQuestions(ctx.Context(), id)
@@ -275,9 +260,6 @@ func (h *happenings) GetHappeningQuestions(ctx *handler.Context) error {
275260
func (h *happenings) RegisterForHappening(ctx *handler.Context) error {
276261
// Extract the happening ID from the URL path
277262
happeningID := ctx.PathValue("id")
278-
if happeningID == "" {
279-
return ctx.Error(fmt.Errorf("missing happening id"), http.StatusBadRequest)
280-
}
281263

282264
// Parse request DTO
283265
var req dto.RegisterForHappeningRequest

apps/uno/http/routes/api/happening_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ func TestGetHappeningById(t *testing.T) {
106106
expectedStatus: http.StatusOK,
107107
expectError: false,
108108
},
109-
{
110-
name: "missing id",
111-
happeningID: "",
112-
setupMocks: func(mockRepo *mocks.HappeningRepo) {
113-
// When ID is empty, route "/" matches GetHappeningsHandler
114-
mockRepo.EXPECT().
115-
GetAllHappenings(mock.Anything).
116-
Return([]model.Happening{}, nil).
117-
Once()
118-
},
119-
expectedStatus: http.StatusOK, // Gets all happenings instead
120-
expectError: false,
121-
},
122109
{
123110
name: "not found",
124111
happeningID: "happening123",
@@ -185,13 +172,6 @@ func TestGetHappeningQuestions(t *testing.T) {
185172
expectedStatus: http.StatusOK,
186173
expectError: false,
187174
},
188-
{
189-
name: "missing id",
190-
happeningID: "",
191-
setupMocks: func(mockRepo *mocks.HappeningRepo) {},
192-
expectedStatus: http.StatusBadRequest, // 400 - handler validates missing ID
193-
expectError: false,
194-
},
195175
{
196176
name: "error from repo",
197177
happeningID: "happening123",
@@ -311,18 +291,6 @@ func TestRegisterForHappening(t *testing.T) {
311291
expectedStatus: http.StatusOK,
312292
expectError: false,
313293
},
314-
{
315-
name: "missing happening id",
316-
happeningID: "",
317-
requestBody: dto.RegisterForHappeningRequest{
318-
UserID: "user123",
319-
Questions: []dto.QuestionAnswerDTO{},
320-
},
321-
setupMocks: func(mockHappeningRepo *mocks.HappeningRepo, mockUserRepo *mocks.UserRepo, mockRegistrationRepo *mocks.RegistrationRepo, mockBanInfoRepo *mocks.BanInfoRepo) {
322-
},
323-
expectedStatus: http.StatusBadRequest,
324-
expectError: true,
325-
},
326294
{
327295
name: "invalid json",
328296
happeningID: "happening123",

apps/uno/http/routes/api/site_feedback.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func (f *feedbacks) GetSiteFeedbacksHandler(ctx *handler.Context) error {
5959
func (f *feedbacks) GetSiteFeedbackByIDHandler(ctx *handler.Context) error {
6060
// Get the feedback ID from the path
6161
feedbackID := ctx.PathValue("id")
62-
if feedbackID == "" {
63-
return ctx.Error(errors.New("missing site feedback id"), http.StatusBadRequest)
64-
}
6562

6663
// Fetch feedback with the given ID from the repository
6764
feedback, err := f.feedbackService.SiteFeedbackRepo().GetSiteFeedbackByID(ctx.Context(), feedbackID)

apps/uno/http/routes/api/whitelist.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

33
import (
4-
"errors"
54
"net/http"
65
"uno/domain/port"
76
"uno/domain/service"
@@ -62,9 +61,7 @@ func (w *whitelist) GetWhitelistHandler(ctx *handler.Context) error {
6261
// @Router /whitelist/{email} [get]
6362
func (w *whitelist) GetWhitelistByEmailHandler(ctx *handler.Context) error {
6463
email := ctx.PathValue("email")
65-
if email == "" {
66-
return ctx.Error(errors.New("missing email"), http.StatusBadRequest)
67-
}
64+
6865
// Get domain model from service
6966
whitelistInfo, err := w.whitelistService.WhitelistRepo().GetWhitelistByEmail(ctx.Context(), email)
7067
if err != nil {

0 commit comments

Comments
 (0)