Skip to content

Commit

Permalink
feat: mission content recommend time (#122)
Browse files Browse the repository at this point in the history
* feat: Add recommend_time column

* feat: fix mission content dto

* feat: fix RoundMissionContentDto field image to recommendTime

* chore: fix ci checker name and jobs
  • Loading branch information
jinsu4755 authored Sep 5, 2023
1 parent 7ef38d8 commit 5162ca2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 85 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/ci_checker_on_main_push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Uni PR Builder
name: On Push CI

on:
push:
Expand All @@ -14,16 +14,6 @@ jobs:
tasks : '["checkstyleMain", "checkstyleTest", "build -x test", "test"]'
secrets: inherit

publish-test-result:
needs:
- ci
runs-on: ubuntu-latest
steps:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: build/test-results/**/*.xml

result-failure:
needs:
- ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public class MissionContent {
@Column(name = "content", nullable = false)
private String content;

@Column(name = "image", nullable = false)
private String image;
@Column(name = "recommend_time", nullable = false)
private String recommendTime;
}
14 changes: 11 additions & 3 deletions src/main/java/com/universe/uni/dto/MissionContentDto.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.universe.uni.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@JsonPropertyOrder({"id", "content"})
@JsonPropertyOrder({"id", "content", "recommend_time"})
@Schema(description = "미션 내용을 담는 DTO")
@Builder
public record MissionContentDto(
Long id,
String content
@Schema(description = "미션 내용 id")
Long id,
@Schema(description = "미션 내용")
String content,
@Schema(description = "미션 추천 시간")
@JsonProperty("recommend_time")
String recommendTime
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class RoundMissionContentDto {
private final Long id;
private final MissionCategoryDto missionCategory;
private final String content;
private final String image;
private final String recommendTime;

public RoundMissionContentDto(MissionContent missionContent) {
this.id = missionContent.getId();
this.missionCategory = new MissionCategoryDto(missionContent.getMissionCategory());
this.content = missionContent.getContent();
this.image = missionContent.getImage();
this.recommendTime = missionContent.getRecommendTime();
}
}
135 changes: 68 additions & 67 deletions src/main/java/com/universe/uni/service/MissionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import static com.universe.uni.exception.dto.ErrorType.NOT_FOUND_MISSION_CATEGORY_EXCEPTION;
import static com.universe.uni.exception.dto.ErrorType.NOT_FOUND_MISSION_CONTENT;

import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.universe.uni.domain.entity.MissionCategory;
import com.universe.uni.domain.entity.MissionContent;
import com.universe.uni.dto.MissionContentDto;
Expand All @@ -18,72 +11,80 @@
import com.universe.uni.repository.MissionCategoryRepository;
import com.universe.uni.repository.MissionContentRepository;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional
public class MissionService {

private final MissionCategoryRepository missionCategoryRepository;
private final MissionContentRepository missionContentRepository;

public MissionCategory getMissionCategoryById(Long missionCategoryId) {
return missionCategoryRepository.findById(missionCategoryId)
.orElseThrow(() -> new NotFoundException(NOT_FOUND_MISSION_CATEGORY_EXCEPTION));
}

public MissionContent getMissionContentByRandom(MissionCategory missionCategory) {
List<MissionContent> missionContentList = missionContentRepository.findByMissionCategory(missionCategory);

try {
int randomIndex = new Random().nextInt(missionContentList.size());
return missionContentList.get(randomIndex);
} catch (Exception exception) {
throw new NotFoundException(NOT_FOUND_MISSION_CONTENT);
}
}

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

public List<MissionCategoryResponseDto> getMissionCategoryList() {
List<MissionCategory> missionCategoryList = missionCategoryRepository.findAll();
return missionCategoryList
.stream()
.map(this::fromMissionCategoryToMissionCategoryResponseDto)
.toList();
}

private MissionCategoryResponseDto fromMissionCategoryToMissionCategoryResponseDto(
MissionCategory missionCategory) {

List<MissionContent> missionContentList = missionContentRepository.findByMissionCategoryId(
missionCategory.getId());

List<MissionContentDto> missionContentDtoList = missionContentList.stream()
.map(this::fromMissionContentToMissionContentResponseDto)
.collect(Collectors.toList());

return MissionCategoryResponseDto.builder()
.id(missionCategory.getId())
.title(missionCategory.getTitle())
.description(missionCategory.getDescription())
.rule(missionCategory.getRule())
.tip(missionCategory.getTip())
.image(missionCategory.getImage())
.missionContentList(missionContentDtoList)
.build();
}

private MissionContentDto fromMissionContentToMissionContentResponseDto(MissionContent missionContent) {
return MissionContentDto.builder()
.id(missionContent.getId())
.content(missionContent.getContent())
.build();
}
private final MissionCategoryRepository missionCategoryRepository;
private final MissionContentRepository missionContentRepository;

public MissionCategory getMissionCategoryById(Long missionCategoryId) {
return missionCategoryRepository.findById(missionCategoryId)
.orElseThrow(() -> new NotFoundException(NOT_FOUND_MISSION_CATEGORY_EXCEPTION));
}

public MissionContent getMissionContentByRandom(MissionCategory missionCategory) {
List<MissionContent> missionContentList = missionContentRepository.findByMissionCategory(missionCategory);

try {
int randomIndex = new Random().nextInt(missionContentList.size());
return missionContentList.get(randomIndex);
} catch (Exception exception) {
throw new NotFoundException(NOT_FOUND_MISSION_CONTENT);
}
}

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

public List<MissionCategoryResponseDto> getMissionCategoryList() {
List<MissionCategory> missionCategoryList = missionCategoryRepository.findAll();
return missionCategoryList
.stream()
.map(this::fromMissionCategoryToMissionCategoryResponseDto)
.toList();
}

private MissionCategoryResponseDto fromMissionCategoryToMissionCategoryResponseDto(
MissionCategory missionCategory) {

List<MissionContent> missionContentList = missionContentRepository.findByMissionCategoryId(
missionCategory.getId());

List<MissionContentDto> missionContentDtoList = missionContentList.stream()
.map(this::fromMissionContentToMissionContentResponseDto)
.collect(Collectors.toList());

return MissionCategoryResponseDto.builder()
.id(missionCategory.getId())
.title(missionCategory.getTitle())
.description(missionCategory.getDescription())
.rule(missionCategory.getRule())
.tip(missionCategory.getTip())
.image(missionCategory.getImage())
.missionContentList(missionContentDtoList)
.build();
}

private MissionContentDto fromMissionContentToMissionContentResponseDto(MissionContent missionContent) {
return MissionContentDto.builder()
.id(missionContent.getId())
.content(missionContent.getContent())
.recommendTime(missionContent.getRecommendTime())
.build();
}

}

0 comments on commit 5162ca2

Please sign in to comment.