Skip to content

Commit

Permalink
Merge pull request #348 from Team-Smeme/feature_#347
Browse files Browse the repository at this point in the history
infra: dev 서버 재구축
  • Loading branch information
thguss authored Oct 18, 2024
2 parents 4a3682e + d3c55b4 commit e4acee0
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 97 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

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

steps:
- name: Checkout
Expand All @@ -22,18 +22,16 @@ jobs:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set FCM_JSON_PATH
run: |
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/ \
smeem_fcm_dev.json" >> $GITHUB_ENV
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
- name: Create FireBase JSON file From AWS
run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_DEV }} ${{ env.FCM_JSON_PATH }}

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ${{ secrets.AWS_REGION }}
aws-region: ap-northeast-2
# AWS 자격 증명 설정

- name: Set FCM JSON File Path
run: |
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/ \
smeem_fcm_dev.json" >> $GITHUB_ENV
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
# FCM JSON 파일 위치 경로 설정

- name: Create FCM JSON File from AWS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.smeem.application.domain.diary;

import com.smeem.application.domain.generic.LangType;
import com.smeem.application.domain.member.Member;
import com.smeem.application.domain.topic.Topic;
import com.smeem.common.exception.ExceptionCode;
import com.smeem.common.exception.SmeemException;
import lombok.Builder;
Expand All @@ -16,8 +14,7 @@ public class Diary {
private Long id;
private String content;
private LangType targetLang;
private Topic topic;
private Member member;
private Long topicId;
private long memberId;
private LocalDateTime createdAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.badge.BadgeType;
import com.smeem.application.domain.member.Member;
import com.smeem.application.domain.topic.Topic;
import com.smeem.application.port.input.DiaryUseCase;
import com.smeem.application.port.input.dto.request.diary.WriteDiaryRequest;
import com.smeem.application.port.input.dto.response.diary.RetrieveDiariesResponse;
Expand All @@ -23,6 +24,7 @@
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class DiaryService implements DiaryUseCase {
private final CorrectionPort correctionPort;
private final DiaryPort diaryPort;
private final MemberPort memberPort;
private final BadgePort badgePort;
Expand All @@ -32,9 +34,11 @@ public class DiaryService implements DiaryUseCase {

@Transactional
public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) {
val member = memberPort.findById(memberId);
val topic = request.topicId() != null ? topicPort.findById(request.topicId()) : null;
val savedDiary = diaryPort.save(request.toDomain(member, topic));
Member member = memberPort.findById(memberId);
if (request.topicId() != null) {
topicPort.checkValidation(request.topicId());
}
Diary savedDiary = diaryPort.save(request.toDomain(member));

val diaryWrittenYesterday = diaryPort.isExistByMemberAndYesterday(memberId);
memberPort.update(member.updateDiaryComboCount(diaryWrittenYesterday));
Expand All @@ -60,19 +64,25 @@ private List<Badge> acquireBadgeOfWritingDiary(Member member) {
}

public RetrieveDiaryResponse retrieveDiary(long diaryId) {
return RetrieveDiaryResponse.of(diaryPort.findByIdJoinMemberAndTopic(diaryId));
Diary diary = diaryPort.findById(diaryId);
Topic topic = diary.getTopicId() != null ? topicPort.findById(diary.getTopicId()) : null;
Member member = memberPort.findById(diary.getMemberId());
List<Correction> corrections = correctionPort.findByDiary(diaryId);
return RetrieveDiaryResponse.of(diary, topic, member, corrections);
}

@Transactional
public void modifyDiary(long diaryId, WriteDiaryRequest request) {
val foundDiary = diaryPort.findById(diaryId);
public void modifyDiary(long memberId, long diaryId, WriteDiaryRequest request) {
Diary foundDiary = diaryPort.findById(diaryId);
foundDiary.validateDiaryOwnership(memberId);
diaryPort.update(request.toDomain(foundDiary));
correctionPort.deleteByDiary(diaryId);
}

@Transactional
public void deleteDiary(long diary) {
diaryPort.softDelete(diary);
//TODO: 코칭 정보 삭제
public void deleteDiary(long diaryId) {
diaryPort.softDelete(diaryId);
correctionPort.deleteByDiary(diaryId);
}

public RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface DiaryUseCase {
WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request);
RetrieveDiaryResponse retrieveDiary(long diaryId);
void modifyDiary(long diaryId, WriteDiaryRequest request);
void modifyDiary(long memberId, long diaryId, WriteDiaryRequest request);
void deleteDiary(long diary);
RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate);
void deleteExpiredDiaries(int duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.smeem.application.domain.diary.Diary;
import com.smeem.application.domain.member.Member;
import com.smeem.application.domain.topic.Topic;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.NonNull;

Expand All @@ -14,21 +13,21 @@ public record WriteDiaryRequest(
Long topicId
) {

public Diary toDomain(Member member, Topic topic) {
public Diary toDomain(Member member) {
return Diary.builder()
.content(content)
.targetLang(member.getTargetLang())
.topic(topic)
.member(member)
.topicId(topicId)
.memberId(member.getId())
.build();
}

public Diary toDomain(Diary diary) {
public Diary toDomain(Diary originDiary) {
return Diary.builder()
.id(diary.getId())
.content(content)
.targetLang(diary.getTargetLang())
.topic(Topic.builder().id(topicId).build())
.targetLang(originDiary.getTargetLang())
.topicId(topicId)
.memberId(originDiary.getMemberId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.smeem.application.port.input.dto.response.diary;

import com.smeem.application.domain.diary.Correction;
import com.smeem.application.domain.diary.Diary;
import com.smeem.application.domain.member.Member;
import com.smeem.application.domain.topic.Topic;
import com.smeem.common.util.SmeemConverter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
Expand All @@ -18,18 +24,24 @@ public record RetrieveDiaryResponse(
@Schema(description = "일기 작성일")
String createdAt,
@Schema(description = "일기 작성자 닉네임")
String username
String username,
@Schema(description = "코칭 결과 정보")
List<Correction> corrections
) {

public static RetrieveDiaryResponse of(Diary diary) {
public static RetrieveDiaryResponse of(
@NotNull Diary diary,
Topic topic,
@NotNull Member member,
@NotNull List<Correction> corrections
) {
return RetrieveDiaryResponse.builder()
.diaryId(diary.getId())
.topic(diary.getTopic() != null ? diary.getTopic().getContent() : "")
.topic(topic != null ? topic.getContent() : "")
.content(diary.getContent())
.createdAt(SmeemConverter.toString(diary.getCreatedAt()))
.username(diary.getMember().getUsername())
.username(member.getUsername())
.corrections(corrections)
.build();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ public interface CorrectionPort {
List<Correction> saveAll(List<Correction> corrections, Diary diary);

int countDistinctByMemberAndDate(long memberId, LocalDate date);

List<Correction> findByDiary(long diary);

void deleteByDiary(long diaryId);

//TODO: 회원탈퇴
void deleteByMember(long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public interface DiaryPort {
int countByMember(long memberId);
Diary save(Diary diary);
boolean isExistByMemberAndYesterday(long memberId);
Diary findByIdJoinMemberAndTopic(long id);
Diary findById(long id);
Diary update(Diary diary);
void softDelete(long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface TopicPort {
Topic findById(long id);
Topic findRandom();

void checkValidation(long topicId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public SmeemException(ExceptionCode exceptionCode, String message) {
this.defaultMessage = exceptionCode.getMessage();
this.detailMessage = message;
}

public String getMessage() {
if (detailMessage != null) {
return "[" + defaultMessage + "] " + detailMessage;
}
return defaultMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void setHttp(HttpSecurity http) throws Exception {
authorizeHttpRequests
.requestMatchers(new AntPathRequestMatcher("/api/v2/auth", "POST")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/actuator/health")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() //TODO: 삭제
.requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/versions/client/app")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/goals/{type}")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/goals")).permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.smeem.application.domain.generic.SmeemMessage;
import com.smeem.application.port.input.DiaryUseCase;
import com.smeem.application.port.input.dto.request.diary.WriteDiaryRequest;
import com.smeem.application.port.input.dto.response.diary.CorrectionsResponse;
import com.smeem.http.controller.dto.SmeemResponse;
import com.smeem.application.port.input.dto.response.diary.RetrieveDiariesResponse;
import com.smeem.application.port.input.dto.response.diary.RetrieveDiaryResponse;
Expand Down Expand Up @@ -45,8 +44,13 @@ public SmeemResponse<RetrieveDiaryResponse> retrieveDiary(@PathVariable long dia

@ResponseStatus(HttpStatus.OK)
@PatchMapping("/{diaryId}")
public SmeemResponse<?> modifyDiary(@PathVariable long diaryId, @RequestBody WriteDiaryRequest request) {
diaryUseCase.modifyDiary(diaryId, request);
public SmeemResponse<?> modifyDiary(
Principal principal,
@PathVariable long diaryId,
@RequestBody WriteDiaryRequest request
) {
long memberId = smeemConverter.toMemberId(principal);
diaryUseCase.modifyDiary(memberId, diaryId, request);
return SmeemResponse.of(SmeemMessage.MODIFY_DIARY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ SmeemResponse<RetrieveDiaryResponse> retrieveDiary(
description = "OK success")
})
SmeemResponse<?> modifyDiary(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "diaryId",
description = "수정할 일기 id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Arrays;
import java.util.Optional;

//TODO: Redis 죽으면 어떻게 할 것인가?
Expand All @@ -26,7 +27,8 @@ public boolean getBit(String key, long offset) {

@Override
public String getBitmap(String key) {
return redisTemplate.opsForValue().get(key);
byte[] arr = redisTemplate.execute(it -> it.stringCommands().get(key.getBytes()), true);
return Arrays.toString(arr);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ public List<Correction> saveAll(List<Correction> corrections, Diary diary) {
public int countDistinctByMemberAndDate(long memberId, LocalDate date) {
return correctionRepository.countDistinctKeyByMemberIdAndCreatedAt(memberId, date);
}

@Override
public List<Correction> findByDiary(long diaryId) {
return correctionRepository.findByDiaryId(diaryId).stream().map(CorrectionEntity::toDomain).toList();
}

@Override
public void deleteByDiary(long diaryId) {
correctionRepository.deleteByDiaryId(diaryId);
}

@Override
public void deleteByMember(long memberId) {
correctionRepository.deleteByMemberId(memberId);
}
}
Loading

0 comments on commit e4acee0

Please sign in to comment.