Skip to content

Commit

Permalink
Merge branch 'dev' into test/#21
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulTree-Lovers authored Jul 25, 2024
2 parents 517cbd8 + efe75b0 commit 503dd1d
Show file tree
Hide file tree
Showing 93 changed files with 3,906 additions and 60 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: server


on:
push:
branches:
- dev

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

- name: Ensure resource directory exists
run: mkdir -p ./src/main/resources

- name : injection-yml
run : echo -E "${{ secrets.YML }}" > ./src/main/resources/application.yml

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Execute Gradle build and analyze
run: ./gradlew jib

- name: Run scripts in server
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.PRIVATE_KEY }}
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
script: ${{ secrets.SCRIPT }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### Setting File ###
src/main/resources/application.yml
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div align="center">

# 빈주머니즈_Spring
<img src="https://github.com/user-attachments/assets/98dd17ec-9019-48f0-b5cb-00a9d0af8e9c" width="100" height="100"/>
![빈주머니즈_커버_대지 1 사본](https://github.com/user-attachments/assets/744ef4c6-87cd-4db9-9c0b-f848231a203c)


<img src="https://img.shields.io/badge/Spring-6DB33F?style=for-the-badge&logo=Spring&logoColor=white"> ![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![MySQL](https://img.shields.io/badge/mysql-4479A1.svg?style=for-the-badge&logo=mysql&logoColor=white) ![IntelliJ IDEA](https://img.shields.io/badge/IntelliJIDEA-000000.svg?style=for-the-badge&logo=intellij-idea&logoColor=white) ![Postman](https://img.shields.io/badge/Postman-FF6C37?style=for-the-badge&logo=postman&logoColor=white)

<img src="https://github.com/user-attachments/assets/98dd17ec-9019-48f0-b5cb-00a9d0af8e9c" width="100" height="100"/>

## Team
|<img src="https://avatars.githubusercontent.com/u/41982054?v=4" width="150" height="150"/>|<img src="https://avatars.githubusercontent.com/u/54972879?v=4" width="150" height="150"/>|<img src="https://avatars.githubusercontent.com/u/96693842?v=4" width="150" height="150"/>|<img src="https://avatars.githubusercontent.com/u/106878778?v=4" width="150" height="150"/>|<img src="https://avatars.githubusercontent.com/u/107318116?v=4" width="150" height="150"/>|<img src="https://avatars.githubusercontent.com/u/162525176?v=4" width="150" height="150"/>|
|:-:|:-:|:-:|:-:|:-:|:-:|
Expand Down
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.7'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.google.cloud.tools.jib' version '3.4.3'
}

group = 'com.bbteam'
Expand Down Expand Up @@ -38,3 +39,21 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

jib {
from {
image = 'openjdk:17-alpine'
platforms {
platform {
architecture = 'amd64'
os = 'linux'
}
}
}
to {
image = 'binjumeoniz1/binjumeoniz:latest'
}
container {
jvmFlags = ['-Dspring.profiles.active=dev']
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.bbteam.budgetbuddies.apiPayload;

import com.bbteam.budgetbuddies.apiPayload.code.BaseCode;
import com.bbteam.budgetbuddies.apiPayload.code.status.SuccessStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@JsonPropertyOrder({"isSuccess", "code", "message", "result"})
public class ApiResponse<T> {

@JsonProperty("isSuccess")
private final Boolean isSuccess;
private final String code;
private final String message;
@JsonInclude(JsonInclude.Include.NON_NULL)
private T result;


// 성공한 경우 응답 생성
public static <T> ApiResponse<T> onSuccess(T result){
return new ApiResponse<>(true, SuccessStatus.OK.getCode() , SuccessStatus.OK.getMessage(), result);
}

public static <T> ApiResponse<T> of(BaseCode code, T result){
return new ApiResponse<>(true, code.getReasonHttpStatus().getCode() , code.getReasonHttpStatus().getMessage(), result);
}


// 실패한 경우 응답 생성
public static <T> ApiResponse<T> onFailure(String code, String message, T data){
return new ApiResponse<>(true, code, message, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bbteam.budgetbuddies.apiPayload.code;

public interface BaseCode {
ReasonHttpStatus getReasonHttpStatus();

interface ReasonHttpStatus {
String getCode();
String getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.bbteam.budgetbuddies.apiPayload.code;

public interface BaseErrorCode {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bbteam.budgetbuddies.apiPayload.code.status;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SuccessStatus {
OK("200", "OK");

private final String code;
private final String message;
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.bbteam.budgetbuddies.common;

import jakarta.persistence.*;
import lombok.*;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SoftDelete;
import org.springframework.data.annotation.CreatedDate;
Expand All @@ -17,6 +22,7 @@
@Getter
@SuperBuilder
@SoftDelete // boolean 타입의 deleted 필드가 추가
@Getter
public abstract class BaseEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.bbteam.budgetbuddies.domain.calendar.controller;

import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;
import com.bbteam.budgetbuddies.domain.calendar.service.CalendarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/calendar")
public class CalendarController {

private final CalendarService calendarService;
@Operation(summary = "[User] 주머니 캘린더 API", description = "주머니 캘린더 화면에 필요한 API를 호출합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "year", description = "호출할 연도입니다."),
@Parameter(name = "month", description = "호출할 연도의 월입니다."),
})
@GetMapping("/")
public ResponseEntity<CalendarDto.CalendarMonthResponseDto> request(
@RequestParam("year") Integer year, @RequestParam("month") Integer month
) {
CalendarDto.CalendarMonthResponseDto result = calendarService.find(year, month);
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bbteam.budgetbuddies.domain.calendar.converter;

import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;
import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo;
import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo;

import java.util.List;

public class CalendarConverter {

public static CalendarDto.CalendarMonthResponseDto toCalendarMonthResponseDto(CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto, CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto){
return CalendarDto.CalendarMonthResponseDto.builder()
.calendarMonthInfoDto(calendarMonthInfoDto)
.recommendMonthInfoDto(recommendMonthInfoDto)
.build();
}

public static CalendarDto.CalendarMonthInfoDto toCalendarMonthInfoDto(List<DiscountInfo> discountInfoList,
List<SupportInfo> supportInfoList) {
List<CalendarDto.CalendarDiscountInfoDto> discountInfoDtoList = discountInfoList.stream()
.map(CalendarConverter::toCalendarDiscountInfoDto)
.toList();
List<CalendarDto.CalendarSupportInfoDto> supportInfoDtoList = supportInfoList.stream()
.map(CalendarConverter::toCalendarSupportInfoDto)
.toList();

return CalendarDto.CalendarMonthInfoDto.builder()
.discountInfoDtoList(discountInfoDtoList)
.supportInfoDtoList(supportInfoDtoList)
.build();
}

public static CalendarDto.CalendarDiscountInfoDto toCalendarDiscountInfoDto(DiscountInfo discountInfo) {
return CalendarDto.CalendarDiscountInfoDto.builder()
.id(discountInfo.getId())
.title(discountInfo.getTitle())
.likeCount(discountInfo.getLikeCount())
.startDate(discountInfo.getStartDate())
.endDate(discountInfo.getEndDate())
.discountRate(discountInfo.getDiscountRate())
.build();
}

public static CalendarDto.CalendarSupportInfoDto toCalendarSupportInfoDto(SupportInfo supportInfo) {
return CalendarDto.CalendarSupportInfoDto.builder()
.id(supportInfo.getId())
.title(supportInfo.getTitle())
.likeCount(supportInfo.getLikeCount())
.startDate(supportInfo.getStartDate())
.endDate(supportInfo.getEndDate())
.build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.bbteam.budgetbuddies.domain.calendar.dto;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.time.LocalDate;
import java.util.List;

public class CalendarDto {

@Getter
@Builder
public static class CalendarMonthResponseDto {
CalendarMonthInfoDto calendarMonthInfoDto;
CalendarMonthInfoDto recommendMonthInfoDto;
}

@Getter
@Builder
public static class CalendarMonthInfoDto {
private List<CalendarDiscountInfoDto> discountInfoDtoList;
private List<CalendarSupportInfoDto> supportInfoDtoList;
}

@Getter
@Builder
@EqualsAndHashCode
public static class CalendarDiscountInfoDto {
private Long id;
private String title;
private LocalDate startDate;
private LocalDate endDate;
private Integer likeCount;
private Integer discountRate;
}

@Getter
@Builder
@EqualsAndHashCode
public static class CalendarSupportInfoDto {
private Long id;
private String title;
private LocalDate startDate;
private LocalDate endDate;
private Integer likeCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bbteam.budgetbuddies.domain.calendar.service;

import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;

public interface CalendarService {

CalendarDto.CalendarMonthResponseDto find(int year, int month);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.bbteam.budgetbuddies.domain.calendar.service;

import com.bbteam.budgetbuddies.domain.calendar.converter.CalendarConverter;
import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto;
import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo;
import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository;
import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo;
import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class CalendarServiceImpl implements CalendarService{

private final DiscountInfoRepository discountInfoRepository;

private final SupportInfoRepository supportInfoRepository;

public CalendarDto.CalendarMonthResponseDto find(int year, int month){
LocalDate firstDay = LocalDate.of(year, month, 1);
LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth());
CalendarDto.CalendarMonthResponseDto result = getCalendarMonthResponseDto(firstDay, lastDay);
return result;
}

private CalendarDto.CalendarMonthResponseDto getCalendarMonthResponseDto(LocalDate firstDay, LocalDate lastDay) {
CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto = getCalendarMonthInfoDto(firstDay, lastDay);
CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto = getRecommendMonthInfoDto(firstDay, lastDay);
return CalendarConverter.toCalendarMonthResponseDto(calendarMonthInfoDto, recommendMonthInfoDto);
}

private CalendarDto.CalendarMonthInfoDto getCalendarMonthInfoDto(LocalDate firstDay, LocalDate lastDay) {
List<DiscountInfo> monthDiscountInfoList = discountInfoRepository.findByMonth(firstDay, lastDay);
List<SupportInfo> monthSupportInfoList = supportInfoRepository.findByMonth(firstDay, lastDay);
return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList);
}

private CalendarDto.CalendarMonthInfoDto getRecommendMonthInfoDto(LocalDate firstDay, LocalDate lastDay) {
List<DiscountInfo> recommendDiscountInfoList = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay);
List<SupportInfo> recommendSupportInfoList = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay);
return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList);
}
}
Loading

0 comments on commit 503dd1d

Please sign in to comment.