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

✨ [Feature] 탬플릿 추가 API #700

Merged
merged 4 commits into from
Mar 9, 2024
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
15 changes: 15 additions & 0 deletions gg-data/src/main/java/gg/data/party/GameTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import gg.data.BaseTimeEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -49,4 +50,18 @@ public class GameTemplate extends BaseTimeEntity {

@Column(length = 100)
private String summary;

@Builder
public GameTemplate(Category category, String gameName, Integer maxGamePeople, Integer minGamePeople,
Integer maxGameTime, Integer minGameTime, String genre, String difficulty, String summary) {
this.category = category;
this.gameName = gameName;
this.maxGamePeople = maxGamePeople;
this.minGamePeople = minGamePeople;
this.maxGameTime = maxGameTime;
this.minGameTime = minGameTime;
this.genre = genre;
this.difficulty = difficulty;
this.summary = summary;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package gg.party.api.admin.templates.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.party.api.admin.templates.controller.request.TemplateAdminCreateReqDto;
import gg.party.api.admin.templates.service.TemplateAdminService;
import lombok.RequiredArgsConstructor;

Expand All @@ -15,6 +19,16 @@
public class TemplateAdminController {
private final TemplateAdminService templateAdminService;

/**
* 템플릿 추가
* return 201 status code(성공적인 추가 status)
*/
@PostMapping
public ResponseEntity<Void> addTemplate(@RequestBody TemplateAdminCreateReqDto request) {
templateAdminService.addTemplate(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

/**
* 템플릿 삭제
* return 204 status code(성공적인 삭제 status)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gg.party.api.admin.templates.controller.request;

import gg.data.party.Category;
import gg.data.party.GameTemplate;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class TemplateAdminCreateReqDto {
private Long categoryId;
private String gameName;
private Integer maxGamePeople;
private Integer minGamePeople;
private Integer maxGameTime;
private Integer minGameTime;
private String genre;
private String difficulty;
private String summary;

public static GameTemplate toEntity(TemplateAdminCreateReqDto dto, Category category) {
return GameTemplate.builder()
.category(category)
.gameName(dto.getGameName())
.maxGamePeople(dto.getMaxGamePeople())
.minGamePeople(dto.getMinGamePeople())
.maxGameTime(dto.getMaxGameTime())
.minGameTime(dto.getMinGameTime())
.genre(dto.getGenre())
.difficulty(dto.getDifficulty())
.summary(dto.getSummary())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.data.party.Category;
import gg.data.party.GameTemplate;
import gg.party.api.admin.templates.controller.request.TemplateAdminCreateReqDto;
import gg.repo.party.CategoryRepository;
import gg.repo.party.TemplateRepository;
import gg.utils.exception.party.CategoryNotFoundException;
import gg.utils.exception.party.TemplateNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class TemplateAdminService {
private final TemplateRepository templateRepository;
private final CategoryRepository categoryRepository;

/**
* 템플릿 추가
* @exception CategoryNotFoundException 존재하지 않는 카테고리 입력
*/
public void addTemplate(TemplateAdminCreateReqDto request) {
Category category = categoryRepository.findById(request.getCategoryId())
.orElseThrow(CategoryNotFoundException::new);

GameTemplate gameTemplate = TemplateAdminCreateReqDto.toEntity(request, category);

templateRepository.save(gameTemplate);
}

/**
* 템플릿 삭제
* @exception TemplateNotFoundException 존재하지 않는 템플릿 입력
*/
@Transactional
public void removeTemplate(Long templateId) {
Expand Down
Loading