Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 46 additions & 41 deletions backend/internal/handlers/college/college_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package college
import (
"context"
"fmt"
"inside-athletics/internal/s3"
models "inside-athletics/internal/models"
"inside-athletics/internal/s3"
"inside-athletics/internal/utils"
)

Expand Down Expand Up @@ -34,14 +34,15 @@ func (u *CollegeService) GetCollege(ctx context.Context, input *GetCollegeParams
}

response := &GetCollegeResponse{
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AthleticsWebsite: college.AthleticsWebsite,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
}

return &utils.ResponseBody[GetCollegeResponse]{
Expand All @@ -60,14 +61,15 @@ func (u *CollegeService) ListColleges(ctx context.Context, input *ListCollegesPa
responseColleges := make([]GetCollegeResponse, 0, len(*colleges))
for _, college := range *colleges {
responseColleges = append(responseColleges, GetCollegeResponse{
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(college.Logo),
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AthleticsWebsite: college.AthleticsWebsite,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(college.Logo),
})
}

Expand Down Expand Up @@ -101,14 +103,15 @@ func (u *CollegeService) CreateCollege(ctx context.Context, input *CreateCollege
}

response := &CreateCollegeResponse{
ID: createdCollege.ID,
Name: createdCollege.Name,
State: createdCollege.State,
City: createdCollege.City,
Website: createdCollege.Website,
AcademicRank: createdCollege.AcademicRank,
DivisionRank: createdCollege.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, createdCollege.Logo)),
ID: createdCollege.ID,
Name: createdCollege.Name,
State: createdCollege.State,
City: createdCollege.City,
Website: createdCollege.Website,
AthleticsWebsite: createdCollege.AthleticsWebsite,
AcademicRank: createdCollege.AcademicRank,
DivisionRank: createdCollege.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, createdCollege.Logo)),
}

return &utils.ResponseBody[CreateCollegeResponse]{
Expand All @@ -128,14 +131,15 @@ func (u *CollegeService) UpdateCollege(ctx context.Context, input *UpdateCollege
}

response := &UpdateCollegeResponse{
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AthleticsWebsite: college.AthleticsWebsite,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
}

return &utils.ResponseBody[UpdateCollegeResponse]{
Expand Down Expand Up @@ -166,14 +170,15 @@ func (u *CollegeService) DeleteCollege(ctx context.Context, input *DeleteCollege
func (u *CollegeService) FuzzySearchForCollege(ctx context.Context, input *utils.SearchParam) (*utils.ResponseBody[utils.SearchResults[*GetCollegeResponse]], error) {
toResponse := func(college *models.College) *GetCollegeResponse {
return &GetCollegeResponse{
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
ID: college.ID,
Name: college.Name,
State: college.State,
City: college.City,
Website: college.Website,
AthleticsWebsite: college.AthleticsWebsite,
AcademicRank: college.AcademicRank,
DivisionRank: college.DivisionRank,
Logo: StringPtrOrNil(s3.ResolveKey(ctx, u.s3, college.Logo)),
}
}
return utils.FuzzySearchService(input, models.College{}, GetCollegeResponse{}, "name", u.collegeDB.db, toResponse)
Expand Down
85 changes: 45 additions & 40 deletions backend/internal/handlers/college/college_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ type ListCollegesParams struct {
}

type GetCollegeResponse struct {
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" example:"Boston" doc:"City of the college"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" example:"Boston" doc:"City of the college"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"Website of the college"`
AthleticsWebsite string `json:"athletics_website" example:"https://www.northeastern.edu" doc:"Website of the colleges athletics information"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
}

type ListCollegesResponse struct {
Expand All @@ -32,38 +33,41 @@ type ListCollegesResponse struct {
}

type CreateCollegeRequest struct {
Name string `json:"name" required:"true" minLength:"1" maxLength:"200" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" required:"true" minLength:"1" maxLength:"100" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" required:"true" minLength:"1" maxLength:"100" example:"Boston" doc:"City of the college"`
Website string `json:"website" required:"true" minLength:"1" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" required:"true" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" maxLength:"500" example:"https://example.com/logo.png" doc:"Logo of the college"`
Name string `json:"name" required:"true" minLength:"1" maxLength:"200" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" required:"true" minLength:"1" maxLength:"100" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" required:"true" minLength:"1" maxLength:"100" example:"Boston" doc:"City of the college"`
Website string `json:"website" required:"true" minLength:"1" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the college"`
AthleticsWebsite string `json:"athletics_website" required:"true" example:"https://www.northeastern.edu" doc:"Website of the colleges athletics information"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" required:"true" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" maxLength:"500" example:"https://example.com/logo.png" doc:"Logo of the college"`
}

type CreateCollegeResponse struct {
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" example:"Boston" doc:"City of the college"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" example:"1" enum:"1,2,3" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" example:"Boston" doc:"City of the college"`
AthleticsWebsite string `json:"athletics_website" example:"https://www.northeastern.edu" doc:"Website of the colleges athletics information"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" example:"1" enum:"1,2,3" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
}

type CreateCollegeInput struct {
Body CreateCollegeRequest
}

type UpdateCollegeRequest struct {
Name *string `json:"name" maxLength:"200" example:"Northeastern University" doc:"Name of the college"`
State *string `json:"state" maxLength:"100" example:"Massachusetts" doc:"State of the college"`
City *string `json:"city" maxLength:"100" example:"Boston" doc:"City of the college"`
Website *string `json:"website" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank *models.Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" maxLength:"500" example:"https://example.com/logo.png" doc:"Logo of the college"`
Name *string `json:"name" maxLength:"200" example:"Northeastern University" doc:"Name of the college"`
State *string `json:"state" maxLength:"100" example:"Massachusetts" doc:"State of the college"`
City *string `json:"city" maxLength:"100" example:"Boston" doc:"City of the college"`
Website *string `json:"website" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the college"`
AthleticsWebsite *string `json:"athletics_website" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the colleges athletics information"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank *models.Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" maxLength:"500" example:"https://example.com/logo.png" doc:"Logo of the college"`
}

// Combined input for Update (path params + body)
Expand All @@ -73,14 +77,15 @@ type UpdateCollegeInput struct {
}

type UpdateCollegeResponse struct {
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" required:"true" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" required:"true" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" required:"true" example:"Boston" doc:"City of the college"`
Website string `json:"website" required:"true" example:"https://www.northeastern.edu" doc:"Website of the college"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" required:"true" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
ID uuid.UUID `json:"id" example:"550e8400-e29b-41d4-a716-446655440000" doc:"ID of the college"`
Name string `json:"name" required:"true" example:"Northeastern University" doc:"Name of the college"`
State string `json:"state" required:"true" example:"Massachusetts" doc:"State of the college"`
City string `json:"city" required:"true" example:"Boston" doc:"City of the college"`
Website string `json:"website" required:"true" example:"https://www.northeastern.edu" doc:"Website of the college"`
AthleticsWebsite string `json:"athletics_website" required:"true" maxLength:"500" example:"https://www.northeastern.edu" doc:"Website of the colleges athletics information"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"Academic rank of the college"`
DivisionRank models.Division `json:"division_rank" required:"true" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)"`
Logo *string `json:"logo" example:"https://example.com/logo.png" doc:"Logo of the college"`
}

type DeleteCollegeParams struct {
Expand All @@ -93,5 +98,5 @@ type DeleteCollegeResponse struct {
}

type GetAllCollegesResponse struct {
Colleges []GetCollegeResponse `json:"colleges"`
}
Colleges []GetCollegeResponse `json:"colleges"`
}
22 changes: 22 additions & 0 deletions backend/internal/models/athlete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models

import (
"time"

"github.com/google/uuid"
)

type Athlete struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`

// useful meta-data
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `sql:"index" json:"deleted_at"`

Name string `json:"name" example:"Suli Rashidzada" doc:"The name of an athlete" gorm:"type:varchar(200);not null"`
SportID *uuid.UUID `json:"sport_id" gorm:"type:uuid;default:null"`
Sport *Sport `json:"-" gorm:"foreignKey:SportID;references:ID;constraint:OnDelete:SET NULL;"`
CollegeID *uuid.UUID `json:"college_id" gorm:"type:uuid;default:null"`
College *College `json:"-" gorm:"foreignKey:CollegeID;references:ID;constraint:OnDelete:SET NULL;"`
}
13 changes: 7 additions & 6 deletions backend/internal/models/college.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ type College struct {
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `sql:"index" json:"deleted_at"`

Name string `json:"name" example:"Northeastern University" doc:"The name of a college" gorm:"type:varchar(200);not null"`
State string `json:"state" example:"Massachusetts" doc:"The state of the college" gorm:"type:varchar(100);not null"`
City string `json:"city" example:"Boston" doc:"The city of the college" gorm:"type:varchar(100);not null"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"The website of the college" gorm:"type:varchar(500);not null"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"The academic rank of the college" gorm:"type:smallint"`
DivisionRank Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)" gorm:"type:uint;not null"`
Name string `json:"name" example:"Northeastern University" doc:"The name of a college" gorm:"type:varchar(200);not null"`
State string `json:"state" example:"Massachusetts" doc:"The state of the college" gorm:"type:varchar(100);not null"`
City string `json:"city" example:"Boston" doc:"The city of the college" gorm:"type:varchar(100);not null"`
Website string `json:"website" example:"https://www.northeastern.edu" doc:"The website of the college" gorm:"type:varchar(500);not null"`
AthleticsWebsite string `json:"athletics_website" example:"https://www.northeastern.edu" doc:"The website for the college athletic website" gorm:"type:varchar(500);not null"`
AcademicRank *int16 `json:"academic_rank" example:"53" doc:"The academic rank of the college" gorm:"type:smallint"`
DivisionRank Division `json:"division_rank" enum:"1,2,3" example:"1" doc:"NCAA division (1, 2, or 3)" gorm:"type:uint;not null"`

// Stores the S3 Key of the image.
Logo string `json:"logo" doc:"The S3 key for the logo of the college" gorm:"type:varchar(500)"`
Expand Down
Loading
Loading