-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor: 파일 구조 개선 및 로그인 구현
- Loading branch information
Showing
75 changed files
with
2,002 additions
and
2,166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/leets/commitatobe/domain/commit/controller/CommitController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.leets.commitatobe.domain.commit.controller; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.leets.commitatobe.domain.commit.dto.response.CommitResponse; | ||
import com.leets.commitatobe.domain.commit.service.FetchCommits; | ||
import com.leets.commitatobe.domain.commit.service.FetchCommitsTest; | ||
import com.leets.commitatobe.global.response.ApiResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Tag(name = "Commit 컨트롤러", description = "GitHub에서 사용자의 Commit 정보를 호출하고 데이터 가공을 처리합니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/commit") | ||
public class CommitController { | ||
private final FetchCommits fetchCommits; | ||
private final FetchCommitsTest fetchCommitsTest; | ||
|
||
@Operation( | ||
summary = "커밋 기록 업데이트", | ||
description = "GitHub에서 커밋 기록을 가져와 DB에 저장하고 사용자의 정보를 최신화 합니다.") | ||
@PostMapping("/update") | ||
public ApiResponse<CommitResponse> fetchCommits() { | ||
return ApiResponse.onSuccess(fetchCommits.execute()); | ||
} | ||
|
||
@Operation( | ||
summary = "커밋 기록 업데이트 (테스트)", | ||
description = "테스트를 위해, 7월 1일부터 커밋 기록을 가져와 DB에 저장하고 사용자의 정보를 최신화 합니다.") | ||
@PostMapping("update/test") | ||
public ApiResponse<CommitResponse> fetchCommitsTest() { | ||
return ApiResponse.onSuccess(fetchCommitsTest.execute()); | ||
} | ||
} |
131 changes: 69 additions & 62 deletions
131
src/main/java/com/leets/commitatobe/domain/commit/domain/Commit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,84 @@ | ||
package com.leets.commitatobe.domain.commit.domain; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
import com.leets.commitatobe.domain.user.domain.User; | ||
import com.leets.commitatobe.global.shared.entity.BaseTimeEntity; | ||
import jakarta.persistence.*; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@Entity(name = "commit") | ||
@Getter | ||
@NoArgsConstructor | ||
public class Commit extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
@Column(name = "commit_id") | ||
private UUID id; | ||
|
||
@Column | ||
private Integer cnt; | ||
|
||
@Column | ||
private LocalDateTime commitDate; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
@JsonBackReference | ||
private User user; | ||
|
||
@Column(name = "is_calculated") | ||
private boolean isCalculated;//경험치 계산 여부를 나타낸다. | ||
|
||
public static Commit create(LocalDateTime commitDate, Integer cnt, User user) { | ||
return Commit.builder() | ||
.commitDate(commitDate) | ||
.cnt(cnt) | ||
.user(user) | ||
.build(); | ||
} | ||
|
||
@Builder | ||
public Commit(LocalDateTime commitDate, Integer cnt, User user) { | ||
this.commitDate = commitDate; | ||
this.cnt = cnt; | ||
this.user = user; | ||
} | ||
|
||
public void updateCnt(Integer cnt) { | ||
if (!this.cnt.equals(cnt)) { | ||
this.cnt = cnt; | ||
markAsUncalculated(); | ||
} | ||
} | ||
|
||
public void markAsCalculated() { | ||
isCalculated = true; | ||
} | ||
|
||
public void markAsUncalculated() { | ||
isCalculated = false; | ||
} | ||
|
||
public int calculateExp(int dailyBonusExp, int consecutiveDays, int bonusExpIncrease) { | ||
int bonusExp = dailyBonusExp + consecutiveDays * bonusExpIncrease; | ||
return this.cnt * 5 + bonusExp; | ||
} | ||
|
||
public boolean commitDateIsToday() { | ||
return this.commitDate.toLocalDate().isEqual(LocalDate.now()); | ||
} | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
@Column(name = "commit_id") | ||
private UUID id; | ||
|
||
@Column | ||
private Integer cnt; | ||
|
||
@Column | ||
private LocalDateTime commitDate; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
@JsonBackReference | ||
private User user; | ||
|
||
@Column(name = "is_calculated") | ||
private boolean isCalculated;//경험치 계산 여부를 나타낸다. | ||
|
||
public static Commit create(LocalDateTime commitDate, Integer cnt, User user) { | ||
return Commit.builder() | ||
.commitDate(commitDate) | ||
.cnt(cnt) | ||
.user(user) | ||
.build(); | ||
} | ||
|
||
@Builder | ||
public Commit(LocalDateTime commitDate, Integer cnt, User user) { | ||
this.commitDate = commitDate; | ||
this.cnt = cnt; | ||
this.user = user; | ||
} | ||
|
||
public void updateCnt(Integer cnt) { | ||
if (!this.cnt.equals(cnt)) { | ||
this.cnt = cnt; | ||
markAsUncalculated(); | ||
} | ||
} | ||
|
||
public void markAsCalculated() { | ||
isCalculated = true; | ||
} | ||
|
||
public void markAsUncalculated() { | ||
isCalculated = false; | ||
} | ||
|
||
public int calculateExp(int dailyBonusExp, int consecutiveDays, int bonusExpIncrease) { | ||
int bonusExp = dailyBonusExp + consecutiveDays * bonusExpIncrease; | ||
return this.cnt * 5 + bonusExp; | ||
} | ||
|
||
public boolean commitDateIsToday() { | ||
return this.commitDate.toLocalDate().isEqual(LocalDate.now()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/leets/commitatobe/domain/commit/dto/response/CommitResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.leets.commitatobe.domain.commit.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.leets.commitatobe.domain.user.domain.User; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record CommitResponse( | ||
Boolean isMyAccount, | ||
String githubId, | ||
Integer exp, | ||
Integer ranking, | ||
String tierName, | ||
String characterUrl, | ||
Integer consecutiveCommitDays, | ||
Integer todayCommitCount, | ||
Integer totalCommitCount, | ||
LocalDateTime lastCommitUpdateTime | ||
) { | ||
public static CommitResponse of(boolean isMyAccount, User user) { | ||
return CommitResponse.builder() | ||
.isMyAccount(isMyAccount) | ||
.githubId(user.getGithubId()) | ||
.exp(user.getExp()) | ||
.ranking(user.getRanking()) | ||
.tierName(user.getTier().getTierName()) | ||
.characterUrl(user.getTier().getCharacterUrl()) | ||
.consecutiveCommitDays(user.getConsecutiveCommitDays()) | ||
.todayCommitCount(user.getTodayCommitCount()) | ||
.totalCommitCount(user.getTotalCommitCount()) | ||
.lastCommitUpdateTime(user.getLastCommitUpdateTime()) | ||
.build(); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
src/main/java/com/leets/commitatobe/domain/commit/presentation/CommitController.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...main/java/com/leets/commitatobe/domain/commit/presentation/dto/request/CommitRequest.java
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...in/java/com/leets/commitatobe/domain/commit/presentation/dto/response/CommitResponse.java
This file was deleted.
Oops, something went wrong.
17 changes: 9 additions & 8 deletions
17
...t/domain/repository/CommitRepository.java → ...n/commit/repository/CommitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com.leets.commitatobe.domain.commit.domain.repository; | ||
|
||
import com.leets.commitatobe.domain.commit.domain.Commit; | ||
import com.leets.commitatobe.domain.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
package com.leets.commitatobe.domain.commit.repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.leets.commitatobe.domain.commit.domain.Commit; | ||
import com.leets.commitatobe.domain.user.domain.User; | ||
|
||
public interface CommitRepository extends JpaRepository<Commit, UUID> { | ||
List<Commit> findAllByUser(User user); | ||
List<Commit> findAllByUser(User user); | ||
|
||
Optional<Commit> findByCommitDateAndUser(LocalDateTime commitDate, User user); | ||
Optional<Commit> findByCommitDateAndUser(LocalDateTime commitDate, User user); | ||
|
||
List<Commit> findAllByUserOrderByCommitDateAsc(User user); | ||
List<Commit> findAllByUserOrderByCommitDateAsc(User user); | ||
} |
Oops, something went wrong.