Skip to content

Commit

Permalink
Change properties for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungJun-L committed Dec 15, 2023
1 parent 20bb10d commit 7681bfc
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 421 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/cd-dev.yml

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/cd-main.yml → .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
BUCKET_NAME: lingoswap-build
ARN: arn:aws:iam::285279154236:role/s3-codedeploy
ARN: arn:aws:iam::455541718696:role/codedeploy
AWS_REGION: ap-northeast-2

permissions:
Expand Down Expand Up @@ -72,7 +72,6 @@ jobs:
aws s3 cp ./build.zip s3://${{ env.BUCKET_NAME }}/
- name: Code Deploy
run: aws deploy create-deployment --application-name lingoswap
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name ec2
run: aws deploy create-deployment --application-name LingoTalk
--deployment-group-name prod
--s3-location bucket=${{ env.BUCKET_NAME }},bundleType=zip,key=build.zip
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public TokenPairInfoResponse reissue(final ReissueRequest reissueRequest) {
}

@Transactional
public void delete(final String username) {
memberRepository.deleteByAuthDetailsUsername(username);
public void delete(final String uuid) {
memberRepository.deleteByAuthDetailsUuid(uuid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
public class BearerTokenAuthenticationFilter extends OncePerRequestFilter {

private final List<String> excludedPatterns = List.of(
"/api/v1/auth/**",
"/api/v1/auth/login",
"/api/v1/auth/signup",
"/api/v1/admin/**",
"/api/v1/form/**",
"/actuator/**",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ default Member getByUuid(final String uuid) {
.orElseThrow(MemberNotFoundException::new);
}

void deleteByAuthDetailsUsername(final String username);
void deleteByAuthDetailsUuid(final String uuid);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.lighthouse.lingoswap.category.domain.model.Category;
import com.lighthouse.lingoswap.category.domain.repository.CategoryRepository;
import com.lighthouse.lingoswap.common.dto.SliceDto;
import com.lighthouse.lingoswap.likemember.domian.repository.LikeMemberRepository;
import com.lighthouse.lingoswap.member.domain.model.Member;
import com.lighthouse.lingoswap.member.domain.repository.MemberRepository;
import com.lighthouse.lingoswap.question.domain.model.LikeMember;
import com.lighthouse.lingoswap.question.domain.model.Question;
import com.lighthouse.lingoswap.question.domain.repository.LikeMemberRepository;
import com.lighthouse.lingoswap.question.domain.repository.QuestionQueryRepository;
import com.lighthouse.lingoswap.question.domain.repository.QuestionRepository;
import com.lighthouse.lingoswap.question.dto.*;
Expand Down Expand Up @@ -63,4 +64,30 @@ public MyQuestionsResponse readByCreatedMember(final String memberUuid) {
return new MyQuestionsResponse(questionRepository.findByCreatedMember(member).stream().map(MyQuestionDetail::from).toList());
}

@Transactional
public void addOneLike(final String memberUuid, final Long questionId) {
// Question question = questionRepository.getByQuestionId(questionId);
Question question = questionRepository.findById(questionId).orElseThrow();
Member member = memberRepository.getByUuid(memberUuid);
likeMemberRepository.validateAlreadyLiked(member, question);
LikeMember likeMember = LikeMember.builder()
.member(member)
.question(question)
.build();
likeMemberRepository.save(likeMember);

question.addOneLike();
}

@Transactional
public void subtractOneLike(final String memberUuid, final Long questionId) {
// Question question = questionRepository.getByQuestionId(questionId);
Question question = questionRepository.findById(questionId).orElseThrow();
Member member = memberRepository.getByUuid(memberUuid);
LikeMember likeMember = likeMemberRepository.getByMemberAndQuestion(member, question);
likeMemberRepository.delete(likeMember);

question.subtractOneLike();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
class Like {

@Column(name = "likes")
private Long value = 0L;
private long value;

Like(final Long value) {
Like(final long value) {
this.value = value;
}

Long getValue() {
long getValue() {
return value;
}

Like addOneLike() {
return new Like(value + 1);
void addOneLike() {
value++;
}

Like subtractOneLike() {
void subtractOneLike() {
validateRange();
return new Like(value - 1);
value--;
}

private void validateRange() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.lighthouse.lingoswap.likemember.domian.model;
package com.lighthouse.lingoswap.question.domain.model;

import com.lighthouse.lingoswap.common.entity.BaseEntity;
import com.lighthouse.lingoswap.member.domain.model.Member;
import com.lighthouse.lingoswap.question.domain.model.Question;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lighthouse.lingoswap.likemember.domian.model;
package com.lighthouse.lingoswap.question.domain.model;

import com.lighthouse.lingoswap.member.domain.model.Member;
import jakarta.persistence.Embeddable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lighthouse.lingoswap.likemember.domian.model;
package com.lighthouse.lingoswap.question.domain.model;

import com.lighthouse.lingoswap.question.domain.model.Question;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public String getContents() {
}

public void addOneLike() {
like = like.addOneLike();
like.addOneLike();
}

public void subtractOneLike() {
like = like.subtractOneLike();
like.subtractOneLike();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.lighthouse.lingoswap.likemember.domian.repository;
package com.lighthouse.lingoswap.question.domain.repository;

import com.lighthouse.lingoswap.likemember.domian.model.LikeMember;
import com.lighthouse.lingoswap.member.domain.model.Member;
import com.lighthouse.lingoswap.question.domain.model.LikeMember;
import com.lighthouse.lingoswap.question.domain.model.Question;
import com.lighthouse.lingoswap.question.exception.DuplicateLikeMemberException;
import com.lighthouse.lingoswap.question.exception.LikeMemberNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.lighthouse.lingoswap.member.domain.model.Member;
import com.lighthouse.lingoswap.question.domain.model.Question;
import com.lighthouse.lingoswap.question.exception.QuestionNotFoundException;
import jakarta.persistence.LockModeType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface QuestionRepository extends JpaRepository<Question, Long> {

Expand All @@ -16,6 +19,9 @@ default Question getByQuestionId(final Long questionId) {
.orElseThrow(QuestionNotFoundException::new);
}

@Lock(LockModeType.PESSIMISTIC_WRITE)
Optional<Question> findById(final Long id);

@Query("select q from Question q join fetch q.questionCategory.category where q.questionCreatedMember.member = :member order by q.id desc")
List<Question> findByCreatedMember(@Param("member") final Member member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ public ResponseEntity<ResponseDto<MyQuestionsResponse>> getMyQuestion(@PathVaria
return ResponseEntity.ok(ResponseDto.success(questionManager.readByCreatedMember(uuid)));
}

@PostMapping("/api/v1/question/{questionId}/like")
public ResponseEntity<ResponseDto<Void>> postLike(@PathVariable final Long questionId) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
questionManager.addOneLike((String) auth.getPrincipal(), questionId);
return ResponseEntity.ok(ResponseDto.noData());
}

@DeleteMapping("/api/v1/question/{questionId}/like")
public ResponseEntity<ResponseDto<Void>> deleteLike(@PathVariable final Long questionId) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
questionManager.subtractOneLike((String) auth.getPrincipal(), questionId);
return ResponseEntity.ok(ResponseDto.noData());
}

}
2 changes: 1 addition & 1 deletion src/main/resources/security
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.lighthouse.lingoswap.infra.service.AmazonImageService;
import com.lighthouse.lingoswap.interests.application.InterestsManager;
import com.lighthouse.lingoswap.language.application.LanguageManager;
import com.lighthouse.lingoswap.likemember.application.LikeMemberManager;
import com.lighthouse.lingoswap.match.application.MatchManager;
import com.lighthouse.lingoswap.member.application.MemberManager;
import com.lighthouse.lingoswap.question.application.QuestionManager;
Expand Down Expand Up @@ -44,9 +43,6 @@ public abstract class ControllerTestSupport {
@MockBean
protected QuestionManager questionManager;

@MockBean
protected LikeMemberManager likeMemberManager;

@MockBean
protected CountryManager countryManager;

Expand Down
Loading

0 comments on commit 7681bfc

Please sign in to comment.