Skip to content

Commit

Permalink
Merge pull request #64 from TeamGromit/feat/LHS-11
Browse files Browse the repository at this point in the history
  • Loading branch information
LHS-11 authored Aug 24, 2023
2 parents a620795 + 33cefa5 commit 40979ca
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 116 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

implementation 'org.jsoup:jsoup:1.14.2'
implementation 'org.jsoup:jsoup:1.16.1'
implementation 'com.google.code.gson:gson:2.8.7'

implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HomeController {
public BaseResponse<ShowHomeResponse> home(@AuthenticationPrincipal UserAccount userAccount) throws ExecutionException, InterruptedException {

// 커밋 갱신
userAccountService.reloadCommits(userAccount, LocalDate.now());
userAccountService.reloadCommits(userAccount);

//유저에게 할당된 캐릭터가 없다면 1레벨 캐릭터 부여
UserCharacter userCharacter = userCharacterService.findByUserAccountId(userAccount);
Expand All @@ -63,7 +63,7 @@ public BaseResponse<ShowHomeResponse> home(@AuthenticationPrincipal UserAccount
public BaseResponse<ShowHomeResponse> reload(@AuthenticationPrincipal UserAccount userAccount) throws ExecutionException, InterruptedException {

// 커밋 갱신
userAccountService.reloadCommits(userAccount, LocalDate.now());
userAccountService.reloadCommits(userAccount);

// 진화
ShowHomeResponse result = userCharacterService.reloadCharacter(userAccount).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public BaseResponse<String> deleteUserAccount(@AuthenticationPrincipal UserAccou
@PatchMapping("/reload") //커밋 새로고침
public BaseResponse<String> reloadCommits(@AuthenticationPrincipal UserAccount userAccount) {
System.out.println("커밋 새로고침 컨트롤러");
userAccountService.reloadCommits(userAccount, LocalDate.now());
userAccountService.reloadCommits(userAccount);
return BaseResponse.onSuccess("커밋 새로고침에 성공했습니다.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@
@EqualsAndHashCode
public class GetChallengeGroupResponse {

private final Long challengeId;
private final String title;
private final LocalDate startDate;
private final int goal;

private final int recruits;
private final int currentMemberNum;

private GetChallengeGroupResponse(String title, LocalDate startDate, int goal, int recruits, int currentMemberNum) {
private GetChallengeGroupResponse(Long challengeId, String title, LocalDate startDate, int goal, int recruits, int currentMemberNum) {
this.challengeId = challengeId;
this.title = title;
this.startDate = startDate;
this.goal = goal;
this.recruits = recruits;
this.currentMemberNum = currentMemberNum;
}

public static GetChallengeGroupResponse of(String title, LocalDate startDate, int goal, int recruits, int currentMemberNum){
return new GetChallengeGroupResponse(title, startDate, goal, recruits, currentMemberNum);
public static GetChallengeGroupResponse of(Long challengeId,String title, LocalDate startDate, int goal, int recruits, int currentMemberNum){
return new GetChallengeGroupResponse(challengeId,title, startDate, goal, recruits, currentMemberNum);
}

public static GetChallengeGroupResponse from(Challenge challenge){
return new GetChallengeGroupResponse(
challenge.getId(),
challenge.getTitle(),
challenge.getStartDate(),
challenge.getGoal(),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/example/gromit/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.time.LocalDate;

@AllArgsConstructor
@NoArgsConstructor
Expand Down Expand Up @@ -36,6 +37,8 @@ public class Member extends BaseEntity {
@Column(nullable = false)
private boolean isDeleted;

private LocalDate commitDate;

private Member(Challenge challenge, UserAccount userAccount, int commits, boolean isDeleted) {
this.challenge = challenge;
this.userAccount = userAccount;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/example/gromit/entity/UserAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.persistence.*;
import javax.validation.constraints.Email;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class UserAccount extends BaseEntity implements UserDetails {
private boolean isAlarm;
private Timestamp alarm;

private LocalDate commitDate;

/**
* 애플 로그인 구현 컬럼들
*/
Expand Down Expand Up @@ -102,7 +105,9 @@ public void reloadCommits(int todayCommit, int commits) {
this.commits = commits;
}


public void setCommitDate(LocalDate commitDate) {
this.commitDate = commitDate;
}

@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.example.gromit.entity.Challenge;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.time.LocalDate;
Expand All @@ -10,12 +12,17 @@
@RepositoryRestResource
public interface ChallengeRepository extends JpaRepository<Challenge, Long> {

List<Challenge> findAllByUserAccountIdAndIsDeleted(Long userAccountId, boolean isDeleted);
@Query("select c from Challenge c join fetch c.userAccount where c.userAccount.id = :userAccountId and c.isDeleted = :isDeleted")
List<Challenge> findAllByUserAccountIdAndIsDeleted(@Param("userAccountId") Long userAccountId, @Param("isDeleted") boolean isDeleted);

List<Challenge> findAllByIsDeletedAndStartDateGreaterThanEqual(boolean isDeleted, LocalDate now);

List<Challenge> findAllByIsDeleted(boolean isDeleted);
@Query("select DISTINCT c from Challenge c join fetch c.userAccount where c.isDeleted = :isDeleted")
List<Challenge> findAllByIsDeleted(@Param("isDeleted") boolean isDeleted);

boolean existsByIdAndStartDateLessThanEqualAndEndDateGreaterThanEqual(Long challengeId, LocalDate now1, LocalDate now2);

List<Challenge> findAllByUserAccountIdAndStartDateGreaterThanAndEndDateLessThan(Long userAccountId, LocalDate now1, LocalDate now2);

boolean existsByIdAndStartDateLessThanEqualAndEndDateGreaterThanEqual (Long challengeId, LocalDate now1, LocalDate now2);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface ChallengeList {
int getCommits();
}

void deleteByUserAccountId(Long userAccountId);
void deleteAllByUserAccountId(Long userAccountId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface UserCharacterRepository extends JpaRepository<UserCharacter, Lo

Optional<UserCharacter> findByUserAccountIdAndStatusAndIsDeleted(Long userAccountId,int status,boolean isDeleted);

void deleteByUserAccountId(Long userAccountId);
void deleteAllByUserAccountId(Long userAccountId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CustomUserDetailService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String userAccountId) throws UsernameNotFoundException{
System.out.println("userAccountId = " + userAccountId);
return (UserDetails) userAccountRepository.findById(Long.parseLong(userAccountId))
return (UserDetails) userAccountRepository.findByIdAndIsDeleted(Long.parseLong(userAccountId),false)
.orElseThrow(() -> new NotFoundException(USER_NOT_FOUND));
}
}
Loading

0 comments on commit 40979ca

Please sign in to comment.