Skip to content

Commit

Permalink
Merge pull request #141 from Team-HMH/chore/#140-change-app-name
Browse files Browse the repository at this point in the history
modify - 앱관련 도메인 이름 ChallengeApp, HistoryApp으로 변경 및 적용
  • Loading branch information
jumining authored May 26, 2024
2 parents 3c0a698 + b2674e6 commit 371dc0b
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AppWithGoalTime extends App {
public class ChallengeApp extends App {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "challenge_id")
Expand All @@ -19,7 +19,7 @@ public class AppWithGoalTime extends App {
private Long goalTime;

@Builder
private AppWithGoalTime(Challenge challenge, String appCode, Long goalTime, String os) {
private ChallengeApp(Challenge challenge, String appCode, Long goalTime, String os) {
this.challenge = challenge;
this.os = os;
this.appCode = appCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AppWithUsageGoalTime extends App {
public class HistoryApp extends App {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "daily_challenge_id")
Expand All @@ -20,7 +20,7 @@ public class AppWithUsageGoalTime extends App {
private Long goalTime;

@Builder
private AppWithUsageGoalTime(DailyChallenge dailyChallenge, String os, String appCode, Long goalTime, Long usageTime) {
private HistoryApp(DailyChallenge dailyChallenge, String os, String appCode, Long goalTime, Long usageTime) {
this.dailyChallenge = dailyChallenge;
this.os = os;
this.appCode = appCode;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sopt.org.hmh.domain.app.dto.request;

import java.util.List;

public record ChallengeAppArrayRequest(
List<ChallengeAppRequest> apps
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sopt.org.hmh.domain.app.dto.request;

public record AppGoalTimeRequest(
public record ChallengeAppRequest(
String appCode,
Long goalTime
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sopt.org.hmh.domain.app.dto.request;

public record AppUsageTimeRequest(
public record HistoryAppRequest(
String appCode,
Long usageTime
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sopt.org.hmh.domain.app.dto.response;

public record AppGoalTimeResponse(
public record ChallengeAppResponse(
String appCode,
Long goalTime
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package sopt.org.hmh.domain.app.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import sopt.org.hmh.domain.app.domain.App;
import sopt.org.hmh.domain.app.domain.AppWithGoalTime;
import sopt.org.hmh.domain.app.domain.AppWithUsageGoalTime;
import sopt.org.hmh.domain.app.domain.ChallengeApp;
import sopt.org.hmh.domain.app.domain.exception.AppError;
import sopt.org.hmh.domain.app.domain.exception.AppException;

import java.util.Optional;

public interface AppWithGoalTimeRepository extends JpaRepository<AppWithGoalTime, Long> {
public interface ChallengeAppRepository extends JpaRepository<ChallengeApp, Long> {

Optional<AppWithGoalTime> findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);
Optional<ChallengeApp> findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);

default AppWithGoalTime findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long challengeId, String appCode, String os) {
default ChallengeApp findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long challengeId, String appCode, String os) {
return findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os).orElseThrow(() -> new AppException(
AppError.APP_NOT_FOUND));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package sopt.org.hmh.domain.app.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import sopt.org.hmh.domain.app.domain.AppWithUsageGoalTime;
import sopt.org.hmh.domain.app.domain.HistoryApp;
import sopt.org.hmh.domain.app.domain.exception.AppError;
import sopt.org.hmh.domain.app.domain.exception.AppException;

import java.util.Optional;

public interface AppWithUsageGoalTimeRepository extends JpaRepository<AppWithUsageGoalTime, Long> {
public interface HistoryAppRepository extends JpaRepository<HistoryApp, Long> {

Optional<AppWithUsageGoalTime> findFirstByDailyChallengeIdAndAppCodeAndOs(Long dailyChallengeId, String appCode, String os);
Optional<HistoryApp> findFirstByDailyChallengeIdAndAppCodeAndOs(Long dailyChallengeId, String appCode, String os);

default AppWithUsageGoalTime findFirstByDailyChallengeIdAndAppCodeAndOsOrElseThrow(Long dailyChallengeId, String appCode, String os) {
default HistoryApp findFirstByDailyChallengeIdAndAppCodeAndOsOrElseThrow(Long dailyChallengeId, String appCode, String os) {
return findFirstByDailyChallengeIdAndAppCodeAndOs(dailyChallengeId, appCode, os).orElseThrow(() -> new AppException(
AppError.APP_NOT_FOUND));
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/sopt/org/hmh/domain/app/service/AppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.hmh.domain.app.domain.AppWithGoalTime;
import sopt.org.hmh.domain.app.domain.AppWithUsageGoalTime;
import sopt.org.hmh.domain.app.domain.ChallengeApp;
import sopt.org.hmh.domain.app.domain.HistoryApp;
import sopt.org.hmh.domain.app.domain.exception.AppError;
import sopt.org.hmh.domain.app.domain.exception.AppException;
import sopt.org.hmh.domain.app.dto.request.AppUsageTimeRequest;
import sopt.org.hmh.domain.app.repository.AppWithUsageGoalTimeRepository;
import sopt.org.hmh.domain.app.dto.request.HistoryAppRequest;
import sopt.org.hmh.domain.app.repository.HistoryAppRepository;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;

@Service
@RequiredArgsConstructor
@Transactional
public class AppService {

private final AppWithUsageGoalTimeRepository appWithUsageGoalTimeRepository;
private final HistoryAppRepository historyAppRepository;

public void addAppForHistory(List<AppWithGoalTime> currentChallengeApps, List<AppUsageTimeRequest> apps,
DailyChallenge dailyChallenge, String os) {
appWithUsageGoalTimeRepository.saveAll(supplementAdditionalInfo(currentChallengeApps, apps, dailyChallenge, os));
public void addAppForHistory(List<ChallengeApp> currentChallengeApps, List<HistoryAppRequest> apps,
DailyChallenge dailyChallenge, String os) {
historyAppRepository.saveAll(supplementAdditionalInfo(currentChallengeApps, apps, dailyChallenge, os));
}

private List<AppWithUsageGoalTime> supplementAdditionalInfo(List<AppWithGoalTime> currentChallengeApps,
List<AppUsageTimeRequest> apps, DailyChallenge dailyChallenge, String os) {
return apps.stream().map(app -> AppWithUsageGoalTime.builder()
private List<HistoryApp> supplementAdditionalInfo(List<ChallengeApp> currentChallengeApps,
List<HistoryAppRequest> apps, DailyChallenge dailyChallenge, String os) {
return apps.stream().map(app -> HistoryApp.builder()
.goalTime(this.getGoalTime(currentChallengeApps, app.appCode()))
.appCode(app.appCode())
.dailyChallenge(dailyChallenge)
Expand All @@ -36,11 +36,11 @@ private List<AppWithUsageGoalTime> supplementAdditionalInfo(List<AppWithGoalTime
).toList();
}

private Long getGoalTime(List<AppWithGoalTime> currentChallengeApps, String appCode) {
private Long getGoalTime(List<ChallengeApp> currentChallengeApps, String appCode) {
return currentChallengeApps.stream()
.filter(currentChallengeApp -> currentChallengeApp.getAppCode().equals(appCode))
.findFirst()
.map(AppWithGoalTime::getGoalTime)
.map(ChallengeApp::getGoalTime)
.orElseThrow(() -> new AppException(AppError.APP_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sopt.org.hmh.domain.app.dto.request.AppArrayGoalTimeRequest;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest;
import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest;
import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest;
import sopt.org.hmh.domain.challenge.dto.response.ChallengeResponse;
Expand Down Expand Up @@ -96,7 +96,7 @@ ResponseEntity<BaseResponse<DailyChallengeResponse>> orderGetDailyChallenge(
content = @Content)})
ResponseEntity<BaseResponse<?>> orderAddApps(@UserId @Parameter(hidden = true) Long userId,
@RequestHeader("OS") String os,
@RequestBody AppArrayGoalTimeRequest requests);
@RequestBody ChallengeAppArrayRequest requests);

@GetMapping("/app")
@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sopt.org.hmh.domain.app.domain.exception.AppSuccess;
import sopt.org.hmh.domain.app.dto.request.AppArrayGoalTimeRequest;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest;
import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.challenge.domain.exception.ChallengeSuccess;
Expand Down Expand Up @@ -59,7 +59,7 @@ public ResponseEntity<BaseResponse<DailyChallengeResponse>> orderGetDailyChallen
@Override
public ResponseEntity<BaseResponse<?>> orderAddApps(@UserId final Long userId,
@RequestHeader("OS") final String os,
@RequestBody final AppArrayGoalTimeRequest requests) {
@RequestBody final ChallengeAppArrayRequest requests) {
Challenge challenge = challengeService.findCurrentChallengeByUserId(userId);
challengeService.addApps(challenge, requests.apps(), os);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import sopt.org.hmh.domain.app.domain.AppWithGoalTime;
import sopt.org.hmh.domain.app.domain.ChallengeApp;
import sopt.org.hmh.global.common.domain.BaseTimeEntity;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;
import java.util.ArrayList;
Expand All @@ -29,13 +29,13 @@ public class Challenge extends BaseTimeEntity {
private boolean isChallengeFailedToday;

@OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<AppWithGoalTime> apps = new ArrayList<>();
private List<ChallengeApp> apps = new ArrayList<>();

@OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true)
private final List<DailyChallenge> historyDailyChallenges = new ArrayList<>();

@Builder
private Challenge(Integer period, Long userId, Long goalTime, List<AppWithGoalTime> apps) {
private Challenge(Integer period, Long userId, Long goalTime, List<ChallengeApp> apps) {
this.period = period;
this.userId = userId;
this.goalTime = goalTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sopt.org.hmh.domain.challenge.dto.request;

import sopt.org.hmh.domain.app.dto.request.AppGoalTimeRequest;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest;

import java.util.List;

public record ChallengeSignUpRequest(
Integer period,
Long goalTime,
List<AppGoalTimeRequest> apps
List<ChallengeAppRequest> apps
) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package sopt.org.hmh.domain.challenge.dto.response;

import lombok.Builder;
import sopt.org.hmh.domain.app.dto.response.AppGoalTimeResponse;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;
import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse;
import sopt.org.hmh.domain.dailychallenge.domain.Status;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Builder
Expand All @@ -17,6 +13,6 @@ public record ChallengeResponse(
Integer todayIndex,
String startDate,
Long goalTime,
List<AppGoalTimeResponse> apps
List<ChallengeAppResponse> apps
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sopt.org.hmh.domain.challenge.dto.response;

import lombok.Builder;
import sopt.org.hmh.domain.app.dto.response.AppGoalTimeResponse;
import sopt.org.hmh.domain.app.dto.response.ChallengeAppResponse;
import sopt.org.hmh.domain.dailychallenge.domain.Status;

import java.util.List;
Expand All @@ -10,6 +10,6 @@
public record DailyChallengeResponse(
Status status,
Long goalTime,
List<AppGoalTimeResponse> apps
List<ChallengeAppResponse> apps
) {
}
Loading

0 comments on commit 371dc0b

Please sign in to comment.