Skip to content

Commit

Permalink
Merge pull request #26 from prgrms-web-devcourse-final-project/feat/#24
Browse files Browse the repository at this point in the history
…-cicd-swagger-설정

feat: cicd swagger 설정
  • Loading branch information
kang-ye-jin authored Nov 29, 2024
2 parents 74faab8 + e6e042a commit ec8473f
Show file tree
Hide file tree
Showing 24 changed files with 532 additions and 514 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI/CD

on:
push:
branches: [ develop ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

# application.yml 파일 생성
- run: touch ./src/main/resources/application.yml
- run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml

# application-secret.yml 파일 생성
- run: touch ./src/main/resources/application-secret.yml
- run: echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application-secret.yml

# 생성된 파일들을 아티팩트로 업로드
- uses: actions/upload-artifact@v3
with:
name: application-files
path: |
./src/main/resources/application.yml
./src/main/resources/application-secret.yml
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build

- name: Get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"

# 배포용 패키지 경로 설정
- name: Set artifact path
run: |
artifact=$(ls ./build/libs/*.jar | head -n 1)
echo "artifact=$artifact" >> $GITHUB_ENV
# 빈스토크 배포
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: flowday
environment_name: Flowday-env
version_label: github-action-${{ steps.current-time.outputs.time }}
region: ap-northeast-2
deployment_package: ${{ env.artifact }}
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ repositories {
}

dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'mysql:mysql-connector-java:8.0.33'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// websocket
Expand Down Expand Up @@ -68,3 +70,7 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}
Original file line number Diff line number Diff line change
@@ -1,93 +1,75 @@
package org.example.flowday.domain.course.course.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.flowday.domain.course.course.dto.CourseReqDTO;
import org.example.flowday.domain.course.course.dto.CourseResDTO;
import org.example.flowday.domain.course.course.dto.PageReqDTO;
import org.example.flowday.domain.course.course.entity.Course;
import org.example.flowday.domain.course.course.exception.CourseException;
import org.example.flowday.domain.course.course.repository.CourseRepository;
import org.example.flowday.domain.course.course.service.CourseService;
import org.example.flowday.domain.course.spot.dto.SpotReqDTO;
import org.example.flowday.domain.member.exception.MemberException;
import org.example.flowday.domain.member.repository.MemberRepository;
import org.example.flowday.global.security.util.SecurityUser;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/courses")
@Tag(name = "Course", description = "코스 관련 api")
public class CourseController {

private final CourseService courseService;
private final MemberRepository memberRepository;
private final CourseRepository courseRepository;

// 코스 생성
@Operation(summary = "생성")
@PostMapping
public ResponseEntity<CourseResDTO> createCourse(@RequestBody CourseReqDTO courseReqDTO) {
return ResponseEntity.ok(courseService.saveCourse(courseReqDTO));
}

// 코스 조회
@Operation(summary = "조회", description = "코스 단일 조회")
@GetMapping("/{courseId}")
public ResponseEntity<CourseResDTO> getCourse(@PathVariable Long courseId) {
return ResponseEntity.ok(courseService.findCourse(courseId));
}

// 코스 수정
@Operation(summary = "수정", description = "파트너가 수정 시에도 요청 DTO에는 memberId는 작성자의 id")
@PutMapping("/{courseId}")
public ResponseEntity<CourseResDTO> updateCourse(
@PathVariable Long courseId,
@RequestBody CourseReqDTO courseReqDTO,
Authentication authentication
@AuthenticationPrincipal SecurityUser user
) {
Long id = memberRepository.findIdByLoginId(authentication.getName()).orElseThrow(MemberException.MEMBER_NOT_FOUND::getMemberTaskException);
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if (!id.equals(course.getMember().getId()) && !id.equals(course.getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

return ResponseEntity.ok(courseService.updateCourse(courseId, courseReqDTO));
return ResponseEntity.ok(courseService.updateCourse(user.getId(), courseId, courseReqDTO));
}

// 코스에 장소 1개 추가
@Operation(summary = "장소 1개 추가", description = "코스에 장소를 1개 추가 / sequence(순서)는 마지막으로 배정")
@PostMapping("/{courseId}")
public ResponseEntity<CourseResDTO> addSpotToCourse(
@PathVariable Long courseId,
@RequestBody SpotReqDTO spotReqDTO,
Authentication authentication
@AuthenticationPrincipal SecurityUser user
) {
Long id = memberRepository.findIdByLoginId(authentication.getName()).orElseThrow(MemberException.MEMBER_NOT_FOUND::getMemberTaskException);
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if (!id.equals(course.getMember().getId()) && !id.equals(course.getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

return ResponseEntity.ok(courseService.addSpot(courseId, spotReqDTO));
return ResponseEntity.ok(courseService.addSpot(user.getId(), courseId, spotReqDTO));
}

// 코스 삭제
@Operation(summary = "삭제")
@DeleteMapping("/{course_id}")
public ResponseEntity<Void> deleteCourse(
@PathVariable("course_id") Long courseId,
Authentication authentication
@AuthenticationPrincipal SecurityUser user
) {
Long id = memberRepository.findIdByLoginId(authentication.getName()).orElseThrow(MemberException.MEMBER_NOT_FOUND::getMemberTaskException);

if(!id.equals(courseRepository.findById(courseId).get().getMember().getId())) {
throw CourseException.FORBIDDEN.get();
}

courseService.removeCourse(courseId);

courseService.removeCourse(user.getId(), courseId);
return ResponseEntity.noContent().build();
}

@Operation(summary = "위시 플레이스 + 코스 목록 조회", description = "나와 (파트너의) 위시플레이스와 나와 (파트너의 COUPLE 상태) 코스 목록")
// 회원 별 위시 플레이스, 코스 목록 조회
@GetMapping("/member/{memberId}")
public ResponseEntity<Page<Object>> CourseListByMember(
Expand All @@ -100,19 +82,13 @@ public ResponseEntity<Page<Object>> CourseListByMember(
}

// 그만 보기 시 상대방의 코스 비공개로 상태 변경
@Operation(summary = "비공개로 상태 변경", description = "(그만 보기) 상대방의 코스를 PRIVATE으로 상태 변경")
@PatchMapping("/{courseId}/private")
public ResponseEntity<Void> updateCourseStatusToPrivate(
@PathVariable Long courseId,
Authentication authentication
@AuthenticationPrincipal SecurityUser member
) {
Long id = memberRepository.findIdByLoginId(authentication.getName()).orElseThrow(MemberException.MEMBER_NOT_FOUND::getMemberTaskException);

if (!id.equals(courseRepository.findById(courseId).get().getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

courseService.updateCourseStatusToPrivate(courseId);

courseService.updateCourseStatusToPrivate(member.getId(), courseId);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ public CourseResDTO findCourse(Long courseId) {
}

// 코스 수정
public CourseResDTO updateCourse(Long courseId, CourseReqDTO courseReqDTO) {
public CourseResDTO updateCourse(Long userId, Long courseId, CourseReqDTO courseReqDTO) {
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if (!userId.equals(course.getMember().getId()) && !userId.equals(course.getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

try {
course.changeTitle(courseReqDTO.getTitle());
course.changeDate(courseReqDTO.getDate());
Expand Down Expand Up @@ -158,9 +162,13 @@ public CourseResDTO updateCourse(Long courseId, CourseReqDTO courseReqDTO) {
}

// 코스에 장소 1개 추가
public CourseResDTO addSpot(Long courseId, SpotReqDTO spotReqDTO) {
public CourseResDTO addSpot(Long userId, Long courseId, SpotReqDTO spotReqDTO) {
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if (!userId.equals(course.getMember().getId()) && !userId.equals(course.getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

try {
List<Integer> existingSequences = spotRepository.findAllByCourseIdAndVoteIsNull(courseId).stream()
.map(Spot::getSequence)
Expand Down Expand Up @@ -193,9 +201,13 @@ public CourseResDTO addSpot(Long courseId, SpotReqDTO spotReqDTO) {
}

// 코스 삭제
public CourseResDTO removeCourse(Long courseId) {
public CourseResDTO removeCourse(Long userId, Long courseId) {
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if(!userId.equals(courseRepository.findById(courseId).get().getMember().getId())) {
throw CourseException.FORBIDDEN.get();
}

courseRepository.delete(course);

return new CourseResDTO(course, null);
Expand Down Expand Up @@ -249,9 +261,13 @@ public Page<Object> findWishPlaceAndCourseListByMember(Long memberId, PageReqDTO
}

// 그만 보기 시 상대방의 코스 비공개로 상태 변경
public void updateCourseStatusToPrivate(Long courseId) {
public void updateCourseStatusToPrivate(Long memberId, Long courseId) {
Course course = courseRepository.findById(courseId).orElseThrow(CourseException.NOT_FOUND::get);

if (!memberId.equals(courseRepository.findById(courseId).get().getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

try {
course.changeStatus(Status.PRIVATE);
courseRepository.save(course);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.example.flowday.domain.course.spot.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.flowday.domain.course.spot.dto.SpotResDTO;
import org.example.flowday.domain.course.spot.service.SpotService;
Expand All @@ -14,12 +16,14 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/spots")
@Tag(name = "Spot", description = "장소 관련 api")
public class SpotController {

private final SpotService spotService;

// 지역별 인기 장소 top4
@GetMapping("/top4")
@Operation(summary = "top4 조회", description = "지역별 인기 장소 top4 조회")
@GetMapping
public ResponseEntity<List<SpotResDTO>> getTopSpotsByCity(@RequestParam String city) {
List<SpotResDTO> topSpots = spotService.getTopSpotsByCity(city);
return ResponseEntity.ok(topSpots);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
package org.example.flowday.domain.course.vote.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.flowday.domain.course.course.dto.CourseResDTO;
import org.example.flowday.domain.course.course.entity.Course;
import org.example.flowday.domain.course.course.exception.CourseException;
import org.example.flowday.domain.course.course.repository.CourseRepository;
import org.example.flowday.domain.course.vote.dto.VoteReqDTO;
import org.example.flowday.domain.course.vote.dto.VoteResDTO;
import org.example.flowday.domain.course.vote.service.VoteService;
import org.example.flowday.domain.member.exception.MemberException;
import org.example.flowday.domain.member.repository.MemberRepository;
import org.example.flowday.global.security.util.SecurityUser;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/votes")
@Tag(name = "Vote", description = "투표 관련 api")
public class VoteController {

private final VoteService voteService;
private final MemberRepository memberRepository;
private final CourseRepository courseRepository;

// 투표 생성
@Operation(summary = "생성", description = "알림 도메인 완성 시 변경 예정")
@PostMapping
public ResponseEntity<VoteResDTO> createVote(
@RequestBody VoteReqDTO voteReqDTO,
Authentication authentication
@AuthenticationPrincipal SecurityUser member
) {
Long id = memberRepository.findIdByLoginId(authentication.getName()).orElseThrow(MemberException.MEMBER_NOT_FOUND::getMemberTaskException);
Course course = courseRepository.findById(voteReqDTO.getCourseId()).orElseThrow(CourseException.NOT_FOUND::get);

if (!id.equals(course.getMember().getId()) && !id.equals(course.getMember().getPartnerId())) {
throw CourseException.FORBIDDEN.get();
}

return ResponseEntity.ok(voteService.saveVote(voteReqDTO));
return ResponseEntity.ok(voteService.saveVote(member.getId(), voteReqDTO));
}

// 투표 조회
@Operation(summary = "조회")
@GetMapping("/{voteId}")
public ResponseEntity<VoteResDTO> getVote(@PathVariable Long voteId) {
return ResponseEntity.ok(voteService.findVote(voteId));
}

// 투표 완료 후 코스 수정
@PutMapping("/{voteId}/spots/{spotId}")
@Operation(summary = "투표 후 코스 수정", description = "파트너가 투표한 장소를 코스에 추가")
@PutMapping("/{voteId}/spot/{spotId}")
public ResponseEntity<CourseResDTO> updateCourseByVote(@PathVariable Long voteId, @PathVariable Long spotId) {
return ResponseEntity.ok(voteService.updateCourseByVote(voteId, spotId));
}
Expand Down
Loading

0 comments on commit ec8473f

Please sign in to comment.