-
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.
* chore: timezone seoul 설정 * chore: 깃 템플릿 추가, readme.md 추가 * chore: 예외처리, 전역 환경 설정 외 * feat: 데이터 모델링 * chore: 🐳 cicd 설정 * chore: 🐳 workflow lowercase 로 수정 * chore: 디스코드 webhook 테스트 * chore: :global: cors 설정 * chore: 🐳 cors 변경사항 yml 재적용 * feat: ✨ 팀(방) 생성 기능 구현 (#9) * feat: 목표 점검(캘린더) 기능 구현 (#11)
- Loading branch information
1 parent
76452d7
commit 5ebf4ec
Showing
9 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/goormdari/domain/calendar/application/CalendarService.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,31 @@ | ||
package com.goormdari.domain.calendar.application; | ||
|
||
import com.goormdari.domain.calendar.domain.repository.CalendarRepository; | ||
import com.goormdari.domain.calendar.dto.response.CheckGoalProgressResponse; | ||
import com.goormdari.domain.user.domain.User; | ||
import com.goormdari.domain.user.domain.repository.UserRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.YearMonth; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CalendarService { | ||
|
||
private final CalendarRepository calendarRepository; | ||
private final UserRepository userRepository; | ||
|
||
|
||
public CheckGoalProgressResponse searchCheckGoalProgress(Long userId, YearMonth date) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new EntityNotFoundException("User not found")); | ||
|
||
CheckGoalProgressResponse checkGoalProgressResponse = calendarRepository.findByIdAndDate(userId, date); | ||
|
||
return checkGoalProgressResponse; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...main/java/com/goormdari/domain/calendar/domain/repository/CalendarQueryDslRepository.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,9 @@ | ||
package com.goormdari.domain.calendar.domain.repository; | ||
|
||
import com.goormdari.domain.calendar.dto.response.CheckGoalProgressResponse; | ||
|
||
import java.time.YearMonth; | ||
|
||
public interface CalendarQueryDslRepository { | ||
CheckGoalProgressResponse findByIdAndDate(Long userId, YearMonth date); | ||
} |
74 changes: 74 additions & 0 deletions
74
.../java/com/goormdari/domain/calendar/domain/repository/CalendarQueryDslRepositoryImpl.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,74 @@ | ||
package com.goormdari.domain.calendar.domain.repository; | ||
|
||
import com.goormdari.domain.calendar.domain.Calendar; | ||
import com.goormdari.domain.calendar.dto.response.CheckGoalProgressResponse; | ||
import com.goormdari.domain.user.domain.User; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.YearMonth; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.goormdari.domain.calendar.domain.QCalendar.calendar; | ||
import static com.goormdari.domain.user.domain.QUser.user; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class CalendarQueryDslRepositoryImpl implements CalendarQueryDslRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
|
||
@Override | ||
public CheckGoalProgressResponse findByIdAndDate(Long userId, YearMonth date) { | ||
|
||
LocalDate startDate = date.atDay(1); | ||
LocalDate endDate = date.atEndOfMonth(); | ||
|
||
User userInfo = queryFactory | ||
.selectFrom(user) | ||
.where(user.id.eq(userId)) | ||
.fetchOne(); | ||
|
||
if (userInfo == null) { | ||
throw new EntityNotFoundException("User not found"); | ||
} | ||
|
||
List<Calendar> calendarList = queryFactory | ||
.selectFrom(calendar) | ||
.where( | ||
calendar.userId.eq(userId), | ||
calendar.date.between(startDate, endDate) | ||
) | ||
.fetch(); | ||
|
||
String goal = userInfo.getGoal(); | ||
|
||
int dDay = calculateDDay(userInfo.getDeadLine()); | ||
|
||
List<CheckGoalProgressResponse.DayAchive> dayAchiveList = calendarList.stream() | ||
.map(entry -> new CheckGoalProgressResponse.DayAchive( | ||
entry.getDate(), | ||
entry.getSuccess_count() | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
return new CheckGoalProgressResponse( | ||
userInfo.getNickname(), | ||
userInfo.getProfileUrl(), | ||
goal, | ||
dDay, | ||
dayAchiveList | ||
); | ||
} | ||
|
||
private int calculateDDay(LocalDate deadLine) { | ||
LocalDate now = LocalDate.now(); | ||
return (int) ChronoUnit.DAYS.between(now, deadLine); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/goormdari/domain/calendar/dto/response/CheckGoalProgressResponse.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,31 @@ | ||
package com.goormdari.domain.calendar.dto.response; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Builder | ||
public record CheckGoalProgressResponse( | ||
String nickname, | ||
String profileUrl, | ||
String goal, | ||
int dDay, | ||
List<DayAchive> dayAchiveList | ||
) { | ||
public record DayAchive( | ||
LocalDate date, | ||
int achieved | ||
) { | ||
} | ||
|
||
@QueryProjection | ||
public CheckGoalProgressResponse(String nickname, String profileUrl, String goal, int dDay, List<DayAchive> dayAchiveList) { | ||
this.nickname = nickname; | ||
this.profileUrl = profileUrl; | ||
this.goal = goal; | ||
this.dDay = dDay; | ||
this.dayAchiveList = dayAchiveList; | ||
} | ||
} |
36 changes: 31 additions & 5 deletions
36
src/main/java/com/goormdari/domain/calendar/presentation/CalendarController.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,16 +1,42 @@ | ||
package com.goormdari.domain.calendar.presentation; | ||
|
||
import com.goormdari.domain.calendar.application.CalendarService; | ||
import com.goormdari.domain.calendar.dto.response.CheckGoalProgressResponse; | ||
import com.goormdari.global.payload.ErrorResponse; | ||
import com.goormdari.global.payload.ResponseCustom; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.YearMonth; | ||
|
||
@Tag(name = "Calendar", description = "Calendar API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/calendar") | ||
public class CalendarController { | ||
|
||
@GetMapping("/test") | ||
public String test() { | ||
return "안뇽"; | ||
// 마이페이지-목표점검 부분 api 입니다. | ||
private final CalendarService calendarService; | ||
|
||
|
||
@Operation(summary = "목표 점검 화면 조회", description = "목표 점검 화면을 조회합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "목표 점검 화면 조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CheckGoalProgressResponse.class))}), | ||
@ApiResponse(responseCode = "400", description = "목표 점검 화면 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), | ||
}) | ||
@GetMapping("/{date}") | ||
public ResponseCustom<CheckGoalProgressResponse> checkGoalProgress( | ||
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader Long userId, | ||
@Parameter(description = "조회할 날짜를 입력해주세요.(ex. 2024-08)", required = false) @PathVariable(required = false) YearMonth date | ||
) { | ||
return ResponseCustom.OK(calendarService.searchCheckGoalProgress(userId, date)); | ||
} | ||
|
||
} |
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