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 #715

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 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 @@ -64,4 +64,37 @@ public GameTemplate(Category category, String gameName, Integer maxGamePeople, I
this.difficulty = difficulty;
this.summary = summary;
}

public void modifyTemplateDetails(String gameName, Integer maxGamePeople, Integer minGamePeople,
Integer maxGameTime, Integer minGameTime, String genre,
String difficulty, String summary) {
if (gameName != null) {
this.gameName = gameName;
}
if (maxGamePeople != null) {
this.maxGamePeople = maxGamePeople;
}
if (minGamePeople != null) {
this.minGamePeople = minGamePeople;
}
if (maxGameTime != null) {
this.maxGameTime = maxGameTime;
}
if (minGameTime != null) {
this.minGameTime = minGameTime;
}
if (genre != null) {
this.genre = genre;
}
if (difficulty != null) {
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
this.difficulty = difficulty;
}
if (summary != null) {
this.summary = summary;
}
}

public void modifyCategory(Category category) {
this.category = category;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.controller.request.TemplateAdminUpdateReqDto;
import gg.party.api.admin.templates.service.TemplateAdminService;
import lombok.RequiredArgsConstructor;

Expand All @@ -29,6 +31,17 @@ public ResponseEntity<Void> addTemplate(@RequestBody TemplateAdminCreateReqDto r
return ResponseEntity.status(HttpStatus.CREATED).build();
}

/**
* 템플릿 수정
* return 204 status code(성공적인 수정 status)
*/
@PatchMapping("/{templateId}")
public ResponseEntity<Void> updateTemplate(@PathVariable Long templateId,
@RequestBody TemplateAdminUpdateReqDto request) {
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
templateAdminService.modifyTemplate(templateId, request);
return ResponseEntity.noContent().build();
}

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

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class TemplateAdminUpdateReqDto {
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gg.data.party.Category;
import gg.data.party.GameTemplate;
import gg.party.api.admin.templates.controller.request.TemplateAdminCreateReqDto;
import gg.party.api.admin.templates.controller.request.TemplateAdminUpdateReqDto;
import gg.repo.party.CategoryRepository;
import gg.repo.party.TemplateRepository;
import gg.utils.exception.party.CategoryNotFoundException;
Expand All @@ -31,6 +32,36 @@ public void addTemplate(TemplateAdminCreateReqDto request) {
templateRepository.save(gameTemplate);
}

/**
* 템플릿 수정
* @exception TemplateNotFoundException 존재하지 않는 템플릿 입력
* @exception CategoryNotFoundException 존재하지 않는 카테고리 입력
*/
@Transactional
public void modifyTemplate(Long templateId, TemplateAdminUpdateReqDto request) {
GameTemplate template = templateRepository.findById(templateId)
.orElseThrow(TemplateNotFoundException::new);

template.modifyTemplateDetails(
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
request.getGameName(),
request.getMaxGamePeople(),
request.getMinGamePeople(),
request.getMaxGameTime(),
request.getMinGameTime(),
request.getGenre(),
request.getDifficulty(),
request.getSummary()
);

if (request.getCategoryId() != null) {
Category newCategory = categoryRepository.findById(request.getCategoryId())
.orElseThrow(CategoryNotFoundException::new);
template.modifyCategory(newCategory);
}

templateRepository.save(template);
}

/**
* 템플릿 삭제
* @exception TemplateNotFoundException 존재하지 않는 템플릿 입력
Expand Down
Loading