Skip to content

Commit

Permalink
pointer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed May 27, 2024
1 parent 19084bc commit ee4e068
Show file tree
Hide file tree
Showing 29 changed files with 99 additions and 70 deletions.
4 changes: 2 additions & 2 deletions external/v3/action-log/action_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewActionLogEntryListResponse(ale []models.ActionLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, a := range ale {
list = append(list, NewActionLogEntryResponse(&a))
for idx := range ale {
list = append(list, NewActionLogEntryResponse(&ale[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/disciplinary-log/disciplinary_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewDisciplinaryLogEntryListResponse(dle []models.DisciplinaryLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, d := range dle {
list = append(list, NewDisciplinaryLogEntryResponse(&d))
for idx := range dle {
list = append(list, NewDisciplinaryLogEntryResponse(&dle[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/facility-log/facility_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFacilityLogEntryListResponse(fle []models.FacilityLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, f := range fle {
list = append(list, NewFacilityLogEntryResponse(&f))
for idx := range fle {
list = append(list, NewFacilityLogEntryResponse(&fle[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/facility/facility.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFacilityListResponse(facilities []models.Facility) []render.Renderer {
list := []render.Renderer{}
for _, facility := range facilities {
list = append(list, NewFacilityResponse(&facility))
for idx := range facilities {
list = append(list, NewFacilityResponse(&facilities[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/faq/faq.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFAQListResponse(faqs []models.FAQ) []render.Renderer {
list := []render.Renderer{}
for _, f := range faqs {
list = append(list, NewFAQResponse(&f))
for idx := range faqs {
list = append(list, NewFAQResponse(&faqs[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions external/v3/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewFeedbackListResponse(f []models.Feedback) []render.Renderer {
func NewFeedbackListResponse(feedback []models.Feedback) []render.Renderer {
list := []render.Renderer{}
for _, d := range f {
list = append(list, NewFeedbackResponse(&d))
for idx := range feedback {
list = append(list, NewFeedbackResponse(&feedback[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/news/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewNewsListResponse(news []models.News) []render.Renderer {
list := []render.Renderer{}
for _, n := range news {
list = append(list, NewNewsResponse(&n))
for idx := range news {
list = append(list, NewNewsResponse(&news[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions external/v3/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewNotificationListResponse(n []models.Notification) []render.Renderer {
func NewNotificationListResponse(notifications []models.Notification) []render.Renderer {
list := []render.Renderer{}
for _, d := range n {
list = append(list, NewNotificationResponse(&d))
for idx := range notifications {
list = append(list, NewNotificationResponse(&notifications[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions external/v3/rating-change/rating_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewRatingChangeListResponse(rc []models.RatingChange) []render.Renderer {
list := []render.Renderer{}
for _, d := range rc {
list = append(list, NewRatingChangeResponse(&d))
for idx := range rc {
list = append(list, NewRatingChangeResponse(&rc[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions external/v3/roster-request/roster_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewRosterRequestListResponse(r []models.RosterRequest) []render.Renderer {
func NewRosterRequestListResponse(rosterReq []models.RosterRequest) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewRosterRequestResponse(&d))
for idx := range rosterReq {
list = append(list, NewRosterRequestResponse(&rosterReq[idx]))
}
return list
}
Expand Down
32 changes: 29 additions & 3 deletions external/v3/roster/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewRosterListResponse(r []models.Roster) []render.Renderer {
func NewRosterListResponse(rosters []models.Roster) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewRosterResponse(&d))
for idx := range rosters {
list = append(list, NewRosterResponse(&rosters[idx]))
}

return list
Expand Down Expand Up @@ -175,3 +175,29 @@ func DeleteRoster(w http.ResponseWriter, r *http.Request) {

render.Status(r, http.StatusNoContent)
}

// GetUserRosters godoc
// @Summary Get rosters by user
// @Description Get rosters by user
// @Tags roster
// @Accept json
// @Produce json
// @Param cid path int true "CID"
// @Success 200 {object} []Response
// @Failure 400 {object} utils.ErrResponse
// @Failure 500 {object} utils.ErrResponse
// @Router /user/{cid}/roster [get]
func GetUserRosters(w http.ResponseWriter, r *http.Request) {
user := utils.GetUserCtx(r)

rosters, err := models.GetRostersByCID(user.CID)
if err != nil {
utils.Render(w, r, utils.ErrInternalServer)
return
}

if err := render.RenderList(w, r, NewRosterListResponse(rosters)); err != nil {
utils.Render(w, r, utils.ErrRender(err))
return
}
}
6 changes: 3 additions & 3 deletions external/v3/user-flag/user_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewUserFlagListResponse(r []models.UserFlag) []render.Renderer {
func NewUserFlagListResponse(userFlags []models.UserFlag) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewUserFlagResponse(&d))
for idx := range userFlags {
list = append(list, NewUserFlagResponse(&userFlags[idx]))
}

return list
Expand Down
12 changes: 6 additions & 6 deletions external/v3/user-role/user-role.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewUserListResponse(resp []Response) []render.Renderer {
func NewUserRoleListResponse(userRoles []models.UserRole) []render.Renderer {
list := []render.Renderer{}
for _, userRole := range resp {
list = append(list, &userRole)
for idx := range userRoles {
list = append(list, NewUserRoleResponse(userRoles[idx].RoleID, userRoles[idx].FacilityID, userRoles[idx].CreatedAt))
}
return list
}
Expand All @@ -77,14 +77,14 @@ func NewUserListResponse(resp []Response) []render.Renderer {
func GetSelfRoles(w http.ResponseWriter, r *http.Request) {
user := middleware.GetSelfUser(r)

roles := []Response{}
roles := []models.UserRole{}
for _, roster := range user.Roster {
for _, role := range roster.Roles {
roles = append(roles, *NewUserRoleResponse(role.RoleID, roster.Facility, role.CreatedAt))
roles = append(roles, role)
}
}

if err := render.RenderList(w, r, NewUserListResponse(roles)); err != nil {
if err := render.RenderList(w, r, NewUserRoleListResponse(roles)); err != nil {
utils.Render(w, r, utils.ErrInternalServer)
}
}
Expand Down
3 changes: 3 additions & 0 deletions external/v3/user/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package user

import (
"context"
"github.com/VATUSA/primary-api/external/v3/roster"
"github.com/VATUSA/primary-api/pkg/database/models"
"github.com/VATUSA/primary-api/pkg/go-chi/middleware/auth"
"github.com/VATUSA/primary-api/pkg/utils"
Expand All @@ -19,6 +20,8 @@ func Router(r chi.Router) {
r.With(middleware.CanViewUser).Get("/", GetUser)
r.With(middleware.CanEditUser).Put("/", UpdateUser)
r.With(middleware.CanEditUser).Patch("/", PatchUser)

r.With(middleware.CanViewUser).Get("/roster", roster.GetUserRosters)
})
}

Expand Down
4 changes: 2 additions & 2 deletions external/v3/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewUserListResponse(users []models.User) []render.Renderer {
list := []render.Renderer{}
for _, user := range users {
list = append(list, NewUserResponse(&user))
for idx := range users {
list = append(list, NewUserResponse(&users[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/action-log/action_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewActionLogEntryListResponse(ale []models.ActionLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, a := range ale {
list = append(list, NewActionLogEntryResponse(&a))
for idx := range ale {
list = append(list, NewActionLogEntryResponse(&ale[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/disciplinary-log/disciplinary_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewDisciplinaryLogEntryListResponse(dle []models.DisciplinaryLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, d := range dle {
list = append(list, NewDisciplinaryLogEntryResponse(&d))
for idx := range dle {
list = append(list, NewDisciplinaryLogEntryResponse(&dle[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions internal/v1/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewDocumentListResponse(d []models.Document) []render.Renderer {
func NewDocumentListResponse(docs []models.Document) []render.Renderer {
list := []render.Renderer{}
for _, doc := range d {
list = append(list, NewDocumentResponse(&doc))
for idx := range docs {
list = append(list, NewDocumentResponse(&docs[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/facility-log/facility_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFacilityLogEntryListResponse(fle []models.FacilityLogEntry) []render.Renderer {
list := []render.Renderer{}
for _, f := range fle {
list = append(list, NewFacilityLogEntryResponse(&f))
for idx := range fle {
list = append(list, NewFacilityLogEntryResponse(&fle[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/faq/faq.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFAQListResponse(faqs []models.FAQ) []render.Renderer {
list := []render.Renderer{}
for _, f := range faqs {
list = append(list, NewFAQResponse(&f))
for idx := range faqs {
list = append(list, NewFAQResponse(&faqs[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewFeedbackListResponse(f []models.Feedback) []render.Renderer {
list := []render.Renderer{}
for _, d := range f {
list = append(list, NewFeedbackResponse(&d))
for idx := range f {
list = append(list, NewFeedbackResponse(&f[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/news/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewNewsListResponse(news []models.News) []render.Renderer {
list := []render.Renderer{}
for _, n := range news {
list = append(list, NewNewsResponse(&n))
for idx := range news {
list = append(list, NewNewsResponse(&news[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewNotificationListResponse(n []models.Notification) []render.Renderer {
list := []render.Renderer{}
for _, d := range n {
list = append(list, NewNotificationResponse(&d))
for idx := range n {
list = append(list, NewNotificationResponse(&n[idx]))
}
return list
}
Expand Down
4 changes: 2 additions & 2 deletions internal/v1/rating-change/rating_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {

func NewRatingChangeListResponse(rc []models.RatingChange) []render.Renderer {
list := []render.Renderer{}
for _, d := range rc {
list = append(list, NewRatingChangeResponse(&d))
for idx := range rc {
list = append(list, NewRatingChangeResponse(&rc[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions internal/v1/roster-request/roster_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewRosterRequestListResponse(r []models.RosterRequest) []render.Renderer {
func NewRosterRequestListResponse(rosterRequests []models.RosterRequest) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewRosterRequestResponse(&d))
for idx := range rosterRequests {
list = append(list, NewRosterRequestResponse(&rosterRequests[idx]))
}
return list
}
Expand Down
6 changes: 3 additions & 3 deletions internal/v1/roster/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewRosterListResponse(r []models.Roster) []render.Renderer {
func NewRosterListResponse(rosters []models.Roster) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewRosterResponse(&d))
for idx := range rosters {
list = append(list, NewRosterResponse(&rosters[idx]))
}

return list
Expand Down
6 changes: 3 additions & 3 deletions internal/v1/user-flag/user_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewUserFlagListResponse(r []models.UserFlag) []render.Renderer {
func NewUserFlagListResponse(userFlags []models.UserFlag) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewUserFlagResponse(&d))
for idx := range userFlags {
list = append(list, NewUserFlagResponse(&userFlags[idx]))
}

return list
Expand Down
6 changes: 3 additions & 3 deletions internal/v1/user-role/user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (res *Response) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}

func NewUserRoleListResponse(r []models.UserRole) []render.Renderer {
func NewUserRoleListResponse(userRoles []models.UserRole) []render.Renderer {
list := []render.Renderer{}
for _, d := range r {
list = append(list, NewUserRoleResponse(&d))
for idx := range userRoles {
list = append(list, NewUserRoleResponse(&userRoles[idx]))
}
return list
}
Expand Down
Loading

0 comments on commit ee4e068

Please sign in to comment.