Skip to content

Commit

Permalink
Merge pull request #87 from kssumin/main
Browse files Browse the repository at this point in the history
[BE/FEAT] BE ci 설정
  • Loading branch information
kssumin authored Nov 24, 2023
2 parents f5e07c6 + 4cf0fbc commit ebcb7c5
Show file tree
Hide file tree
Showing 39 changed files with 435 additions and 147 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# github repository actions 페이지에 나타날 이름
name: Backend CI

# event trigger
# main 브랜치에 push, PR이 되었을 때 workflow 실행
on:
push:
branches: [ "main","be" ]
paths : 'BE/**'
pull_request:
branches: [ "main","be" ]
paths : 'BE/**'

defaults:
run:
working-directory: BE/eeos

jobs:
build:
runs-on: ubuntu-latest
steps:

# JDK setting : github actions에서 사용할 JDK 설정
- name: Set up JDK 17
- uses: actions/checkout@v3
with:
java-version: '17'
distribution: 'temurin'

# gradlew에 실행 권한을 부여합니다.
- name: Grant execute permisson for gradlew
run: chmod +x gradlew
shell : bash

# gradle caching - 빌드 시간 향상
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# gradle build
- name: Build with Gradle
working-directory : ./be/overflow
run: ./gradlew build -x test

- name: 테스트 결과를 PR에 코멘트로 등록합니다
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'

- name: 테스트 실패 시, 실패한 코드 라인에 Check 코멘트를 등록합니다
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
token: ${{ github.token }}

- name: build 실패 시 Slack으로 알립니다
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: 백엔드 빌드 실패 알림
fields: repo, message, commit, author, action, eventName, ref, workflow, job, took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
3 changes: 2 additions & 1 deletion BE/eeos/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ services:
ports:
- "13306:3306"
volumes: #볼륨 지정
- ./resources/local-develop-environment/mysql-init.d:/docker-entrypoint-initdb.d
- ./resources/local-develop-environment/mysql-init.d/:/docker-entrypoint-initdb.d
- ./resources/local-develop-environment/mysql-data:/var/lib/mysql
networks: #사용할 네트워크 지정
- eeos-network
backend:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,40 @@ create table program
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
program_content varchar(255) not null,
program_date timestamp not null,
program_content TEXT not null,
program_date TIMESTAMP not null,
program_title varchar(255) not null,
primary key (program_id)
) engine = InnoDB;

create table member
(
member_id bigint not null auto_increment,
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
member_name varchar(255) not null,
member_generation int not null,
member_id bigint not null auto_increment,
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
member_name varchar(255) not null,
member_generation BIGINT not null,
primary key (member_id)
) engine = InnoDB;
) engine = InnoDB;

create table attend
(
attend_id bigint not null auto_increment,
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
attend_program_id BIGINT not null,
attend_member_id BIGINT not null,
attend_status VARCHAR(40) not null,
primary key (attend_id)
) engine = InnoDB;

ALTER TABLE member
ADD INDEX idx_generation_name (member_generation, member_name);

ALTER TABLE attend
ADD INDEX idx_program (attend_program_id);

ALTER TABLE program
ADD INDEX idx_program_date (program_date);
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
use eeos;

insert into program (created_date, is_deleted, updated_date, program_content, program_date , program_title)
values
('2023-10-16 16:30:00.000000', false, '2023-10-16 16:30:00.000000', '프로그램 내용 1', '2023-10-16 16:30:01.000000', '프로그램 제목 1'),
('2023-10-16 16:31:00.000000', false, '2023-10-16 16:31:00.000000', '프로그램 내용 2', '2023-10-16 16:31:02.000000', '프로그램 제목 2'),
('2023-10-16 16:32:00.000000', false, '2023-10-16 16:32:00.000000', '프로그램 내용 3', '2023-10-16 16:32:03.000000', '프로그램 제목 3'),
('2023-10-16 16:33:00.000000', false, '2023-10-16 16:33:00.000000', '프로그램 내용 4', '2023-10-16 16:33:04.000000', '프로그램 제목 4'),
('2023-10-16 16:34:00.000000', false, '2023-10-16 16:34:00.000000', '프로그램 내용 5', '2023-10-16 16:34:05.000000', '프로그램 제목 5'),
('2023-10-16 16:35:00.000000', false, '2023-10-16 16:35:00.000000', '프로그램 내용 6', '2023-10-16 16:35:06.000000', '프로그램 제목 6'),
('2023-10-16 16:36:00.000000', false, '2023-10-16 16:36:00.000000', '프로그램 내용 7', '2023-10-16 16:36:07.000000', '프로그램 제목 7'),
('2023-10-16 16:37:00.000000', false, '2023-10-16 16:37:00.000000', '프로그램 내용 8', '2023-10-16 16:37:08.000000', '프로그램 제목 8'),
('2023-10-16 16:38:00.000000', false, '2023-10-16 16:38:00.000000', '프로그램 내용 9', '2023-10-16 16:38:09.000000', '프로그램 제목 9'),
('2023-10-16 16:39:00.000000', false, '2023-10-16 16:39:00.000000', '프로그램 내용 10', '2023-10-16 16:39:10.000000', '프로그램 제목 10');


insert into member (created_date, is_deleted, updated_date, member_name, member_generation)
values
('2023-10-16 16:40:00', false, '2023-10-16 16:40:00', '멤버 1', 20),
('2023-10-16 16:41:00', false, '2023-10-16 16:41:00', '멤버 2', 21),
('2023-10-16 16:42:00', false, '2023-10-16 16:42:00', '멤버 3', 23),
('2023-10-16 16:43:00', false, '2023-10-16 16:43:00', '멤버 4', 29),
('2023-10-16 16:44:00', false, '2023-10-16 16:44:00', '멤버 5', 19),
('2023-10-16 16:45:00', false, '2023-10-16 16:45:00', '멤버 6', 12),
('2023-10-16 16:46:00', false, '2023-10-16 16:46:00', '멤버 7', 13),
('2023-10-16 16:47:00', false, '2023-10-16 16:47:00', '멤버 8', 19),
('2023-10-16 16:48:00', false, '2023-10-16 16:48:00', '멤버 9', 19),
('2023-10-16 16:49:00', false, '2023-10-16 16:49:00', '멤버 10', 20);
('2023-10-16 16:40:00', false, '2023-10-16 16:40:00', '김수민', 20),
('2023-10-16 16:41:00', false, '2023-10-16 16:41:00', '강바다', 21),
('2023-10-16 16:42:00', false, '2023-10-16 16:42:00', '만두', 23),
('2023-10-16 16:43:00', false, '2023-10-16 16:43:00', '바다', 29),
('2023-10-16 16:44:00', false, '2023-10-16 16:44:00', '카리나', 19),
('2023-10-16 16:45:00', false, '2023-10-16 16:45:00', '사장님', 12),
('2023-10-16 16:46:00', false, '2023-10-16 16:46:00', '장현지', 13),
('2023-10-16 16:47:00', false, '2023-10-16 16:47:00', '박준수', 19),
('2023-10-16 16:48:00', false, '2023-10-16 16:48:00', '박지유', 19),
('2023-10-16 16:49:00', false, '2023-10-16 16:49:00', '스티브', 20);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@NoArgsConstructor
@Builder(toBuilder = true)
public class AttendInfoResponse implements AbstractResponseDto {
private Long id;
private Long memberId;
private Long generation;
private String name;
private String attendStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@

import com.blackcompany.eeos.attend.application.dto.AttendInfoResponse;
import com.blackcompany.eeos.attend.application.model.AttendStatus;
import com.blackcompany.eeos.member.application.model.MemberModel;
import com.blackcompany.eeos.member.persistence.MemberEntity;
import org.springframework.stereotype.Component;

@Component
public class AttendInfoConverter {
public AttendInfoResponse from(final MemberModel target, final AttendStatus attendStatus) {

public AttendInfoResponse from(final MemberEntity source, final AttendStatus attendStatus) {
return AttendInfoResponse.builder()
.id(target.getId())
.generation(target.getGeneration())
.name(target.getName())
.memberId(source.getId())
.generation(source.getGeneration())
.name(source.getName())
.attendStatus(attendStatus.getStatus())
.build();
}

public AttendInfoResponse from(final MemberEntity source, final String status) {
return AttendInfoResponse.builder()
.memberId(source.getId())
.generation(source.getGeneration())
.name(source.getName())
.attendStatus(status)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.blackcompany.eeos.attend.application.dto.converter.AttendInfoConverter;
import com.blackcompany.eeos.attend.application.exception.NotFoundAttendException;
import com.blackcompany.eeos.attend.application.model.AttendModel;
import com.blackcompany.eeos.attend.application.model.AttendStatus;
import com.blackcompany.eeos.attend.application.model.converter.AttendEntityConverter;
import com.blackcompany.eeos.attend.application.usecase.ChangeStatusUsecase;
import com.blackcompany.eeos.attend.application.usecase.GetAttendantInfoUsecase;
import com.blackcompany.eeos.attend.persistence.AttendEntity;
import com.blackcompany.eeos.attend.persistence.AttendRepository;
import com.blackcompany.eeos.member.application.service.MemberService;
import com.blackcompany.eeos.member.persistence.MemberRepository;
import com.blackcompany.eeos.program.application.service.ProgramValidService;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -24,37 +25,42 @@
public class AttendService implements GetAttendantInfoUsecase, ChangeStatusUsecase {

private final AttendRepository attendRepository;

private final MemberRepository memberRepository;
private final ProgramValidService programValidService;
private final AttendInfoConverter infoConverter;
private final AttendEntityConverter entityConverter;
private final MemberService memberService;
private final AttendEntityConverter attendEntityConverter;

@Override
public List<AttendInfoResponse> findAttendInfo(final Long programId) {
programValidService.validate(programId);

List<AttendEntity> attendEntities = attendRepository.findAllByProgramId(programId);
return attendEntities.stream()
.map(
attendEntity ->
infoConverter.from(
memberService.findMemberInfo(attendEntity.getId()), attendEntity.getStatus()))
return memberRepository.findMembersByProgramId(programId).stream()
.map(member -> infoConverter.from(member, getAttendStatus(member.getId(), programId)))
.collect(Collectors.toList());
}

private AttendStatus getAttendStatus(final Long memberId, final Long programId) {
return attendRepository
.findByProgramIdAndMemberId(programId, memberId)
.map(AttendEntity::getStatus)
.orElseThrow(NotFoundAttendException::new);
}

@Override
public List<AttendInfoResponse> findAttendInfo(final Long programId, final String status) {
programValidService.validate(programId);

List<AttendEntity> attendEntities = attendRepository.findAllByProgramId(programId);
AttendStatus attendStatus = AttendStatus.findByAttendStatus(status);

List<Long> statusMember =
attendRepository.findAllByProgramIdAndStatus(programId, attendStatus).stream()
.map(AttendEntity::getMemberId)
.collect(Collectors.toList());

return attendEntities.stream()
.map(entityConverter::from)
.filter(model -> model.isSame(status))
.map(
attendEntity ->
infoConverter.from(
memberService.findMemberInfo(attendEntity.getId()), attendEntity.getStatus()))
return memberRepository.findMembersByProgramId(programId).stream()
.filter(member -> statusMember.contains(member.getId()))
.map(member -> infoConverter.from(member, status))
.collect(Collectors.toList());
}

Expand All @@ -64,12 +70,12 @@ public void changeStatus(final ChangeStatusRequest request, final Long programId
AttendModel model =
attendRepository
.findByProgramIdAndMemberId(programId, request.getMemberId())
.map(entityConverter::from)
.map(attendEntityConverter::from)
.orElseThrow(NotFoundAttendException::new);

model.isSame(request.getBeforeAttendStatus());

model.changeStatus(request.getAfterAttendStatus());
attendRepository.save(entityConverter.toEntity(model));
attendRepository.save(attendEntityConverter.toEntity(model));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -24,7 +25,9 @@
@ToString
@SuperBuilder(toBuilder = true)
@Entity
@Table(name = AttendEntity.ENTITY_PREFIX)
@Table(
name = AttendEntity.ENTITY_PREFIX,
indexes = @Index(name = "idx_program", columnList = "attend_program_id"))
public class AttendEntity extends BaseEntity {
public static final String ENTITY_PREFIX = "attend";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.blackcompany.eeos.attend.persistence;

import com.blackcompany.eeos.attend.application.model.AttendStatus;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AttendRepository extends JpaRepository<AttendEntity, Long> {
List<AttendEntity> findAllByProgramId(Long programId);
List<AttendEntity> findAllByProgramIdAndStatus(Long programId, AttendStatus status);

Optional<AttendEntity> findByProgramIdAndMemberId(Long programId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AttendController {
private final GetAttendantInfoUsecase getAttendantInfoUsecase;
private final ChangeStatusUsecase changeStatusUsecase;

@GetMapping("/candidate/program/{programId}")
@GetMapping("/candidate/programs/{programId}")
public ApiResponse<SuccessBody<List<AttendInfoResponse>>> findAttendMemberInfo(
@PathVariable("programId") Long programId) {
List<AttendInfoResponse> response = getAttendantInfoUsecase.findAttendInfo(programId);
Expand All @@ -43,7 +43,7 @@ public ApiResponse<SuccessBody<Void>> changeAttendStatus(

@GetMapping("/programs/{programId}/members")
public ApiResponse<SuccessBody<List<AttendInfoResponse>>> getAttendInfoByProgram(
@PathVariable("programId") Long programId, @RequestParam("status") String status) {
@PathVariable("programId") Long programId, @RequestParam("attendStatus") String status) {
List<AttendInfoResponse> response = getAttendantInfoUsecase.findAttendInfo(programId, status);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blackcompany.eeos.common.presentation.respnose;

import com.blackcompany.eeos.program.application.dto.PageResponse;
import java.util.List;
import lombok.experimental.UtilityClass;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import lombok.experimental.UtilityClass;

Expand Down Expand Up @@ -32,9 +33,7 @@ public static LocalDate toLocalDate(Long epochSecond) {
return null;
}

return Instant.ofEpochSecond(epochSecond)
.atZone(ZoneOffset.of(KOREA_ZONE_OFFSET))
.toLocalDate();
return Instant.ofEpochSecond(epochSecond).atZone(ZoneId.of("Asia/Seoul")).toLocalDate();
}

public static LocalDateTime toLocalDateTime(Long epochSecond) {
Expand Down
Loading

0 comments on commit ebcb7c5

Please sign in to comment.