Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#24
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-seong committed Jan 31, 2024
2 parents 68d2d59 + 46b3418 commit 590b5b7
Show file tree
Hide file tree
Showing 43 changed files with 1,054 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .ebextensions_dev/00-makeFiles.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
files:
"/sbin/appstart" :
mode: "000755"
owner: webapp
group: webapp
content: |
#!/usr/bin/env bash
JAR_PATH=/var/app/current/application.jar

# run app
killall java
java -Dfile.encoding=UTF-8 -jar $JAR_PATH
3 changes: 3 additions & 0 deletions .ebextensions_dev/01-set-timezone.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
61 changes: 61 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Onnoff Dev CI/CD

on:
pull_request:
types: [closed]
workflow_dispatch: # (2).수동 실행도 가능하도록

jobs:
build:
runs-on: ubuntu-latest # (3).OS환경
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev'

steps:
- name: Checkout
uses: actions/checkout@v2 # (4).코드 check out

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17 # (5).자바 설치
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash # (6).권한 부여

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # (7).build 시작

- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (8).build 시점의 시간확보

- name: Show Current Time
run: echo "CurrentTime=$"
shell: bash # (9).확보한 시간 보여주기

- name: Generate deployment package
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions_dev deploy/.ebextensions
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }}
application_name: onnoff-dev # 원하는 어플 이름
environment_name: Onnoff-dev-env # 원하는 환경 이름
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_deployment: false
63 changes: 63 additions & 0 deletions .platform/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 33282;

events {
use epoll;
worker_connections 1024;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;


log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

include conf.d/*.conf;

map $http_upgrade $connection_upgrade {
default "upgrade";
}

upstream springboot {
server 127.0.0.1:8080;
keepalive 1024;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
proxy_pass http://springboot;
# CORS 관련 헤더 추가
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

access_log /var/log/nginx/access.log main;

client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;

# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: appstart
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ tasks.named('bootBuildImage') {
tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public enum ErrorStatus implements BaseErrorCode {
USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "USER4001", "사용자가 없습니다."),

// 오늘의 다짐 관련 에러
RESOLUTION_NOT_FOUND(HttpStatus.BAD_REQUEST, "RESOLUTION4001", "오늘의 다짐이 없습니다."),
RESOLUTION_NOT_FOUND(HttpStatus.BAD_REQUEST, "RESOLUTION4001", "해당하는 오늘의 다짐이 없습니다."),

//업무일지 관련 에러
WORKLOG_NOT_FOUND(HttpStatus.BAD_REQUEST, "WORKLOG4001", "해당하는 업무일지가 없습니다."),

// 회고 질문 관련 에러
QUESTION_NOT_FOUND(HttpStatus.BAD_REQUEST, "QUESTION4001", "해당하는 회고 질문이 없습니다."),
Expand All @@ -32,6 +35,10 @@ public enum ErrorStatus implements BaseErrorCode {
ANSWER_NOT_FOUND(HttpStatus.BAD_REQUEST, "ANSWER4001", "해당하는 회고 답변이 없습니다."),
ANSWER_BAD_MATCH(HttpStatus.BAD_REQUEST, "ANSWER4002", "해당하는 회고에 속하는 회고 답변이 아닙니다."),

// 피드 관련 에러
FEED_NOT_FOUND(HttpStatus.BAD_REQUEST, "FEED4001", "해당하는 워라벨 피드가 없습니다."),
FEED_NOT_BLANK(HttpStatus.BAD_REQUEST, "FEED4002", "워라벨 피드 내용은 공백일 수 없습니다."),

// 피드 사진 관련 에러
FEED_IMAGE_EXIST(HttpStatus.BAD_REQUEST, "FEEDIMAGE4001", "이미 해당 위치에 업로드된 워라벨 피드 사진이 있습니다."),
FEED_IMAGE_LOCATION_INVALID(HttpStatus.BAD_REQUEST, "FEEDIMAGE4002", "워라벨 피드 사진의 위치는 1에서 9 사이여야 합니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.onnoff.onnoff.apiPayload.exception.handler;

import com.onnoff.onnoff.apiPayload.code.BaseErrorCode;
import com.onnoff.onnoff.apiPayload.exception.GeneralException;

public class WorklogHandler extends GeneralException {
public WorklogHandler(BaseErrorCode errorCode){
super(errorCode);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/onnoff/onnoff/auth/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public void addInterceptors(InterceptorRegistry registry) {

registry.addInterceptor(new UserInterceptor(userService, jwtUtil))
.addPathPatterns("/**") // 스프링 경로는 /*와 /**이 다름
.excludePathPatterns("/swagger-ui/**", "/v3/api-docs/**", "/oauth2/**");
.excludePathPatterns("/swagger-ui/**", "/v3/api-docs/**", "/oauth2/**", "/on/**", "/health");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@RequiredArgsConstructor
public class JwtAuthFilter extends OncePerRequestFilter {
private final JwtTokenProvider jwtTokenProvider;
private final static String[] ignorePrefix = {"/swagger-ui", "/v3/api-docs", "/oauth2"};
private final static String[] ignorePrefix = {"/swagger-ui", "/v3/api-docs", "/oauth2", "/on", "/health"};
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
log.info("url ={}", request.getRequestURI());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.onnoff.onnoff.domain.common.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RootController {
@GetMapping("/health")
public String healthCheck(){
return "I'm healthy!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.onnoff.onnoff.domain.off.feed.controller;

import com.onnoff.onnoff.apiPayload.ApiResponse;
import com.onnoff.onnoff.domain.off.feed.converter.FeedConverter;
import com.onnoff.onnoff.domain.off.feed.dto.FeedRequestDTO;
import com.onnoff.onnoff.domain.off.feed.dto.FeedResponseDTO;
import com.onnoff.onnoff.domain.off.feed.entity.Feed;
import com.onnoff.onnoff.domain.off.feed.service.FeedService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequiredArgsConstructor
public class FeedController {

private final FeedService feedService;

@PostMapping("/feeds")
@Operation(summary = "워라벨 피드 추가 API", description = "새로운 워라벨 피드를 추가하는 API입니다.")
public ApiResponse<FeedResponseDTO.FeedResultDTO> addFeed(@RequestBody @Valid FeedRequestDTO.AddFeedDTO request) {
Feed feed = feedService.addFeed(request);
return ApiResponse.onSuccess(FeedConverter.toFeedResultDTO(feed));
}

@GetMapping("/feeds")
@Operation(summary = "워라벨 피드 조회 API",description = "특정한 날짜의 워라벨 피드를 조회하는 API입니다. Query String으로 사용자 아이디와 날짜를 입력해 주세요.")
public ApiResponse<List<FeedResponseDTO.FeedResultDTO>> getFeed(@RequestParam(name = "userId") Long userId, @RequestParam(name = "date") LocalDate date){
List<Feed> feedList = feedService.getFeed(userId, date);
return ApiResponse.onSuccess(feedList.stream().map(FeedConverter::toFeedResultDTO).toList());
}

@PatchMapping("/feeds")
@Operation(summary = "워라벨 피드 수정 API", description = "기존의 워라벨 피드를 수정하는 API입니다.")
public ApiResponse<FeedResponseDTO.FeedResultDTO> modifyFeed(@RequestBody @Valid FeedRequestDTO.ModifyFeedDTO request) {
Feed feed = feedService.modifyFeed(request);
return ApiResponse.onSuccess(FeedConverter.toFeedResultDTO(feed));
}

@DeleteMapping("/feeds/{feedId}")
@Operation(summary = "워라벨 피드 삭제 API",description = "기존의 워라벨 피드를 삭제하는 API입니다.")
public ApiResponse<?> deleteFeed(@PathVariable(name = "feedId") Long feedId){
feedService.deleteFeed(feedId);
return ApiResponse.onSuccess(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.onnoff.onnoff.domain.off.feed.converter;

import com.onnoff.onnoff.domain.off.feed.dto.FeedRequestDTO;
import com.onnoff.onnoff.domain.off.feed.dto.FeedResponseDTO;
import com.onnoff.onnoff.domain.off.feed.entity.Feed;
import com.onnoff.onnoff.domain.user.User;

public class FeedConverter {

public static Feed toFeed(FeedRequestDTO.AddFeedDTO request, User user) {
return Feed.builder()
.date(request.getDate())
.content(request.getContent())
.isChecked(false)
.user(user)
.build();
}

public static FeedResponseDTO.FeedResultDTO toFeedResultDTO(Feed feed) {
return FeedResponseDTO.FeedResultDTO.builder()
.feedId(feed.getId())
.date(feed.getDate())
.content(feed.getContent())
.isChecked(feed.getIsChecked())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.onnoff.onnoff.domain.off.feed.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PastOrPresent;
import jakarta.validation.constraints.Size;
import lombok.Getter;

import java.time.LocalDate;

public class FeedRequestDTO {

@Getter
public static class AddFeedDTO {
@NotNull
Long userId;
@NotNull
@PastOrPresent
LocalDate date;
@NotBlank
@Size(max = 30)
String content;
}

@Getter
public static class ModifyFeedDTO {
@NotNull
Long feedId;
LocalDate date;
@Size(max = 30)
String content;
Boolean isChecked;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.onnoff.onnoff.domain.off.feed.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

public class FeedResponseDTO {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class FeedResultDTO {
Long feedId;
LocalDate date;
String content;
Boolean isChecked;
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ public class Feed extends BaseEntity {
private String content;

@Column(columnDefinition = "boolean default false")
private Boolean checked;
private Boolean isChecked;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public void updateFeed(LocalDate date, String content, Boolean isChecked) {
if (date != null) {
this.date = date;
}
if (content != null) {
this.content = content;
}
if (isChecked != null) {
this.isChecked = isChecked;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.onnoff.onnoff.domain.off.feed.repository;

import com.onnoff.onnoff.domain.off.feed.entity.Feed;
import com.onnoff.onnoff.domain.user.User;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface FeedRepository extends JpaRepository<Feed, Long> {

List<Feed> findAllByUserAndDateOrderByCreatedAtAsc(User user, LocalDate date);
}
Loading

0 comments on commit 590b5b7

Please sign in to comment.