-
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.
Co-authored-by: GuoHeZuYa <[email protected]> Co-authored-by: Jyf <[email protected]> Co-authored-by: amber <> Co-authored-by: Yuwang Cai <[email protected]>
- Loading branch information
1 parent
c353f0b
commit eddfe9f
Showing
40 changed files
with
673 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: CI for Wishlist Service | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- services/wishlist/** | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- services/wishlist/** | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: services/wishlist | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Start containers | ||
run: | | ||
docker compose -f docker-compose.test.yaml up -d --build | ||
- name: Wait for test reports | ||
run: | | ||
for i in {1..30}; do | ||
if [ -f ./reports/index.html ]; then | ||
echo "Test report is ready!" | ||
break | ||
fi | ||
echo "Waiting for test report to be generated..." | ||
sleep 5 | ||
done | ||
ls -lart reports | ||
- name: Upload Test Reports | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: jacoco-reports | ||
path: ${{ github.workspace }}/services/wishlist/reports |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- NSHM-9-Set-up-environment | ||
workflow_dispatch: | ||
inputs: | ||
provision: | ||
|
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ FROM alpine AS production | |
|
||
WORKDIR /app | ||
|
||
RUN apk add --no-cache curl | ||
|
||
COPY --from=build /app/app . | ||
|
||
CMD ["./app"] |
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
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,3 @@ | ||
export async function GET() { | ||
return new Response("ok"); | ||
} |
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,18 +1,13 @@ | ||
# Stage 1: Build the application | ||
FROM maven:3.8-openjdk-17 AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY pom.xml . | ||
COPY src ./src | ||
|
||
RUN mvn clean package -DskipTests | ||
|
||
# Stage 2: Create a slim production image | ||
FROM openjdk:17-jdk-slim | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app/target/*.jar app.jar | ||
|
||
EXPOSE 8082 | ||
|
||
EXPOSE 8083 | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
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,6 @@ | ||
FROM maven:3.8-openjdk-17 | ||
WORKDIR /app | ||
COPY pom.xml . | ||
COPY src ./src | ||
EXPOSE 8083 5005 | ||
CMD ["mvn", "spring-boot:run", "-Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"] |
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,8 @@ | ||
FROM maven:3.8.5-openjdk-17 AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY pom.xml ./ | ||
COPY src ./src | ||
|
||
CMD ["mvn", "test", "-DskipClean"] |
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,14 @@ | ||
// Create 'wishlist' collection (if it doesn't exist yet) | ||
db.createCollection("wishlist"); | ||
|
||
// Create an index to ensure the combination of userId and itemId is unique | ||
db.wishlist.createIndex({ userId: 1, itemId: 1 }, { unique: true }); | ||
|
||
// Create an index to speed up queries that fetch the latest favorite records for an item, sorted by wantedAt | ||
db.wishlist.createIndex({ itemId: 1, wantedAt: -1 }); | ||
|
||
// Create a single-field index on userId to speed up queries that fetch all favorites of a specific user, sorted by wantedAt | ||
db.wishlist.createIndex({ userId: 1, wantedAt: -1 }); | ||
|
||
// Print confirmation message | ||
print("Wishlist collection initialized with updated indexes."); |
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,106 @@ | ||
// Insert seed data into 'wishlist' collection | ||
db.wishlist.insertMany([ | ||
{ | ||
_id: ObjectId("670f7703ad0e321f3552e02c"), | ||
_class: "edu.nus.market.pojo.SingleLike", | ||
itemId: "581cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "iPhone 12", | ||
photoUrls: ["https://example.com/iphone12.jpg"], | ||
price: 999.99, | ||
seller: { | ||
_id: "110", | ||
nickname: "Johnny", | ||
avatarUrl: "https://example.com/avatar.png" | ||
}, | ||
status: 1, | ||
type: "single", | ||
userId: 110, | ||
wantedAt: ISODate("2024-10-16T08:19:15.624Z") | ||
}, | ||
{ | ||
_id: ObjectId("670f7706ad0e321f3552e02d"), | ||
_class: "edu.nus.market.pojo.PackLike", | ||
itemId: "681cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "Apple Device Bundle", | ||
price: 1999.99, | ||
seller: { | ||
_id: "seller001", | ||
nickname: "John's Store", | ||
avatarUrl: "http://example.com/avatar.jpg" | ||
}, | ||
status: 1, | ||
type: "pack", | ||
userId: 110, | ||
wantedAt: ISODate("2024-10-16T08:19:18.582Z"), | ||
discount: 10 | ||
}, | ||
{ | ||
_id: ObjectId("670f7707ad0e321f3552e02e"), | ||
_class: "edu.nus.market.pojo.SingleLike", | ||
itemId: "981cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "Samsung Galaxy S21", | ||
photoUrls: ["https://example.com/galaxys21.jpg"], | ||
price: 799.99, | ||
seller: { | ||
_id: "seller002", | ||
nickname: "Galaxy Shop", | ||
avatarUrl: "https://example.com/galaxyshop.jpg" | ||
}, | ||
status: 1, | ||
type: "single", | ||
userId: 111, | ||
wantedAt: ISODate("2024-10-17T10:30:45.120Z") | ||
}, | ||
{ | ||
_id: ObjectId("670f7708ad0e321f3552e02f"), | ||
_class: "edu.nus.market.pojo.PackLike", | ||
itemId: "781cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "Smart Home Bundle", | ||
price: 499.99, | ||
seller: { | ||
_id: "seller003", | ||
nickname: "Smart Home Store", | ||
avatarUrl: "https://example.com/smarthome.jpg" | ||
}, | ||
status: 1, | ||
type: "pack", | ||
userId: 111, | ||
wantedAt: ISODate("2024-10-17T11:45:32.524Z"), | ||
discount: 15 | ||
}, | ||
{ | ||
_id: ObjectId("670f7709ad0e321f3552e030"), | ||
_class: "edu.nus.market.pojo.SingleLike", | ||
itemId: "881cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "PlayStation 5", | ||
photoUrls: ["https://example.com/ps5.jpg"], | ||
price: 499.99, | ||
seller: { | ||
_id: "seller004", | ||
nickname: "Game World", | ||
avatarUrl: "https://example.com/gameworld.jpg" | ||
}, | ||
status: 1, | ||
type: "single", | ||
userId: 112, | ||
wantedAt: ISODate("2024-10-18T09:25:18.743Z") | ||
}, | ||
{ | ||
_id: ObjectId("670f7710ad0e321f3552e031"), | ||
_class: "edu.nus.market.pojo.PackLike", | ||
itemId: "881cd614-27a1-4716-889d-e9a22fc27f07", | ||
name: "Gamer Bundle", | ||
price: 1499.99, | ||
seller: { | ||
_id: "seller005", | ||
nickname: "Gamer's Paradise", | ||
avatarUrl: "https://example.com/gamersparadise.jpg" | ||
}, | ||
status: 1, | ||
type: "pack", | ||
userId: 113, | ||
wantedAt: ISODate("2024-10-18T12:15:47.982Z"), | ||
discount: 20 | ||
} | ||
]); | ||
|
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,35 @@ | ||
// Switch to the target database | ||
db = db.getSiblingDB('test_nshm_wishlist'); | ||
|
||
// Create 'wishlist' collection (if it doesn't exist yet) | ||
db.createCollection("wishlist"); | ||
|
||
// Create an index to ensure the combination of userId and itemId is unique | ||
db.wishlist.createIndex({ userId: 1, itemId: 1 }, { unique: true }); | ||
|
||
// Create an index to speed up queries that fetch the latest favorite records for an item, sorted by wantedAt | ||
db.wishlist.createIndex({ itemId: 1, wantedAt: -1 }); | ||
|
||
// Create a single-field index on userId to speed up queries that fetch all favorites of a specific user, sorted by wantedAt | ||
db.wishlist.createIndex({ userId: 1, wantedAt: -1 }); | ||
|
||
// Check if the user already exists | ||
var user = db.getUser("test_user"); | ||
|
||
if (!user) { | ||
// Create user with readWrite role on the test_nshm_wishlist database | ||
db.createUser({ | ||
user: "test_user", | ||
pwd: "test_password", // Replace with a secure password in production | ||
roles: [ | ||
{ role: "readWrite", db: "test_nshm_wishlist" } | ||
] | ||
}); | ||
print("User 'test_user' created with readWrite access."); | ||
} else { | ||
print("User 'test_user' already exists."); | ||
} | ||
|
||
// Print confirmation message | ||
print("Wishlist collection initialized with updated indexes."); | ||
|
Oops, something went wrong.