Skip to content

Commit b17d02f

Browse files
committed
Add user event response
1 parent 1ac5079 commit b17d02f

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func main() {
8585
&models.UserTag{},
8686
&models.Tag{},
8787
&models.ThirdPartyIdentity{},
88+
&models.VolunteeringHourLog{},
8889
)
8990
if err != nil {
9091
// Error migrating the database, panic.

internal/events/service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ func (s *service) GetUserEvents(ctx context.Context, userID int64) ([]EventView,
312312
}
313313
view.EventResponsesSummary = responsesSummary
314314

315+
response, err := s.GetUserEventResponse(ctx, userID, event.ID)
316+
if err == nil {
317+
view.UserResponse = response
318+
}
319+
315320
views = append(views, *view)
316321
}
317322

internal/events/view.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package events
33
import (
44
"time"
55

6+
"github.com/joinimpact/api/internal/models"
67
"github.com/joinimpact/api/pkg/location"
78
)
89

@@ -23,6 +24,7 @@ type EventView struct {
2324
EventBase `validate:"dive"`
2425
EventSchedule *EventSchedule `json:"schedule"`
2526
EventResponsesSummary *EventResponsesSummary `json:"responses,omitempty" scope:"manager"`
27+
UserResponse *models.EventResponse `json:"userResponse,omitempty"`
2628
Location *location.Location `json:"location"`
2729
}
2830

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package models
2+
3+
import "context"
4+
5+
// VolunteeringHourLog represents a log of a volunteer's verified hours.
6+
type VolunteeringHourLog struct {
7+
Model
8+
OpportunityID int64 `json:"opportunityId"`
9+
Opportunity Opportunity `json:"-" gorm:"foreignkey:OpportunityID"`
10+
VolunteerID int64 `json:"volunteerId"`
11+
Volunteer User `json:"-" gorm:"foreignkey:VolunteerID"`
12+
GranterID int64 `json:"granterId"`
13+
Granter User `json:"-" gorm:"foreignkey:GranterID"`
14+
GrantedHours float32 `json:"grantedHours"`
15+
}
16+
17+
// VolunteeringHourLogsResponse wraps an array of VolunteeringHourLogs and contains information from the database.
18+
type VolunteeringHourLogsResponse struct {
19+
VolunteeringHourLogs []VolunteeringHourLog
20+
TotalResults int
21+
}
22+
23+
// VolunteeringHourLogRepository represents a repository of VolunteeringHourLog entities.
24+
type VolunteeringHourLogRepository interface {
25+
// FindByID finds a single entity by ID.
26+
FindByID(ctx context.Context, id int64) (*VolunteeringHourLog, error)
27+
// FindByOpportunityID finds multiple entities by the opportunity ID.
28+
FindByOpportunityID(ctx context.Context, opportunityID int64) (*VolunteeringHourLogsResponse, error)
29+
// FindByOpportunityIDs finds multiple entities by multiple opportunity IDs.
30+
FindByOpportunityIDs(ctx context.Context, opportunityIDs []int64) ([]Event, error)
31+
// FindByCreatorID finds multiple entities by the creator ID.
32+
FindByCreatorID(ctx context.Context, creatorID int64) ([]Event, error)
33+
// Create creates a new entity.
34+
Create(ctx context.Context, event Event) error
35+
// Update updates an entity with the ID in the provided entity.
36+
Update(ctx context.Context, event Event) error
37+
// DeleteByID deletes an entity by ID.
38+
DeleteByID(ctx context.Context, id int64) error
39+
}

server

3.92 KB
Binary file not shown.

0 commit comments

Comments
 (0)