diff --git a/src/challenge-event/challenge-event-api.mts b/src/challenge-event/challenge-event-api.mts index 3863ea9..674d862 100644 --- a/src/challenge-event/challenge-event-api.mts +++ b/src/challenge-event/challenge-event-api.mts @@ -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: @@ -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: diff --git a/src/challenge-event/challenge-event-repo.mts b/src/challenge-event/challenge-event-repo.mts index b95cfa2..d54449c 100644 --- a/src/challenge-event/challenge-event-repo.mts +++ b/src/challenge-event/challenge-event-repo.mts @@ -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'; @@ -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: () => @@ -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 @@ -79,7 +75,7 @@ where const ResultSchema = FindManyResultSchema( Schema.Struct({ - ...ChallengeEventView.fields, + ...ChallengeEvent.fields, coordinate: Schema.NullishOr(FromStringToCoordinate), }), ); @@ -101,11 +97,11 @@ 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) => @@ -113,11 +109,11 @@ where 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; @@ -187,7 +183,7 @@ where ${sql('id')} = ${request.id}; const with_ = ( id: ChallengeEventId, - f: (event: ChallengeEventView) => Effect.Effect, + f: (event: ChallengeEvent) => Effect.Effect, ): Effect.Effect => pipe( findById(id),