-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SHR-24] feat: search campaigns in explore screen (#178)
- Loading branch information
1 parent
b77cbaf
commit c53378f
Showing
19 changed files
with
215 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Order } from './' | ||
|
||
export class ThenByOrder extends Order { | ||
#firstOrder; | ||
#secondOrder; | ||
|
||
constructor(firstOrder, secondOrder) { | ||
super(); | ||
this.#firstOrder = firstOrder; | ||
this.#secondOrder = secondOrder; | ||
} | ||
|
||
toSql() { | ||
console.log(123,this.#firstOrder.toSql(), " ",this.#secondOrder.toSql()); | ||
return `${this.#firstOrder.toSql()}, ${this.#secondOrder.toSql()}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './order'; | ||
export * from './and-then-order'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ThenByOrder } from './'; | ||
|
||
export class Order { | ||
constructor(direction = null) { | ||
if (direction) { | ||
this.validateDirection(direction); | ||
} | ||
this.direction = direction; | ||
} | ||
|
||
validateDirection(direction) { | ||
var direction = direction.toUpperCase(); | ||
|
||
if (direction !== 'ASC' && direction !== 'DESC') { | ||
throw new Error('Invalid direction'); | ||
} | ||
} | ||
|
||
thenBy(order) { | ||
return new ThenByOrder(this, order); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { OrderFactory } from 'core/modules/campaign/orders'; | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const CampaignSortQuery = SwaggerDocument.ApiParams({ | ||
name: 'isSortedByStatus', | ||
export const CampaignOrderQuery = SwaggerDocument.ApiParams({ | ||
name: 'orderBy', | ||
paramsIn: 'query', | ||
type: 'bool', | ||
type: 'string', | ||
required: false, | ||
description: 'Sort campaigns by status as follows: UPCOMING, ENDED, IN PROGRESS', | ||
description: `Syntax follows the pattern 'value + 'asc' or 'desc' (+ ', ') (e.g., 'value1 asc, value2 desc'). Allowed values include: ${OrderFactory.getAllOrderQueryValues()}.`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const CurrentLatitudeQuery = SwaggerDocument.ApiParams( | ||
{ | ||
name: 'currentLat', | ||
paramsIn: 'query', | ||
type: 'string', | ||
required: false, | ||
description: "User's current latitude", | ||
} | ||
); |
11 changes: 11 additions & 0 deletions
11
backend/src/core/common/swagger/current-longitude-query.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const CurrentLongitudeQuery = SwaggerDocument.ApiParams( | ||
{ | ||
name: 'currentLng', | ||
paramsIn: 'query', | ||
type: 'string', | ||
required: false, | ||
description: "User's current longitude", | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
backend/src/core/modules/campaign/interceptor/campaign-sort-interceptor.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/src/core/modules/campaign/orders/campaign-by-proximity-order.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Order } from 'core/common/orders'; | ||
|
||
export class CampaignByProximityOrder extends Order { | ||
#lat; | ||
#lng; | ||
|
||
constructor(lat, lng, direction = 'ASC') { | ||
super(direction); | ||
if (!lat || !lng) throw new Error('Latitude and longitude are required'); | ||
this.#lat = parseFloat(lat); | ||
this.#lng = parseFloat(lng); | ||
} | ||
|
||
toSql() { | ||
return `ST_Distance( | ||
ST_MakePoint(cast(coordinate->>'lng' as float), cast(coordinate->>'lat' as float))::geography, | ||
ST_MakePoint(${this.#lng}, ${this.#lat})::geography) ${this.direction}`; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/core/modules/campaign/orders/campaign-status-order.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Order } from 'core/common/orders'; | ||
|
||
export class CampaignStatusOrder extends Order { | ||
#upComing; | ||
#onGoing; | ||
#passed; | ||
|
||
constructor(upComing, onGoing, passed, direction = 'ASC') { | ||
super(direction); | ||
this.#upComing = Number(upComing); | ||
this.#onGoing = Number(onGoing); | ||
this.#passed = Number(passed); | ||
} | ||
|
||
toSql() { | ||
return ` | ||
CASE | ||
WHEN campaigns.start_date > NOW() AND campaigns.end_date > NOW() THEN ${this.#upComing} -- UPCOMING | ||
WHEN campaigns.start_date < NOW() AND campaigns.end_date < NOW() THEN ${this.#passed} -- PASSED | ||
ELSE ${this.#onGoing} -- ONGOING | ||
END ${this.direction} | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './campaign-by-proximity-order'; | ||
export * from './campaign-status-order'; | ||
export * from './order-factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { CampaignByProximityOrder, CampaignStatusOrder } from '.' | ||
|
||
export class OrderFactory { | ||
static OrderTypeEnum = { | ||
PROXIMITY: 'proximity', | ||
PASSED_ONGOING_UPCOMING: 'passed_ongoing_upcoming', | ||
UPCOMING_PASSED_ONGOING: 'upcoming_passed_ongoing', | ||
PASSED_UPCOMING_ONGOING: 'passed_upcoming_ongoing', | ||
}; | ||
static getOrder(param, lat, lng, direction) { | ||
switch(param) { | ||
case OrderTypeEnum.PROXIMITY: | ||
return new CampaignByProximityOrder(lat, lng, direction); | ||
case OrderTypeEnum.PASSED_ONGOING_UPCOMING: | ||
return new CampaignStatusOrder(3, 2, 1, direction); | ||
case OrderTypeEnum.UPCOMING_PASSED_ONGOING: | ||
return new CampaignStatusOrder(1, 3, 2, direction); | ||
case OrderTypeEnum.PASSED_UPCOMING_ONGOING: | ||
return new CampaignStatusOrder(2, 3, 1, direction); | ||
default: | ||
throw new Error('Order not found'); | ||
} | ||
} | ||
|
||
static getAllOrderQueryValues() { | ||
return Object.values(this.OrderTypeEnum).join(", "); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...end/src/core/modules/campaign/specifications/campaign-location-proximity-specification.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Specification } from 'core/common/specifications'; | ||
|
||
export class CampaignLocationProximitySpecification extends Specification { | ||
#lat; | ||
#lng; | ||
#radius = 5000; | ||
|
||
constructor(lat, lng) { | ||
super(); | ||
this.#lat = lat; | ||
this.#lng = lng; | ||
} | ||
|
||
toSql() { | ||
return [`ST_DWithin( | ||
ST_MakePoint(cast(coordinate->>'lng' as float), cast(coordinate->>'lat' as float))::geography, | ||
ST_MakePoint(:lng, :lat)::geography,:radius)`, | ||
{ lng: this.#lng, lat: this.#lat, radius: this.#radius }]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters