Skip to content

Commit

Permalink
TEMP rollback ChallengeEventView -> ChallengeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
orlein committed Dec 1, 2024
1 parent 1577173 commit 5dce75d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/challenge-event/challenge-event-api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ChallengeEventApi extends HttpApiGroup.make('challenge-event')
}),
)
.addError(ChallengeNotFound)
.addSuccess(Schema.Array(ChallengeEventView.json))
.addSuccess(Schema.Array(ChallengeEvent.json))
.annotateContext(
OpenApi.annotations({
description:
Expand All @@ -49,7 +49,7 @@ export class ChallengeEventApi extends HttpApiGroup.make('challenge-event')
)
.addError(ChallengeNotFound)
.addError(ChallengeEventNotFound)
.addSuccess(ChallengeEventView.json)
.addSuccess(ChallengeEvent.json)
.annotateContext(
OpenApi.annotations({
description:
Expand Down
32 changes: 14 additions & 18 deletions src/challenge-event/challenge-event-repo.mts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { AccountId } from '@/account/account-schema.mjs';
import { ChallengeId } from '@/challenge/challenge-schema.mjs';
import { CommonCountSchema } from '@/misc/common-count-schema.mjs';
import { FindManyResultSchema } from '@/misc/find-many-result-schema.mjs';
import { FindManyUrlParams } from '@/misc/find-many-url-params-schema.mjs';
import { makeTestLayer } from '@/misc/test-layer.mjs';
import { CREATED_AT, DESC } from '@/sql/order-by.mjs';
import { SqlLive } from '@/sql/sql-live.mjs';
import { Model, SqlClient, SqlSchema } from '@effect/sql';
import { Effect, Layer, Option, pipe, Schema } from 'effect';
import { ChallengeEventNotFound } from './challenge-event-error.mjs';
import {
ChallengeEvent,
ChallengeEventId,
ChallengeEventView,
} from './challenge-event-schema.mjs';
import { ChallengeEvent, ChallengeEventId } from './challenge-event-schema.mjs';
import { FromStringToCoordinate, Meters } from './helper-schema.mjs';
import { FindManyUrlParams } from '@/misc/find-many-url-params-schema.mjs';
import { AccountId } from '@/account/account-schema.mjs';
import { CREATED_AT, DESC } from '@/sql/order-by.mjs';
import { CommonCountSchema } from '@/misc/common-count-schema.mjs';
import { FindManyResultSchema } from '@/misc/find-many-result-schema.mjs';

const TABLE_NAME = 'challenge_event';

Expand All @@ -36,7 +32,7 @@ const make = Effect.gen(function* () {
const posts = yield* SqlSchema.findAll({
Request: FindManyUrlParams,
Result: Schema.Struct({
...ChallengeEventView.fields,
...ChallengeEvent.fields,
coordinate: Schema.NullishOr(FromStringToCoordinate),
}),
execute: () =>
Expand All @@ -47,7 +43,7 @@ SELECT
FROM
challenge_event_participant cep
LEFT JOIN
${sql(VIEW_NAME)} ce ON cep.challenge_event_id = ce.id
${sql(TABLE_NAME)} ce ON cep.challenge_event_id = ce.id
where
${sql.and(
accountId
Expand Down Expand Up @@ -79,7 +75,7 @@ where

const ResultSchema = FindManyResultSchema(
Schema.Struct({
...ChallengeEventView.fields,
...ChallengeEvent.fields,
coordinate: Schema.NullishOr(FromStringToCoordinate),
}),
);
Expand All @@ -101,23 +97,23 @@ where
SqlSchema.findOne({
Request: ChallengeEventId,
Result: Schema.Struct({
...ChallengeEventView.fields,
...ChallengeEvent.fields,
coordinate: Schema.NullishOr(FromStringToCoordinate),
}),
execute: (id) =>
sql`select *, ST_AsText(${sql('coordinate')}) as coordinate from ${sql(VIEW_NAME)} where ${sql('id')} = ${id};`,
sql`select *, ST_AsText(${sql('coordinate')}) as coordinate from ${sql(TABLE_NAME)} where ${sql('id')} = ${id};`,
})(id).pipe(Effect.orDie, Effect.withSpan('ChallengeEventRepo.findById'));

const findAllByChallengeId = (challengeId: ChallengeId) =>
Effect.gen(function* () {
const events = yield* SqlSchema.findAll({
Request: ChallengeId,
Result: Schema.Struct({
...ChallengeEventView.fields,
...ChallengeEvent.fields,
coordinate: Schema.NullishOr(FromStringToCoordinate),
}),
execute: () =>
sql`select *, ST_AsText(${sql('coordinate')}) as coordinate from ${sql(VIEW_NAME)} where challenge_id = ${challengeId};`,
sql`select *, ST_AsText(${sql('coordinate')}) as coordinate from ${sql(TABLE_NAME)} where challenge_id = ${challengeId};`,
})(challengeId);

return events;
Expand Down Expand Up @@ -187,7 +183,7 @@ where ${sql('id')} = ${request.id};

const with_ = <A, E, R>(
id: ChallengeEventId,
f: (event: ChallengeEventView) => Effect.Effect<A, E, R>,
f: (event: ChallengeEvent) => Effect.Effect<A, E, R>,
): Effect.Effect<A, E | ChallengeEventNotFound, R> =>
pipe(
findById(id),
Expand Down

0 comments on commit 5dce75d

Please sign in to comment.