Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 미션 카테고리 불 필요 필드 및 불 일치 필드 삭제 및 통합 #140

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.universe.uni.controller;

import com.universe.uni.controller.docs.MissionControllerV1Contract;
import com.universe.uni.dto.response.MissionCategoryWithContentsDto;
import com.universe.uni.service.MissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/mission")
public class MissionCategoryControllerV1 implements MissionControllerV1Contract {
private final MissionService missionService;

@GetMapping("/{missionCategoryId}")
@ResponseStatus(HttpStatus.OK)
@Override
public MissionCategoryWithContentsDto getSelectedMissionCategory(@PathVariable Long missionCategoryId) {
return missionService.getSelectedMissionCategory(missionCategoryId);
}

@GetMapping()
@ResponseStatus(HttpStatus.OK)
@Override
public List<MissionCategoryWithContentsDto> getAllMissionCategories() {
return missionService.getMissionCategories();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public class MissionController implements MissionControllerContract {
private final MissionService missionService;

@GetMapping("/{missionCategoryId}")
@Deprecated
@ResponseStatus(HttpStatus.OK)
@Override
public MissionCategoryResponseDto getMissionCategory(@PathVariable Long missionCategoryId) {
return missionService.getMissionCategory(missionCategoryId);
}

@GetMapping()
@Deprecated
@ResponseStatus(HttpStatus.OK)
@Override
public List<MissionCategoryResponseDto> getMissionCategoryList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.universe.uni.controller.docs;

import com.universe.uni.dto.response.MissionCategoryResponseDto;
import com.universe.uni.dto.response.MissionCategoryWithContentsDto;
import com.universe.uni.exception.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
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.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.List;

@Tag(
name = "Mission",
description = "사용자의 미션 관련 API 입니다."
)
public interface MissionControllerV1Contract {

@Operation(
summary = "미션 카테고리 상세 조회",
description = "사용자는 미션 카테고리 아이디를 통해 상세 정보를 조회할 수 있다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = MissionCategoryResponseDto.class)
)
),
@ApiResponse(
responseCode = "404-UE5003",
description = "존재하지 않는 미션 카테고리입니다",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class)
)
),
@ApiResponse(
responseCode = "500-UE500",
description = "서버 내부 오류입니다.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class)
)
)
}
)
@GetMapping("/{missionCategoryId}")
@ResponseStatus(HttpStatus.OK)
MissionCategoryWithContentsDto getSelectedMissionCategory(
@Parameter(required = true)
@PathVariable Long missionCategoryId
);

@Operation(
summary = "미션 카테고리 전체 조회",
description = "사용자는 게임 생성시 미션의 모든 카테고리를 확인할 수 있다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(
schema = @Schema(implementation = MissionCategoryResponseDto.class)
)
)
),
@ApiResponse(
responseCode = "500-UE500",
description = "서버 내부 오류입니다.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class)
)
)
}
)
@GetMapping()
@ResponseStatus(HttpStatus.OK)
List<MissionCategoryWithContentsDto> getAllMissionCategories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public class MissionCategory {
@Column(name = "image", nullable = false)
private String image;

@Deprecated
@Column(name = "level", nullable = false)
private int level;

@Deprecated
@Column(name = "expected_time", nullable = false)
private int expectedTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public class MissionCategoryDto {
private final String tip;
private final String example;
private final String image;
@Schema(deprecated = true)
@Deprecated
private final int level;
@Schema(deprecated = true)
@Deprecated
private final int expectedTime;
@Schema(description = "미션 타입 [SAME, DIFFERENCE] enum 값")
private final MissionType missionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import java.util.List;

@Schema(description = "미션 카테고리 상세 정보 응답 DTO")
@Schema(description = "미션 카테고리 상세 정보 응답 DTO", deprecated = true)
@Deprecated
@JsonPropertyOrder({"id", "title", "description", "rule", "tip", "image", "missionContentList"})
@Builder
public record MissionCategoryResponseDto(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.universe.uni.dto.response;

import com.universe.uni.domain.entity.MissionCategory;
import com.universe.uni.dto.MissionContentDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.List;

@Schema(description = "미션 카테고리 정보 DTO")
@Getter
public class MissionCategoryWithContentsDto extends MissionCategoryDto {

private final List<MissionContentDto> missionContentsDto;

public MissionCategoryWithContentsDto(
MissionCategory missionCategory,
List<MissionContentDto> missionContentsDto
) {
super(missionCategory);
this.missionContentsDto = missionContentsDto;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/universe/uni/service/MissionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.universe.uni.domain.entity.MissionContent;
import com.universe.uni.dto.MissionContentDto;
import com.universe.uni.dto.response.MissionCategoryResponseDto;
import com.universe.uni.dto.response.MissionCategoryWithContentsDto;
import com.universe.uni.exception.NotFoundException;
import com.universe.uni.repository.MissionCategoryRepository;
import com.universe.uni.repository.MissionContentRepository;
Expand Down Expand Up @@ -44,12 +45,14 @@ public MissionContent getMissionContentByRandom(MissionCategory missionCategory)
}
}

@Deprecated
public MissionCategoryResponseDto getMissionCategory(Long missionCategoryId) {
MissionCategory missionCategory = missionCategoryRepository.findById(missionCategoryId)
.orElseThrow(() -> new NotFoundException(NOT_FOUND_MISSION_CATEGORY_EXCEPTION));
return fromMissionCategoryToMissionCategoryResponseDto(missionCategory);
}

@Deprecated
public List<MissionCategoryResponseDto> getMissionCategoryList() {
List<MissionCategory> missionCategoryList = missionCategoryRepository.findAll();
return missionCategoryList
Expand All @@ -58,6 +61,7 @@ public List<MissionCategoryResponseDto> getMissionCategoryList() {
.toList();
}

@Deprecated
private MissionCategoryResponseDto fromMissionCategoryToMissionCategoryResponseDto(
MissionCategory missionCategory) {

Expand Down Expand Up @@ -87,4 +91,27 @@ private MissionContentDto fromMissionContentToMissionContentResponseDto(MissionC
.build();
}

public MissionCategoryWithContentsDto getSelectedMissionCategory(Long missionCategoryId) {
MissionCategory missionCategory = missionCategoryRepository.findById(missionCategoryId)
.orElseThrow(() -> new NotFoundException(NOT_FOUND_MISSION_CATEGORY_EXCEPTION));
return new MissionCategoryWithContentsDto(missionCategory, getAllMissionContents(missionCategory.getId()));
}

public List<MissionCategoryWithContentsDto> getMissionCategories() {
List<MissionCategory> missionCategoryList = missionCategoryRepository.findAll();

return missionCategoryList
.stream()
.map(missionCategory -> new MissionCategoryWithContentsDto(missionCategory, getAllMissionContents(missionCategory.getId())))
.toList();
}

private List<MissionContentDto> getAllMissionContents(Long missionCategoryId) {
List<MissionContent> missionContentList = missionContentRepository.findByMissionCategoryId(missionCategoryId);

return missionContentList.stream()
.map(this::fromMissionContentToMissionContentResponseDto)
.toList();
}

}
Loading