diff --git a/gg-data/src/main/java/gg/data/party/GameTemplate.java b/gg-data/src/main/java/gg/data/party/GameTemplate.java index 5454c6bf1..cd3640954 100644 --- a/gg-data/src/main/java/gg/data/party/GameTemplate.java +++ b/gg-data/src/main/java/gg/data/party/GameTemplate.java @@ -64,4 +64,22 @@ 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) { + this.gameName = gameName; + this.maxGamePeople = maxGamePeople; + this.minGamePeople = minGamePeople; + this.maxGameTime = maxGameTime; + this.minGameTime = minGameTime; + this.genre = genre; + this.difficulty = difficulty; + this.summary = summary; + } + + public void modifyCategory(Category category) { + this.category = category; + } + } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java index 33a2416eb..669065fd5 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java @@ -1,8 +1,11 @@ package gg.party.api.admin.templates.controller; +import javax.validation.Valid; + 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; @@ -10,6 +13,7 @@ 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; @@ -29,6 +33,17 @@ public ResponseEntity addTemplate(@RequestBody TemplateAdminCreateReqDto r return ResponseEntity.status(HttpStatus.CREATED).build(); } + /** + * 템플릿 수정 + * return 204 status code(성공적인 수정 status) + */ + @PatchMapping("/{templateId}") + public ResponseEntity updateTemplate(@PathVariable Long templateId, + @Valid @RequestBody TemplateAdminUpdateReqDto request) { + templateAdminService.modifyTemplate(templateId, request); + return ResponseEntity.noContent().build(); + } + /** * 템플릿 삭제 * return 204 status code(성공적인 삭제 status) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/request/TemplateAdminUpdateReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/request/TemplateAdminUpdateReqDto.java new file mode 100644 index 000000000..4a06063b1 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/request/TemplateAdminUpdateReqDto.java @@ -0,0 +1,34 @@ +package gg.party.api.admin.templates.controller.request; + +import javax.validation.constraints.NotNull; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class TemplateAdminUpdateReqDto { + @NotNull(message = "Category must not be null") + private Long categoryId; + + @NotNull(message = "Game name must not be null") + private String gameName; + + @NotNull(message = "Maximum game people must not be null") + private Integer maxGamePeople; + + @NotNull(message = "Minimum game people must not be null") + private Integer minGamePeople; + + @NotNull(message = "Maximum game time must not be null") + private Integer maxGameTime; + + @NotNull(message = "Minimum game time must not be null") + private Integer minGameTime; + + private String genre; + private String difficulty; + + @NotNull(message = "Summary must not be null") + private String summary; +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java index 2dfeb8fec..4b68a3314 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java @@ -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; @@ -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( + 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 존재하지 않는 템플릿 입력