Skip to content

Commit

Permalink
release: 2.0.0 배포
Browse files Browse the repository at this point in the history
release: 2.0.0 배포
  • Loading branch information
Ji-soo708 authored Jan 2, 2024
2 parents 3044fbe + d6708ab commit c0446b0
Show file tree
Hide file tree
Showing 97 changed files with 1,472 additions and 664 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
- develop

jobs:
build:
test:
name: Code Quality Check
runs-on: ubuntu-latest

steps:
Expand All @@ -26,5 +27,21 @@ jobs:
- name: Grant execute permisson for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: check
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar --info --stacktrace
88 changes: 88 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'jacoco'
id 'org.sonarqube' version '4.2.1.3168'
}

group = 'mocacong'
Expand Down Expand Up @@ -45,6 +47,92 @@ dependencies {
testImplementation 'it.ozimov:embedded-redis:0.7.2'
}

jacoco {
toolVersion = '0.8.8'
}

test {
useJUnitPlatform()
finalizedBy 'jacocoTestReport'
}

def Qdomains = []
for (qPattern in "**/QA" .. "**/QZ") {
Qdomains.add(qPattern + "*")
}

sonar {
properties {
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'mocacong'
property 'sonar.projectKey', 'mocacong_Mocacong-Backend'
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/index.xml'
property 'sonar.sources', 'src'
property 'sonar.language', 'java'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.exclusions', '**/test/**, **/resources/**, **/*Application*.java, **/*Controller*.java, **/*Config.java' +
'**/*Response.java, **/*Exception.java, **/security/**, **/support/**, **/Q*.java'
property 'sonar.test.inclusions', '**/*Test.java'
property 'sonar.java.coveragePlugin', 'jacoco'
}
}

jacocoTestReport {
dependsOn test
reports{
html.required.set(true)
xml.required.set(true)
html.destination file("$buildDir/reports/jacoco/index.html")
xml.destination file("$buildDir/reports/jacoco/index.xml")
}

afterEvaluate {
classDirectories.setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, excludes:
[
"**/*Application*",
"**/*Controller*",
"**/config/*",
"**/dto/*",
"**/exception/*",
"**/security/*",
"**/support/*"
]+ Qdomains)
})
)
}
finalizedBy 'jacocoTestCoverageVerification'
}

jacocoTestCoverageVerification {
violationRules {
rule {
failOnViolation = false
enabled = true
element = 'CLASS'

limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.70
}

limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.70
}

excludes = [
'**.*Application*',
'**.*Controller*',
'**.config.*',
'**.dto.*',
'**.exception.*',
'**.security.*',
'**.support.*'
] + Qdomains
}
}
}
12 changes: 11 additions & 1 deletion src/main/java/mocacong/server/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import mocacong.server.dto.request.AppleLoginRequest;
import mocacong.server.dto.request.AuthLoginRequest;
import mocacong.server.dto.request.KakaoLoginRequest;
import mocacong.server.dto.request.RefreshTokenRequest;
import mocacong.server.dto.response.OAuthTokenResponse;
import mocacong.server.dto.response.ReissueTokenResponse;
import mocacong.server.dto.response.TokenResponse;
import mocacong.server.service.AuthService;
import org.springframework.http.ResponseEntity;
Expand All @@ -16,6 +17,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Tag(name = "Login", description = "인증")
@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -44,4 +47,11 @@ public ResponseEntity<OAuthTokenResponse> loginKakao(@RequestBody @Valid KakaoLo
OAuthTokenResponse response = authService.kakaoOAuthLogin(request);
return ResponseEntity.ok(response);
}

@Operation(summary = "토큰 재발급")
@PostMapping("/reissue")
public ResponseEntity<ReissueTokenResponse> refreshAccessToken(@RequestBody @Valid RefreshTokenRequest request) {
ReissueTokenResponse response = authService.reissueAccessToken(request);
return ResponseEntity.ok(response);
}
}
14 changes: 14 additions & 0 deletions src/main/java/mocacong/server/controller/ReportController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import mocacong.server.dto.request.CafeImageReportRequest;
import mocacong.server.dto.request.CommentReportRequest;
import mocacong.server.dto.response.CafeImageReportResponse;
import mocacong.server.dto.response.CommentReportResponse;
import mocacong.server.security.auth.LoginUserId;
import mocacong.server.service.ReportService;
Expand Down Expand Up @@ -32,4 +34,16 @@ public ResponseEntity<CommentReportResponse> reportComment(
CommentReportResponse response = reportService.reportComment(memberId, commentId, request.getMyReportReason());
return ResponseEntity.ok(response);
}

@Operation(summary = "카페 이미지 신고")
@SecurityRequirement(name = "JWT")
@PostMapping("/img/{cafeImageId}")
public ResponseEntity<CafeImageReportResponse> reportCafeImage(
@LoginUserId Long memberId,
@PathVariable Long cafeImageId,
@RequestBody @Valid CafeImageReportRequest request
) {
CafeImageReportResponse response = reportService.reportCafeImage(memberId, cafeImageId, request.getMyReportReason());
return ResponseEntity.ok(response);
}
}
50 changes: 50 additions & 0 deletions src/main/java/mocacong/server/domain/Cafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class Cafe extends BaseTime {
@Column(name = "map_id", unique = true, nullable = false)
private String mapId;

@Column(name = "road_address")
private String roadAddress;

@Column(name = "phone_number")
private String phoneNumber;

@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Score> score;

Expand All @@ -54,6 +60,29 @@ public Cafe(String mapId, String name) {
this.comments = new ArrayList<>();
}

public Cafe(String mapId, String name, String roadAddress) {
this.mapId = mapId;
this.name = name;
this.roadAddress = roadAddress;
this.cafeDetail = new CafeDetail();
this.cafeImages = new ArrayList<>();
this.score = new ArrayList<>();
this.reviews = new ArrayList<>();
this.comments = new ArrayList<>();
}

public Cafe(String mapId, String name, String roadAddress, String phoneNumber) {
this.mapId = mapId;
this.name = name;
this.roadAddress = roadAddress;
this.phoneNumber = phoneNumber;
this.cafeDetail = new CafeDetail();
this.cafeImages = new ArrayList<>();
this.score = new ArrayList<>();
this.reviews = new ArrayList<>();
this.comments = new ArrayList<>();
}

public void updateCafeDetails() {
StudyType studyType = getMostFrequentStudyType();
Wifi wifi = Wifi.averageFrom(reviews.stream().map(Review::getWifi)
Expand All @@ -71,6 +100,10 @@ public void updateCafeDetails() {
this.cafeDetail = new CafeDetail(studyType, wifi, parking, toilet, desk, power, sound);
}

public void updateCafeRoadAddress(String roadAddress) {
this.roadAddress = roadAddress;
}

private StudyType getMostFrequentStudyType() {
int solo = 0, group = 0;
for (Review review : reviews) {
Expand Down Expand Up @@ -107,4 +140,21 @@ public void addScore(Score score) {
public void addReview(Review review) {
this.reviews.add(review);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Cafe)) {
return false;
}
Cafe cafe = (Cafe) o;
return Objects.equals(mapId, cafe.mapId);
}

@Override
public int hashCode() {
return Objects.hash(mapId);
}
}
41 changes: 41 additions & 0 deletions src/main/java/mocacong/server/domain/CafeImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "cafe_image")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CafeImage extends BaseTime {

private static final int REPORT_CAFE_IMAGE_THRESHOLD_COUNT = 3;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cafe_image_id")
Expand All @@ -31,11 +35,18 @@ public class CafeImage extends BaseTime {
@JoinColumn(name = "member_id")
private Member member;

@OneToMany(mappedBy = "cafeImage", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Report> reports = new ArrayList<>();

@Column(name = "is_masked")
private boolean isMasked;

public CafeImage(String imgUrl, Boolean isUsed, Cafe cafe, Member member) {
this.imgUrl = imgUrl;
this.isUsed = isUsed;
this.cafe = cafe;
this.member = member;
this.isMasked = false;
}

public boolean isOwned(Member member) {
Expand All @@ -49,4 +60,34 @@ public void updateImgUrl(String imgUrl) {
public void removeMember() {
this.member = null;
}

public boolean hasAlreadyReported(Member member) {
return this.reports.stream()
.anyMatch(report -> report.getReporter().equals(member));
}

public void addReport(Report report) {
reports.add(report);
}

public int getReportsCount() {
return reports.size();
}

public boolean isDeletedMember() {
return member == null;
}

public boolean isSavedByMember(Member member) {
return this.member != null && this.member.equals(member);
}

public boolean isReportThresholdExceeded() {
return getReportsCount() >= REPORT_CAFE_IMAGE_THRESHOLD_COUNT;
}

public void maskCafeImage() {
this.isUsed = false;
this.isMasked = true;
}
}
14 changes: 9 additions & 5 deletions src/main/java/mocacong/server/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class Comment extends BaseTime {
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Report> reports = new ArrayList<>();

@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL, orphanRemoval = true)
private List<CommentLike> commentLikes = new ArrayList<>();

@Column(name = "is_masked")
private boolean isMasked;

Expand Down Expand Up @@ -88,10 +91,6 @@ public boolean isReportThresholdExceeded() {
return getReportsCount() >= REPORT_COMMENT_THRESHOLD_COUNT;
}

public boolean isDeletedCommenter() {
return isDeletedMember() && isReportThresholdExceeded();
}

public boolean hasAlreadyReported(Member member) {
return this.reports.stream()
.anyMatch(report -> report.getReporter().equals(member));
Expand All @@ -110,6 +109,11 @@ public void addReport(Report report) {
}

public void updateIsMasked(boolean isMasked) {
this.isMasked= isMasked;
this.isMasked = isMasked;
}

public int getLikeCounts() {
return commentLikes.size();
}

}
2 changes: 1 addition & 1 deletion src/main/java/mocacong/server/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class Member extends BaseTime {

private static final Pattern NICKNAME_REGEX = Pattern.compile("^[a-zA-Zㄱ-ㅎㅏ-ㅣ가-힣]{2,6}$");
private static final int REPORT_MEMBER_THRESHOLD_COUNT = 11;
private static final int REPORT_MEMBER_THRESHOLD_COUNT = 5;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Loading

0 comments on commit c0446b0

Please sign in to comment.