Skip to content

Commit

Permalink
fix: Delete and integrate mission category (#140)
Browse files Browse the repository at this point in the history
* fix: Deprecate MissionCategoryResponseDto

* fix: Fix mission Category Response
  • Loading branch information
jinsu4755 authored Dec 21, 2023
1 parent d369da8 commit 18c711f
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 1 deletion.
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();
}

}

0 comments on commit 18c711f

Please sign in to comment.