Skip to content

Commit

Permalink
Merge pull request #22 from geekcamp-vol11-team30/feature/EventNotify…
Browse files Browse the repository at this point in the history
…Reservation

予約確定機能
  • Loading branch information
TAK848 authored Sep 23, 2023
2 parents 3e88cde + 085b24d commit ea04cf7
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 107 deletions.
13 changes: 8 additions & 5 deletions controller/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ func eventRequestToEvent(er entity.EventRequest) entity.Event {
}
}
return entity.Event{
Name: er.Name,
Description: er.Description,
DurationAbout: er.DurationAbout,
UnitSeconds: er.UnitSeconds,
Units: units,
Name: er.Name,
Description: er.Description,
DurationAbout: er.DurationAbout,
UnitSeconds: er.UnitSeconds,
Units: units,
NotifyByEmail: er.NotifyByEmail,
NumberOfParticipants: er.NumberOfParticipants,
ConfirmationEmail: er.ConfirmationEmail,
}
}

Expand Down
15 changes: 15 additions & 0 deletions db/migrations/20230923042107_add_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query';
ALTER TABLE `event`
ADD COLUMN `enables_email_notification` BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN `expected_participants_number` INT NOT NULL DEFAULT 0,
ADD COLUMN `notification_email` VARCHAR(255) NOT NULL DEFAULT '';
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query';
ALTER TABLE `event` DROP COLUMN `enables_email_notification`,
DROP COLUMN `expected_participants_number`,
DROP COLUMN `notification_email`;
-- +goose StatementEnd
32 changes: 19 additions & 13 deletions entity/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ import (
)

type Event struct {
ID ulid.ULID `json:"id"`
OwnerID ulid.ULID `json:"ownerId"`
Name string `json:"name"`
Description string `json:"description"`
DurationAbout string `json:"durationAbout"`
UnitSeconds int `json:"unitSeconds"`
Units []EventTimeUnit `json:"units"`
UserAnswers []UserEventAnswer `json:"userAnswers"`
ID ulid.ULID `json:"id"`
OwnerID ulid.ULID `json:"ownerId"`
Name string `json:"name"`
Description string `json:"description"`
DurationAbout string `json:"durationAbout"`
UnitSeconds int `json:"unitSeconds"`
Units []EventTimeUnit `json:"units"`
UserAnswers []UserEventAnswer `json:"userAnswers"`
NotifyByEmail bool `json:"enablesEmailNotification"`
NumberOfParticipants int `json:"expectedParticipantsNumber"`
ConfirmationEmail string `json:"notificationEmail"`
}
type EventRequest struct {
Name string `json:"name"`
Description string `json:"description"`
DurationAbout string `json:"durationAbout"`
UnitSeconds int `json:"unitDuration"`
Units []EventTimeUnitRequest `json:"units"`
Name string `json:"name"`
Description string `json:"description"`
DurationAbout string `json:"durationAbout"`
UnitSeconds int `json:"unitDuration"`
Units []EventTimeUnitRequest `json:"units"`
NotifyByEmail bool `json:"enablesEmailNotification"`
NumberOfParticipants int `json:"expectedParticipantsNumber"`
ConfirmationEmail string `json:"notificationEmail"`
}
type EventResponse struct {
ID string `json:"id"`
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/geekcamp-vol11-team30/backend/router"
"github.com/geekcamp-vol11-team30/backend/service"
"github.com/geekcamp-vol11-team30/backend/usecase"
"github.com/geekcamp-vol11-team30/backend/util"
"github.com/geekcamp-vol11-team30/backend/validator"
_ "github.com/go-sql-driver/mysql"
"github.com/volatiletech/sqlboiler/v4/boil"
Expand Down Expand Up @@ -53,7 +52,7 @@ func run(ctx context.Context, logger *zap.Logger) error {
uv := validator.NewUserValidator()
uu := usecase.NewUserUsecase(ur, oar, er, uv, gs, ms)
au := usecase.NewAuthUsecase(cfg, logger, ar)
eu := usecase.NewEventUsecase(er)
eu := usecase.NewEventUsecase(cfg, er)
oau := usecase.NewOauthUsecase(cfg, oar, ur, gs, ms, uu)

em := middleware.NewErrorMiddleware(logger, uu)
Expand All @@ -69,8 +68,8 @@ func run(ctx context.Context, logger *zap.Logger) error {
if err != nil {
logger.Fatal("failed to listen port", zap.Error(err))
}
err = util.SendMail(*cfg, "[email protected]", "konnitiha", "hello")
fmt.Println(err)
// err = util.SendMail(*cfg, "[email protected]", "konnitiha", "hello")
// fmt.Println(err)

e := router.NewRouter(cfg, logger, em, atm, am, uc, ac, ec, oc)
s := NewServer(e, l, logger)
Expand Down
33 changes: 27 additions & 6 deletions repository/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type EventRepository interface {
FetchEventTimeUnits(ctx context.Context, tx *sql.Tx, eventId ulid.ULID) ([]entity.EventTimeUnit, error)
// イベントの全ユーザー回答(Unit付き)を取得する
FetchEventAnswersWithUnits(ctx context.Context, tx *sql.Tx, eventId ulid.ULID) ([]entity.UserEventAnswer, error)
// 回答したユーザーの数を取得する
FetchUserAnswerCount(ctx context.Context, tx *sql.Tx, eventId ulid.ULID) (int, error)
// イベントの指定ユーザー回答(Unit無し)を取得する
FetchEventAnswer(ctx context.Context, tx *sql.Tx, eventId ulid.ULID, userId ulid.ULID) (entity.UserEventAnswer, error)

Expand Down Expand Up @@ -66,12 +68,15 @@ func (er *eventRepository) CreateEvent(ctx context.Context, tx *sql.Tx, event en

id := util.GenerateULID(ctx)
e := &models.Event{
ID: util.ULIDToString(id),
OwnerID: util.ULIDToString(event.OwnerID),
Name: event.Name,
Description: event.Description,
DurationAbout: event.DurationAbout,
UnitSeconds: uint64(event.UnitSeconds),
ID: util.ULIDToString(id),
OwnerID: util.ULIDToString(event.OwnerID),
Name: event.Name,
Description: event.Description,
DurationAbout: event.DurationAbout,
UnitSeconds: uint64(event.UnitSeconds),
EnablesEmailNotification: event.NotifyByEmail,
ExpectedParticipantsNumber: event.NumberOfParticipants,
NotificationEmail: event.ConfirmationEmail,
}
err := e.Insert(ctx, exc, boil.Infer())
if err != nil {
Expand Down Expand Up @@ -262,6 +267,22 @@ func (er *eventRepository) FetchEventAnswer(ctx context.Context, tx *sql.Tx, eve
}, nil
}

// FetchUserAnswerCount implements EventRepository.
func (er *eventRepository) FetchUserAnswerCount(ctx context.Context, tx *sql.Tx, eventId ulid.ULID) (int, error) {
var exc boil.ContextExecutor = tx
if tx == nil {
exc = er.db
}

count, err := models.UserEventAnswers(
models.UserEventAnswerWhere.EventID.EQ(util.ULIDToString(eventId)),
).Count(ctx, exc)
if err != nil {
return 0, err
}
return int(count), nil
}

// UpdateEventAnswer implements EventRepository.
func (er *eventRepository) UpdateEventAnswer(ctx context.Context, tx *sql.Tx, answer entity.UserEventAnswer) (entity.UserEventAnswer, error) {
var exc boil.ContextExecutor = tx
Expand Down
19 changes: 11 additions & 8 deletions repository/internal/converter/event_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ func EventModelToEntity(ctx context.Context, em *models.Event, units []entity.Ev
return entity.Event{}, fmt.Errorf("failed to parse ULID(%s): %w", em.OwnerID, err)
}
return entity.Event{
ID: id,
OwnerID: ownerId,
Name: em.Name,
Description: em.Description,
DurationAbout: em.DurationAbout,
UnitSeconds: int(em.UnitSeconds),
Units: units,
UserAnswers: userAnswers,
ID: id,
OwnerID: ownerId,
Name: em.Name,
Description: em.Description,
DurationAbout: em.DurationAbout,
UnitSeconds: int(em.UnitSeconds),
Units: units,
UserAnswers: userAnswers,
NotifyByEmail: em.EnablesEmailNotification,
NumberOfParticipants: em.ExpectedParticipantsNumber,
ConfirmationEmail: em.NotificationEmail,
}, nil
}
171 changes: 112 additions & 59 deletions repository/internal/models/event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea04cf7

Please sign in to comment.