Skip to content

Commit

Permalink
feat: check wishlist by pages (#55)
Browse files Browse the repository at this point in the history
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
4 people authored Oct 20, 2024
1 parent c353f0b commit eddfe9f
Show file tree
Hide file tree
Showing 40 changed files with 673 additions and 127 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci-wishlist-service.yaml
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
1 change: 1 addition & 0 deletions .github/workflows/provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- NSHM-9-Set-up-environment
workflow_dispatch:
inputs:
provision:
Expand Down
4 changes: 2 additions & 2 deletions envs/account.env.gpg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
� ��cՋ����FN>�naZz�����}���� y
d�e}��p�d<��ur�BǢP�@6`�AZ�l-�oÕɫ����R�O:�F)X�x�y�9�.���v�.��!��K��u_=�4oΦ�1�_x�8�@�q��b/��8g�G����;��!��+t�i�����w�[{A�% ,끡�� #(��~'߻]���&W$��W-_#X>��.?}�%�4`�.a����J��+�!�52y�M0�e�$�^�݉J��b}E��!h|쑰����
� &RD�LșD���HK��p���ɞt2�y[(>�������J�hOB�]�]�P9�[�{2�_�8 �N��V��-��ϙ���������J1��s)_ⷐ ��\L�#��7&\��ϲw7�$t���,$�w�*��(`�P��\Mt����{3w- �z,��HU-�*�.t?��~
÷�+*�+u�����8�r�|0bV��|q�t���̵U#��q��e�7��p���Cu���q��LD�55IJ��+� }�g�wz�i�d{��V*ҟg
Expand Down
Binary file modified envs/currency.env.gpg
Binary file not shown.
Binary file modified envs/item.env.gpg
Binary file not shown.
Binary file modified envs/notification.env.gpg
Binary file not shown.
3 changes: 1 addition & 2 deletions envs/web.env.gpg
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
� �}��ܪ�<��pr��"�^�Ը�/r3V������S�?��fe��9�>�O�з�-%>�
J�+��a����t黓��9����m�dTΧ�+.Y�8��ź�y1��of�x ��1�6�T~��
� =:���7 ���p[(S�q!d�Fr���G�+�+R;)@{�C+���F�H��InT;ۈ�p���Re}��]*��h��z�"���+��9�I~Ⱥ����p��B�ڶ��=.�U�]GT� V
Expand Down
Binary file modified envs/wishlist-mongo.env.gpg
Binary file not shown.
Binary file modified envs/wishlist.env.gpg
Binary file not shown.
4 changes: 2 additions & 2 deletions helm/templates/wishlist/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
type: ClusterIP
ports:
- port: 8082
targetPort: 8082
- port: 8083
targetPort: 8083
selector:
app: wishlist
6 changes: 4 additions & 2 deletions services/item/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun AS build
FROM oven/bun:alpine AS build

WORKDIR /app

Expand All @@ -10,10 +10,12 @@ COPY . .

RUN bun run build

FROM oven/bun AS production
FROM oven/bun:alpine AS production

WORKDIR /app

RUN apk add --no-cache curl

COPY --from=build /app/dist/index.js .

CMD ["bun", "run", "index.js"]
4 changes: 3 additions & 1 deletion services/item/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM oven/bun
FROM oven/bun:alpine

WORKDIR /app

RUN apk add --no-cache curl

COPY package.json bun.lockb ./

RUN bun install --frozen-lockfile
Expand Down
2 changes: 2 additions & 0 deletions services/notification/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ FROM alpine AS production

WORKDIR /app

RUN apk add --no-cache curl

COPY --from=build /app/app .

CMD ["./app"]
16 changes: 16 additions & 0 deletions services/notification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"

_ "github.com/joho/godotenv/autoload"
Expand Down Expand Up @@ -34,6 +35,8 @@ func main() {
log.Panic(err)
}

startHealthCheck()

log.Print("service started")

var forever = make(chan struct{})
Expand Down Expand Up @@ -80,3 +83,16 @@ func startQueue[Payload interface{ Process() error }](ch *amqp.Channel, topic st

return nil
}

func startHealthCheck() {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

go func() {
err := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
if err != nil {
log.Panic(err)
}
}()
}
2 changes: 2 additions & 0 deletions services/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ FROM node:lts-alpine AS production

WORKDIR /app

RUN apk add --no-cache curl

COPY --from=build /app/.next/standalone .

ENV HOSTNAME=0.0.0.0
Expand Down
4 changes: 1 addition & 3 deletions services/web/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ FROM node:lts-alpine

WORKDIR /app

RUN apk add --no-cache libc6-compat
RUN apk add --no-cache curl libc6-compat

RUN corepack enable pnpm

COPY package.json pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile

COPY . .

ENV HOSTNAME=0.0.0.0

CMD ["pnpm", "run", "dev"]
3 changes: 3 additions & 0 deletions services/web/src/app/healthz/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function GET() {
return new Response("ok");
}
11 changes: 3 additions & 8 deletions services/wishlist/Dockerfile
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"]
6 changes: 6 additions & 0 deletions services/wishlist/Dockerfile.dev
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"]
8 changes: 8 additions & 0 deletions services/wishlist/Dockerfile.test
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"]
10 changes: 5 additions & 5 deletions services/wishlist/database/1-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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 favoriteDate
db.wishlist.createIndex({ itemId: 1, favoriteDate: -1 });
// 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
db.wishlist.createIndex({ userId: 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 indexes.");
print("Wishlist collection initialized with updated indexes.");
14 changes: 14 additions & 0 deletions services/wishlist/database/dev/1-schema.js
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.");
106 changes: 106 additions & 0 deletions services/wishlist/database/dev/2-seed.js
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
}
]);

35 changes: 35 additions & 0 deletions services/wishlist/database/test/1-schema.js
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.");

Loading

0 comments on commit eddfe9f

Please sign in to comment.