Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added requests, responses, and search conditions #99

Merged
merged 7 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-gradle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Java CI with Gradle
on:
[ push, pull_request ]
workflow_call:

jobs:
build_on_test:
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Docker build and push
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true

DOCKERHUB_TOKEN:
required: true

jobs:
docker:
strategy:
matrix:
project: [ foods, orders, notifications, payment ]

runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Test and Build
run: |
chmod +x gradlew
./gradlew clean build

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3

- name: Build and Push for ${{ matrix.project }}
uses: docker/build-push-action@v6
with:
push: true
context: ./${{ matrix.project }}
file: ./${{ matrix.project }}/Dockerfile
platforms: linux/arm64,linux/amd64
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.project }}:latest
49 changes: 49 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Terraform Apply'

on:
push:
branches:
- main

env:
TF_CLOUD_ORGANIZATION: "${{ secrets.TERRAFORM_ORGANISATION }}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "${{ secrets.TF_WORKSPACE }}"
CONFIG_DIRECTORY: "./infrastructure"

jobs:
docker-build:
uses: ./.github/workflows/docker.yml
secrets:
DOCKERHUB_USERNAME: "${{ secrets.DOCKERHUB_USERNAME }}"
DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}"

terraform:
name: "Terraform Apply"
needs: [ docker-build ]
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply-upload
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.CONFIG_DIRECTORY }}

- name: Create Apply Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply-run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }}

- name: Wait for Manual Approval
run: |
echo "Terraform apply requires manual approval in Terraform Cloud."
echo "Go to Terraform Cloud UI to approve the apply: ${{ steps.apply-run.outputs.run_link }}"
83 changes: 83 additions & 0 deletions .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Terraform Plan
on:
[ pull_request ]

env:
TF_CLOUD_ORGANIZATION: "${{ secrets.TERRAFORM_ORGANISATION }}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "${{ secrets.TF_WORKSPACE }}"
CONFIG_DIRECTORY: "./infrastructure"

jobs:
ci-gradle:
uses: ./.github/workflows/ci-gradle.yml

terraform:
needs: [ ci-gradle ]
name: "Terraform Plan"
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-upload
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.CONFIG_DIRECTORY }}
speculative: true

- name: Create Plan Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.plan-upload.outputs.configuration_version_id }}
plan_only: true

- name: Get Plan Output
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-output
with:
plan: ${{ fromJSON(steps.plan-run.outputs.payload).data.relationships.plan.data.id }}

- name: Update PR
uses: actions/github-script@v6
id: plan-comment
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('HCP Terraform Plan Output')
});
const output = `#### HCP Terraform Plan Output
\`\`\`
Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy.
\`\`\`
[HCP Terraform Plan](${{ steps.plan-run.outputs.run_link }})
`;
// 3. Delete previous comment so PR timeline makes sense
if (botComment) {
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
});
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -39,13 +38,6 @@ public class Currency extends BaseTimeEntity {
private int roundingScale;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "VARCHAR(20) NOT NULL DEFAULT 'FLOOR'")
private RoundingMode roundingMode;

@PrePersist
public void prePersist() {
if (this.roundingMode == null) {
this.roundingMode = RoundingMode.FLOOR;
}
}
}
19 changes: 5 additions & 14 deletions core/src/main/java/com/f_lab/joyeuse_planete/core/domain/Food.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.f_lab.joyeuse_planete.core.domain;

import com.f_lab.joyeuse_planete.core.domain.base.BaseEntity;
import com.f_lab.joyeuse_planete.core.domain.converter.StringListConverter;
import com.f_lab.joyeuse_planete.core.exceptions.ErrorCode;
import com.f_lab.joyeuse_planete.core.exceptions.JoyeusePlaneteApplicationException;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -19,8 +21,6 @@

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static jakarta.persistence.FetchType.LAZY;
Expand Down Expand Up @@ -55,9 +55,10 @@ public class Food extends BaseEntity {
@JoinColumn(name = "currency_id")
private Currency currency;

private Double rate;
private BigDecimal rate;

private String tags;
@Convert(converter = StringListConverter.class)
private List<String> tags;

private LocalDateTime collectionStartTime;

Expand Down Expand Up @@ -85,24 +86,14 @@ public void update(
String foodName,
BigDecimal price,
int totalQuantity,
Currency currency,
LocalDateTime collectionStartTime,
LocalDateTime collectionEndTime
) {

this.foodName = foodName;
this.price = price;
this.totalQuantity = totalQuantity;
this.currency = currency;
this.collectionStartTime = collectionStartTime;
this.collectionEndTime = collectionEndTime;
}

public List<String> getTags() {
return tags == null ? new ArrayList<>() : Arrays.asList(tags.split(","));
}

public void setTags(List<String> tags) {
this.tags = String.join(",", tags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class Order extends BaseTimeEntity {

private int quantity;

private double rate;

@Enumerated(EnumType.STRING)
private OrderStatus status;

Expand All @@ -56,8 +58,6 @@ public class Order extends BaseTimeEntity {
@JoinColumn(name = "voucher_id")
private Voucher voucher;

private LocalDateTime collectionTime;

public BigDecimal calculateTotalCost() {
return (voucher != null)
? voucher.apply(food.calculateCost(quantity), food.getCurrency())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.f_lab.joyeuse_planete.core.domain.converter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;

import static java.util.Collections.emptyList;

@Converter
public class StringListConverter implements AttributeConverter<List<String>, String> {

private static final String SPLIT_CHAR = ";";

@Override
public String convertToDatabaseColumn(List<String> attribute) {
return (attribute != null) ? String.join(SPLIT_CHAR, attribute) : "";
}

@Override
public List<String> convertToEntityAttribute(String dbData) {
return (!ObjectUtils.isEmpty(dbData)) ? Arrays.asList(dbData.split(SPLIT_CHAR)) : emptyList();
}
}
11 changes: 11 additions & 0 deletions foods/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM openjdk:17

ARG JAVA_FILE=build/libs/*.jar

WORKDIR /usr/src/app

COPY ${JAVA_FILE} joyeuse_planete-foods.jar

EXPOSE 8080

CMD [ "java", "-jar", "joyeuse_planete-foods.jar" ]
Loading
Loading