Skip to content

Commit

Permalink
✨ feat: 7차 배포
Browse files Browse the repository at this point in the history
✨ feat: 7차 배포
  • Loading branch information
sunnyineverywhere authored Sep 22, 2023
2 parents 9e59888 + f74fd03 commit d632169
Show file tree
Hide file tree
Showing 32 changed files with 421 additions and 35 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ jobs:

- name: create application.yml in mail
run: touch ./snapspot-admin/src/main/resources/application-mail.yml
&& echo "${{secrets.APPLICATION_MAIL}}" > ./snapspot-mail/src/main/resources/application-mail.yml

&& echo "${{secrets.APPLICATION_MAIL}}" > ./snapspot-mail/src/main/resources/application-mail.yml

- name: create application.yml in batch
run: touch ./snapspot-batch/src/main/resources/application.yml
&& echo "${{secrets.APPLICATION_BATCH}}" > ./snapspot-batch/src/main/resources/application.yml

- uses: actions/upload-artifact@v2
with:
name: application-domain.yml
Expand All @@ -83,6 +87,11 @@ jobs:
name: application-mail.yml
path: ./snapspot-mail/src/main/resources/application-mail.yml

- uses: actions/upload-artifact@v2
with:
name: application.yml
path: ./snapspot-batch/src/main/resources/application.yml

- name: Grant execute permission for gradlew
run: chmod +x gradlew

Expand Down
22 changes: 15 additions & 7 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
REPOSITORY=/home/ubuntu/snapspot
cd $REPOSITORY
#REPOSITORY=/home/ubuntu/snapspot
# cd $REPOSITORY
cd ../

CURRENT_CONTAINER=$(sudo docker ps)

Expand All @@ -8,14 +9,21 @@ then
echo "> 현재 실행중인 도커 컨테이너가 없습니다."
else
echo "> kill -15 $CURRENT_CONTAINER"
sudo sudo docker stop snapspot-server
sudo docker stop snapspot-server
sudo docker stop snapspot-batch-server
sleep 10
sudo sudo docker rm snapspot-server
sudo docker rm snapspot-server
sudo docker rm snapspot-batch-server
sleep 5
fi

echo "> 도커 이미지 빌드"
echo "> 도커 이미지 빌드: api"
sudo docker build -t snapspot-api .

echo "> 도커 컨테이너 올리기"
sudo docker run -d -p 80:8080 --name snapspot-server snapspot-api
echo "> snapspot-api 도커 컨테이너 올리기"
sudo docker run -d -p 80:8080 --name snapspot-server snapspot-api

echo "> 도커 이미지 빌드: batch"
cd ./snapspot-batch
sudo docker build -t snapspot-batch .
sudo docker run -d -p 8080:8080 --name snapspot-batch-server snapspot-batch
1 change: 0 additions & 1 deletion snapspot-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ dependencies {
implementation project(":snapspot-common")
implementation project(":snapspot-admin")
implementation project(":snapspot-mail")
implementation project(":snapspot-batch")
implementation 'org.springframework.boot:spring-boot-starter-validation'
}
15 changes: 9 additions & 6 deletions snapspot-api/src/main/java/snap/ApiApplication.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package snap;

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@EntityScan(basePackages = {"snap"})
@EnableJpaRepositories(basePackages = {"snap"})
@EnableBatchProcessing
@EnableScheduling
@SpringBootApplication
public class ApiApplication {

@PostConstruct
public void started() {
// timezone UTC 셋팅
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}

public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
Expand Down
30 changes: 30 additions & 0 deletions snapspot-api/src/main/java/snap/api/photo/SnapPhotoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package snap.api.photo;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import snap.api.photo.dto.SnapPhotoRequestDto;
import snap.api.photo.dto.SnapPhotoResponseDto;
import snap.domains.member.entity.Member;
import snap.resolver.AuthMember;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/photos")
public class SnapPhotoController {

private final SnapPhotoService snapPhotoService;

@PostMapping
public ResponseEntity<SnapPhotoResponseDto> photoRegister(@AuthMember Member member, @RequestBody SnapPhotoRequestDto requestDto) {
return new ResponseEntity<>(snapPhotoService.createPhoto(member, requestDto), HttpStatus.CREATED);
}

@GetMapping
public ResponseEntity<List<SnapPhotoResponseDto>> photoList(@AuthMember Member member) {
return new ResponseEntity<>(snapPhotoService.findPhotoListByMember(member), HttpStatus.OK);
}
}
31 changes: 31 additions & 0 deletions snapspot-api/src/main/java/snap/api/photo/SnapPhotoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package snap.api.photo;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import snap.api.photo.dto.SnapPhotoRequestDto;
import snap.api.photo.dto.SnapPhotoResponseDto;
import snap.domains.member.entity.Member;
import snap.domains.photo.service.SnapPhotoDomainService;
import snap.domains.photographer.entity.Photographer;
import snap.domains.photographer.service.PhotographerDomainService;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class SnapPhotoService {

private final SnapPhotoDomainService snapPhotoDomainService;
private final PhotographerDomainService photographerDomainService;

public SnapPhotoResponseDto createPhoto(Member member, SnapPhotoRequestDto requestDto) {
Photographer photographer = photographerDomainService.findById(requestDto.getPhotographerId());
return new SnapPhotoResponseDto(snapPhotoDomainService.createPhoto(member, requestDto.getImageUrl(), requestDto.getPhotoDate(),
requestDto.getLocation(), photographer, requestDto.getTag1(), requestDto.getTag2(), requestDto.getTag3()));
}

public List<SnapPhotoResponseDto> findPhotoListByMember(Member member) {
return snapPhotoDomainService.findPhotoListByMember(member).stream().map(SnapPhotoResponseDto::new).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package snap.api.photo.dto;

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

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SnapPhotoRequestDto {
private String imageUrl;
private LocalDateTime photoDate;
private String location;
private Long photographerId;
private String tag1;
private String tag2;
private String tag3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package snap.api.photo.dto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import snap.domains.photo.entity.SnapPhoto;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SnapPhotoResponseDto {
private Long snapPhotoId;
private String imageUrl;
private LocalDateTime photoDate;
private String location;
private Long photographerId;
private String photographerName;
private String tag1;
private String tag2;
private String tag3;

public SnapPhotoResponseDto(SnapPhoto snapPhoto) {
this.snapPhotoId = snapPhoto.getSnapPhotoId();
this.imageUrl = snapPhoto.getImageUrl();
this.photoDate = snapPhoto.getPhotoDate();
this.location = snapPhoto.getLocation();
this.photographerId = snapPhoto.getPhotographer().getPhotographerId();
this.photographerName = snapPhoto.getPhotographer().getMember().getNickname();
this.tag1 = snapPhoto.getTag1();
this.tag2 = snapPhoto.getTag2();
this.tag3 = snapPhoto.getTag3();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ResponseEntity<List<PhotographerSimpleDto>> photographerFindByTag(@Reques
}

@GetMapping
public ResponseEntity<List<PhotographerSimpleDto>> photographerList(PhotographerFilterReq filterReq, @PageableDefault(size = 6) Pageable pageable){
public ResponseEntity<List<PhotographerSimpleDto>> photographerList(PhotographerFilterReq filterReq, @PageableDefault(size = 15) Pageable pageable){
return new ResponseEntity<>(photographerService.findByFilter(filterReq, pageable), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Sort;
import snap.api.photographer.dto.response.PhotographerResponseDto;
import snap.domains.photographer.entity.Photographer;
import snap.domains.review.entity.Review;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -20,6 +22,6 @@ public class PhotographerReviewResponseDto {
public PhotographerReviewResponseDto(List<Review> entities) {
this.totalReview = entities.size();
this.averageScore = (entities.stream().mapToDouble(Review::getScore).sum() / entities.size());
this.reviews = entities.stream().map(ReviewResponseDto::new).toList();
this.reviews = entities.stream().map(ReviewResponseDto::new).sorted(Comparator.comparing(ReviewResponseDto::getScore).reversed()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class ReviewRequestDto {
private UUID planId;
private Integer score;
private String title;
private String comment;
private String image;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public class ReviewResponseDto {
private PlanResponseDto plan;
private Integer score;
private String image;
private String title;
private String comment;

public ReviewResponseDto(Review entity) {
this.reviewId = entity.getReviewId();
this.plan = new PlanResponseDto(entity.getPlan());
this.score = entity.getScore();
this.image = entity.getImage();
this.title = entity.getTitle();
this.comment = entity.getComment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ReviewService {
public void createReview(Member member, ReviewRequestDto request) {
Plan plan = planDomainService.findByPlanIdAndMember(request.getPlanId(), member);
if (plan.getStatus().equals(Status.DELIVERY)) {
reviewDomainService.createReview(plan, request.getImage(), request.getScore(), request.getComment());
reviewDomainService.createReview(plan, request.getImage(), request.getScore(), request.getTitle(), request.getComment());
} else {
throw new IllegalArgumentException("사진 전달이 완료되지 않은 촬영입니다.");
}
Expand Down
9 changes: 9 additions & 0 deletions snapspot-batch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM azul/zulu-openjdk:17

ARG JAR_FILE=./build/libs/*.jar

COPY ${JAR_FILE} batch.jar

EXPOSE 8080

ENTRYPOINT ["java","-jar","batch.jar"]
4 changes: 2 additions & 2 deletions snapspot-batch/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bootJar { enabled = false }
jar { enabled = true }
bootJar { enabled = true }
jar { enabled = false }

dependencies {
implementation project(":snapspot-domain")
Expand Down
29 changes: 29 additions & 0 deletions snapspot-batch/src/main/java/snap/batch/BatchApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package snap.batch;

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@EnableBatchProcessing
@EnableScheduling
@EntityScan(basePackages = {"snap.domains"})
@EnableJpaRepositories(basePackages = {"snap.domains"})
@SpringBootApplication
public class BatchApplication {

@PostConstruct
public void started() {
// timezone UTC 셋팅
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}

public static void main(String[] args) {
SpringApplication.run(BatchApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package snap.batch.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan({"snap"})
class ComponentScanConfiguration {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import snap.batch.service.JobPlanService;
import snap.domains.plan.service.PlanDomainService;

@Slf4j
Expand All @@ -23,7 +23,8 @@ public class JobConfiguration {

private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
private final PlanDomainService planDomainService;
private final JobPlanService planService;


@Bean
public Job job() {
Expand All @@ -37,7 +38,7 @@ public Job job() {
public Step step1() {
return stepBuilderFactory.get("step1")
.tasklet((stepContribution, chunkContext) -> {
planDomainService.updateStateOfToday();
planService.updateStateOfToday();
return RepeatStatus.FINISHED;
}).build();
}
Expand All @@ -46,7 +47,7 @@ public Step step1() {
public Step step2() {
return stepBuilderFactory.get("step1")
.tasklet((stepContribution, chunkContext) -> {
planDomainService.updateStateOfComplete();
planService.updateStateOfComplete();
return RepeatStatus.FINISHED;
}).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class JobScheduler {
private final JobLauncher jobLauncher;
private final JobConfiguration jobConfiguration;

@Scheduled(cron = "0 0 0 * * *")
@Scheduled(cron = "0 51 19 * * *")
public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
Map<String, JobParameter> confMap = new HashMap<>();
log.info("start job");
Expand Down
Loading

0 comments on commit d632169

Please sign in to comment.