Skip to content

Commit 8571225

Browse files
committed
fix team api
1 parent b125d58 commit 8571225

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

internal/app/db/team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ type Team struct {
66
Id openapi_types.UUID `db:"id"`
77
Name string `db:"name"`
88
Description string `db:"description"`
9-
UniversityId int `db:"university_id"`
10-
University string
9+
UniversityId *int `db:"university_id"`
10+
University *string
1111
SocialLinks string `db:"social_links"`
1212
AvatarUrl string `db:"avatar_url"`
1313
}

internal/app/handlers/teams.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (h *Handlers) CreateTeam(w http.ResponseWriter, r *http.Request) {
2727
Name: team.Name,
2828
SocialLinks: *team.SocialLinks,
2929
Description: *team.Description,
30-
UniversityId: team.UniversityId,
30+
UniversityId: &team.UniversityId,
3131
AvatarUrl: api_helpers.PrepareImage(*team.AvatarUrl),
3232
}
3333
if err := teamRepo.Create(r.Context(), newTeam); err != nil {
@@ -82,7 +82,7 @@ func (h *Handlers) UpdateTeam(w http.ResponseWriter, r *http.Request, id openapi
8282
Name: team.Name,
8383
SocialLinks: *team.SocialLinks,
8484
Description: *team.Description,
85-
UniversityId: team.UniversityId,
85+
UniversityId: &team.UniversityId,
8686
AvatarUrl: *team.AvatarUrl,
8787
}
8888
updateTeam.Id = id

internal/app/repository/team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (r *teamRepo) Delete(ctx context.Context, id openapi_types.UUID) error {
5656
}
5757

5858
func (r *teamRepo) List(ctx context.Context) ([]*models.Team, error) {
59-
query := "SELECT t.*, u.name as university_name FROM teams t JOIN universities u ON t.university_id = u.id"
59+
query := "SELECT t.*, u.name as university_name FROM teams t LEFT JOIN universities u ON t.university_id = u.id"
6060
rows, err := r.db.QueryContext(ctx, query)
6161
if err != nil {
6262
return nil, err
@@ -66,7 +66,7 @@ func (r *teamRepo) List(ctx context.Context) ([]*models.Team, error) {
6666
var teams []*models.Team
6767
for rows.Next() {
6868
var team models.Team
69-
if err := rows.Scan(&team.Id, &team.Name, &team.Description, &team.UniversityId, &team.SocialLinks, &team.AvatarUrl, &team.University); err != nil {
69+
if err := rows.Scan(&team.Name, &team.Description, &team.SocialLinks, &team.AvatarUrl, &team.Id, &team.UniversityId, &team.University); err != nil {
7070
return nil, err
7171
}
7272
teams = append(teams, &team)

internal/app/view/team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func NewTeamFromModel(t *db.Team) *server.TeamResponse {
1010
Id: t.Id,
1111
Name: t.Name,
1212
Description: &t.Description,
13-
University: &t.University,
13+
University: t.University,
1414
SocialLinks: &t.SocialLinks,
1515
AvatarUrl: &t.AvatarUrl,
1616
}

0 commit comments

Comments
 (0)