-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lsn5963/feat/quest
퀘스트 수정,삭제, 조회 로직
- Loading branch information
Showing
14 changed files
with
303 additions
and
15 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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/noplanb/domain/quest/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,47 @@ | ||
package com.noplanb.domain.quest.application; | ||
|
||
import com.noplanb.domain.character.domain.Character; | ||
import com.noplanb.domain.character.repository.CharacterRepository; | ||
import com.noplanb.domain.quest.domain.Quest; | ||
import com.noplanb.domain.quest.dto.res.RetrieveCalendarRes; | ||
import com.noplanb.global.payload.ApiResponse; | ||
import com.noplanb.global.payload.exception.CharacterNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.YearMonth; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CalendarService { | ||
private final CharacterRepository characterRepository; | ||
|
||
public ResponseEntity<?> retrieveQuest(YearMonth date, Long id) { | ||
Character character = characterRepository.findById(id).orElseThrow(CharacterNotFoundException::new); | ||
List<Quest> quests = character.getQuests(); | ||
// YearMonth 필터링 | ||
List<Quest> filteredByDate = quests.stream() | ||
.filter(quest -> YearMonth.from(quest.getCreatedAt().toLocalDate()).equals(date)) | ||
.collect(Collectors.toList()); | ||
|
||
List<RetrieveCalendarRes> calendarRes = filteredByDate.stream(). | ||
map(f -> RetrieveCalendarRes.builder() | ||
.id(f.getId()) | ||
.exp(f.getExp()) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
ApiResponse apiResponse = ApiResponse.builder() | ||
.check(true) | ||
.information(calendarRes) | ||
.build(); | ||
|
||
return ResponseEntity.ok(apiResponse); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/noplanb/domain/quest/controller/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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.noplanb.domain.quest.controller; | ||
|
||
import com.noplanb.domain.quest.application.CalendarService; | ||
import com.noplanb.domain.quest.dto.res.RetrieveCalendarRes; | ||
import com.noplanb.domain.quest.dto.res.RetrieveQuestRes; | ||
import com.noplanb.global.payload.ErrorResponse; | ||
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.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.time.LocalDate; | ||
import java.time.YearMonth; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/calendar") | ||
@Tag(name = "CalendarController", description = "CalendarController입니다.") | ||
public class CalendarController { | ||
private final CalendarService calendarService; | ||
@GetMapping("/{date}/{id}") | ||
@Operation(summary = "달력 경험치 조회", description = "달력경험치를 조회할 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "달력 조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = RetrieveCalendarRes.class))}), | ||
@ApiResponse(responseCode = "400", description = "달력 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), | ||
}) | ||
public ResponseEntity<?> retrieveCalendar( | ||
// @Parameter(description = "Access Token을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, | ||
@Parameter(example = "2024-08", description = "날짜를 입력해주세요", required = true) @PathVariable("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) YearMonth date, | ||
@Parameter(description = "Access Token을 입력해주세요.", required = true) @PathVariable Long id){ | ||
return calendarService.retrieveQuest(date,id); | ||
} | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/noplanb/domain/quest/dto/req/ModifyQuestReq.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,15 @@ | ||
package com.noplanb.domain.quest.dto.req; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@Schema(description = "ModifyQuestReq") | ||
public class ModifyQuestReq { | ||
@Schema(type = "Long", example = "1", description = "퀘스트 ID") | ||
private Long id; | ||
@Schema(type = "String", example = "빨래하기", description = "퀘스트 내용") | ||
private String contents; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/noplanb/domain/quest/dto/res/RetrieveCalendarRes.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,13 @@ | ||
package com.noplanb.domain.quest.dto.res; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
@Builder | ||
@Getter | ||
public class RetrieveCalendarRes { | ||
@Schema(type = "Long", example = "1", description = "퀘스트 아이디") | ||
private Long id; | ||
@Schema(type = "Long", example = "5", description = "퀘스트 경험치") | ||
private Long exp; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/noplanb/domain/quest/dto/res/RetrieveLevelAndTodayExpRes.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,19 @@ | ||
package com.noplanb.domain.quest.dto.res; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class RetrieveLevelAndTodayExpRes { | ||
@Schema(type = "Long", example = "11", description = "현재 레벨") | ||
private Long level; | ||
@Schema(type = "Long", example = "5", description = "다음 레벨업까지 획득한 경험치") | ||
private Long acquireExp; | ||
@Schema(type = "Long", example = "10", description = "다음 레벨업까지 필요한 경험치") | ||
private Long needExp; | ||
@Schema(type = "Long", example = "5", description = "오늘 얻은 경험치") | ||
private Long todayExp; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/noplanb/domain/quest/dto/res/RetrieveQuestRes.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,18 @@ | ||
package com.noplanb.domain.quest.dto.res; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class RetrieveQuestRes { | ||
@Schema(type = "Long", example = "1", description = "퀘스트 아이디") | ||
private Long id; | ||
@Schema(type = "String", example = "청소하기", description = "퀘스트 내용") | ||
private String contents; | ||
@Schema(type = "Long", example = "5", description = "퀘스트 경험치") | ||
private Long exp; | ||
@Schema(type = "Boolean", example = "true", description = "퀘스트 완료 여부") | ||
private Boolean isComplete; | ||
} |
Oops, something went wrong.