Skip to content

Commit

Permalink
Merge pull request #97 from kakao-tech-campus-2nd-step3/weekly/10
Browse files Browse the repository at this point in the history
merge: 10주차 작업 master에 반영
  • Loading branch information
peeerr authored Nov 8, 2024
2 parents a591f4a + 4035549 commit 1c54d2b
Show file tree
Hide file tree
Showing 77 changed files with 7,074 additions and 192 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/master_weekly_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ jobs:
- name: 프로젝트 코드를 CI 서버로 옮겨오기
uses: actions/checkout@v4

- name: Gradle 캐시 설정
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: JDK 21 설치
uses: actions/setup-java@v4
with:
Expand All @@ -35,12 +45,13 @@ jobs:
aws.s3.bucket: ${{ secrets.AWS_S3_BUCKET }}
aws.s3.accessKey: ${{ secrets.AWS_S3_ACCESS_KEY }}
aws.s3.secretKey: ${{ secrets.AWS_S3_SECRET_KEY }}
jwt.secret: ${{ secrets.JWT_SECRET }}

- name: 빌드로 테스트 수행 및 Jar 파일 생성
run: |
chmod +x ./gradlew
./gradlew clean build
mv build/libs/*SNAPSHOT.jar ./app.jar
./gradlew clean build --build-cache
- run: mv build/libs/*SNAPSHOT.jar ./app.jar

- name: 생성된 Jar 파일 EC2 서버로 전송하기
uses: appleboy/[email protected]
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/pr_weekly_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ jobs:
- name: 프로젝트 코드를 CI 서버로 옮겨오기
uses: actions/checkout@v4

- name: Gradle 캐시 설정
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: JDK 21 설치
uses: actions/setup-java@v4
with:
Expand All @@ -38,11 +48,12 @@ jobs:
aws.s3.bucket: ${{ secrets.AWS_S3_BUCKET }}
aws.s3.accessKey: ${{ secrets.AWS_S3_ACCESS_KEY }}
aws.s3.secretKey: ${{ secrets.AWS_S3_SECRET_KEY }}
jwt.secret: ${{ secrets.JWT_SECRET }}

- name: 빌드 테스트 수행
run: |
chmod +x ./gradlew
./gradlew clean build --stacktrace
./gradlew clean build --build-cache --stacktrace
- name: 테스트 수행 결과 보고
uses: EnricoMi/publish-unit-test-result-action@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/members/login", "/h2-console/**", "/error", "/favicon.ico").permitAll()
.requestMatchers("/api/members/login", "/api/members/anonymous-login", "/h2-console/**",
"/error", "/favicon.ico").permitAll()
.requestMatchers("/swagger-resources/**", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
.anyRequest().authenticated());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private OpenApiCustomizer addSecurityItemToAllEndpointsExceptLogin() {
return openApi -> {
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth");
openApi.getPaths().forEach((path, item) -> {
if (!"/api/members/login".equals(path)) {
if (!"/api/members/login".equals(path) && !"/api/members/anonymous-login".equals(path)) {
item.readOperations().forEach(operation -> {
operation.addSecurityItem(securityRequirement);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -60,4 +61,18 @@ public ResponseEntity<SuccessResponse<Void>> deleteComment(
return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

@Operation(summary = "댓글 개수", description = "특정 일기의 댓글 개수를 조회합니다.")
@ApiResponse(responseCode = "200", description = "댓글 개수 조회 성공")
@GetMapping("/{diaryId}/count")
public ResponseEntity<SuccessResponse<Void>> getCommentCount(
@Parameter(description = "인증된 사용자 정보", hidden = true)
@AuthenticationPrincipal MemberDetails memberDetails,
@Parameter(description = "댓글 개수를 조회할 일기 ID", required = true)
@PathVariable Long diaryId) {
Long commentCount = commentService.getCommentCountByDiary(diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok(commentCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ResponseEntity<SuccessResponse<Void>> createDiaryManual(
@Parameter(description = "인증된 사용자 정보", hidden = true)
@AuthenticationPrincipal MemberDetails memberDetails,
@Parameter(description = "수기 일기 작성 정보", required = true)
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
@RequestBody @Valid DiaryManualCreateRequest diaryManualCreateRequest) {
Long memberId = memberDetails.getId();
diaryService.createDiaryManual(memberId, diaryManualCreateRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.MemberLoginRequest;
import com.potatocake.everymoment.dto.response.AnonymousLoginResponse;
import com.potatocake.everymoment.dto.response.JwtResponse;
import com.potatocake.everymoment.dto.response.MemberDetailResponse;
import com.potatocake.everymoment.dto.response.MemberMyResponse;
Expand Down Expand Up @@ -39,6 +40,15 @@ public class MemberController {

private final MemberService memberService;

@Operation(summary = "익명 로그인", description = "회원번호로 로그인하거나 새로운 익명 계정을 생성합니다.")
@ApiResponse(responseCode = "200", description = "익명 로그인 성공")
@GetMapping("/anonymous-login")
public ResponseEntity<SuccessResponse> anonymousLogin(@Parameter(description = "기기에 저장된 회원번호 (없을 경우 새로운 계정 생성)")
@RequestParam(required = false) Long number) {
AnonymousLoginResponse response = memberService.anonymousLogin(number);
return ResponseEntity.ok(SuccessResponse.ok(response));
}

@Operation(summary = "로그인", description = "회원 번호와 닉네임으로 로그인합니다.")
@ApiResponse(responseCode = "200", description = "로그인 성공", content = @Content(schema = @Schema(implementation = JwtResponse.class)))
@PostMapping("/login")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import com.potatocake.everymoment.entity.Member;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class CategoryCreateRequest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.potatocake.everymoment.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class CategoryRequest {
private Long categoryId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class CommentRequest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.potatocake.everymoment.dto.request;

import com.potatocake.everymoment.dto.LocationPoint;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class DiaryAutoCreateRequest {
private LocationPoint locationPoint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.potatocake.everymoment.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.potatocake.everymoment.dto.LocationPoint;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class DiaryManualCreateRequest {

Expand All @@ -18,7 +21,10 @@ public class DiaryManualCreateRequest {
@Size(max = 250, message = "주소는 250자를 초과할 수 없습니다")
private String address;

@JsonProperty("bookmark")
private boolean isBookmark;

@JsonProperty("public")
private boolean isPublic;

@Size(max = 10, message = "이모지는 10자를 초과할 수 없습니다")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class DiaryPatchRequest {

private Boolean deleteAllCategories;
private Boolean locationNameDelete;
private Boolean addressDelete;
private Boolean emojiDelete;
private Boolean contentDelete;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class FcmTokenRequest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.potatocake.everymoment.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
public class AnonymousLoginResponse {

private Long number;
private String token;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
public class CommentResponse {
private Long id;
private Long memberId;
private CommentFriendResponse commentFriendResponse;
private String content;
private LocalDateTime createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public class FriendDiaryResponse {
private String emoji;
private String content;
private LikeCountResponse likeCount;
private boolean isLiked;
private LocalDateTime createAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class MyDiaryResponse {
private boolean isBookmark;
private String emoji;
private String content;
private boolean isLiked;
private LocalDateTime createAt;
}
10 changes: 10 additions & 0 deletions src/main/java/com/potatocake/everymoment/entity/Diary.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public void updateEmoji(String emoji) {
}
}

public void updateContentNull() {
this.content = null;
}

public void updateEmojiNull() {
this.emoji = null;

}

public void updateBookmark(boolean isBookmark) {
this.isBookmark = isBookmark;
}
Expand All @@ -112,3 +121,4 @@ public boolean checkOwner(Long memberId) {
}

}

2 changes: 2 additions & 0 deletions src/main/java/com/potatocake/everymoment/entity/Like.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Table(name = "likes")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
public class Like {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum ErrorCode {

/* File */
FILE_NOT_FOUND("존재하지 않는 파일입니다.", NOT_FOUND),
FILE_SIZE_EXCEEDED("각 파일은 1MB 이하로, 전체 파일 크기는 10MB 이하로 첨부해 주세요.", PAYLOAD_TOO_LARGE),
FILE_SIZE_EXCEEDED("각 파일은 5MB 이하로, 전체 파일 크기는 25MB 이하로 첨부해 주세요.", PAYLOAD_TOO_LARGE),

/* Comment */
COMMENT_NOT_FOUND("존재하지 않는 댓글입니다.", NOT_FOUND),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface CommentRepository extends JpaRepository<Comment, Long> {
Page<Comment> findAllByDiaryId(Long diaryId, Pageable pageable);

Long countByDiaryId(Long diaryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface LikeRepository extends JpaRepository<Like, Long> {

Long countByDiary(Diary diary);

boolean existsByMemberIdAndDiaryId(Long memberId, Long diaryId);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.potatocake.everymoment.repository;

import com.potatocake.everymoment.entity.Member;
import jakarta.persistence.LockModeType;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Window;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;

public interface MemberRepository extends JpaRepository<Member, Long> {

Expand All @@ -15,4 +18,8 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

Window<Member> findByNicknameContaining(String nickname, ScrollPosition position, Pageable pageable);

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT CASE WHEN MIN(m.number) > 0 OR MIN(m.number) IS NULL THEN -1 ELSE MIN(m.number) - 1 END FROM Member m")
Long findNextAnonymousNumber();

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ private CommentFriendResponse convertToCommentFriendResponseDTO(Member member) {
private CommentResponse convertToCommentResponseDTO(Comment comment) {
return CommentResponse.builder()
.id(comment.getId())
.memberId(comment.getMember().getId())
.commentFriendResponse(convertToCommentFriendResponseDTO(comment.getMember()))
.content(comment.getContent())
.createdAt(comment.getCreateAt())
.build();
}

public Long getCommentCountByDiary(Long diaryId) {
return commentRepository.countByDiaryId(diaryId);
}
}
Loading

0 comments on commit 1c54d2b

Please sign in to comment.