Skip to content

Commit

Permalink
πŸ§ͺ [Test] Admin ν…œν”Œλ¦Ώ μΆ”κ°€, 제거, μˆ˜μ • ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„± (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Mar 25, 2024
1 parent a61cb94 commit f07723d
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TemplateAdminController {
* return 201 status code(성곡적인 μΆ”κ°€ status)
*/
@PostMapping
public ResponseEntity<Void> addTemplate(@RequestBody TemplateAdminCreateReqDto request) {
public ResponseEntity<Void> addTemplate(@RequestBody @Valid TemplateAdminCreateReqDto request) {
templateAdminService.addTemplate(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package gg.party.api.admin.templates.controller.request;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import gg.data.party.Category;
import gg.data.party.GameTemplate;
import lombok.Getter;
Expand All @@ -8,16 +13,53 @@
@Getter
@NoArgsConstructor
public class TemplateAdminCreateReqDto {
@NotNull(message = "μΉ΄ν…Œκ³ λ¦¬ IDλŠ” ν•„μˆ˜μž…λ‹ˆλ‹€.")
private Long categoryId;

@NotBlank(message = "κ²Œμž„ 이름은 ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 15, message = "κ²Œμž„ 이름은 15자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String gameName;

@NotNull(message = "μ΅œλŒ€ κ²Œμž„ 인원은 ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 2, message = "μ΅œλŒ€ κ²Œμž„ 인원은 μ΅œμ†Œ 2λͺ… 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer maxGamePeople;

@NotNull(message = "μ΅œμ†Œ κ²Œμž„ 인원은 ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 2, message = "μ΅œμ†Œ κ²Œμž„ 인원은 μ΅œμ†Œ 2λͺ… 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer minGamePeople;

@NotNull(message = "μ΅œλŒ€ κ²Œμž„ μ‹œκ°„μ€ ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 1, message = "μ΅œλŒ€ κ²Œμž„ μ‹œκ°„μ€ μ΅œμ†Œ 1λΆ„ 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer maxGameTime;

@NotNull(message = "μ΅œμ†Œ κ²Œμž„ μ‹œκ°„μ€ ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 1, message = "μ΅œμ†Œ κ²Œμž„ μ‹œκ°„μ€ μ΅œμ†Œ 1λΆ„ 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer minGameTime;

@NotBlank(message = "μž₯λ₯΄λŠ” ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 10, message = "μž₯λ₯΄λŠ” 10자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String genre;

@Size(max = 10, message = "λ‚œμ΄λ„λŠ” 10자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String difficulty;

@NotBlank(message = "λ‚΄μš©μ€ ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 100, message = "λ‚΄μš©μ€ 100자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String summary;

public TemplateAdminCreateReqDto(long categoryId, String gameName, int maxGamePeople, int minGamePeople,
int maxGameTime, int minGameTime, String genre, String difficulty, String summary) {
this.categoryId = categoryId;
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 static GameTemplate toEntity(TemplateAdminCreateReqDto dto, Category category) {
return GameTemplate.builder()
.category(category)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
package gg.party.api.admin.templates.controller.request;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class TemplateAdminUpdateReqDto {
@NotNull(message = "Category must not be null")
@NotNull(message = "μΉ΄ν…Œκ³ λ¦¬ IDλŠ” ν•„μˆ˜μž…λ‹ˆλ‹€.")
private Long categoryId;

@NotNull(message = "Game name must not be null")
@NotBlank(message = "κ²Œμž„ 이름은 ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 15, message = "κ²Œμž„ 이름은 15자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String gameName;

@NotNull(message = "Maximum game people must not be null")
@NotNull(message = "μ΅œλŒ€ κ²Œμž„ 인원은 ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 2, message = "μ΅œλŒ€ κ²Œμž„ 인원은 μ΅œμ†Œ 2λͺ… 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer maxGamePeople;

@NotNull(message = "Minimum game people must not be null")
@NotNull(message = "μ΅œμ†Œ κ²Œμž„ 인원은 ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 2, message = "μ΅œμ†Œ κ²Œμž„ 인원은 μ΅œμ†Œ 2λͺ… 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer minGamePeople;

@NotNull(message = "Maximum game time must not be null")
@NotNull(message = "μ΅œλŒ€ κ²Œμž„ μ‹œκ°„μ€ ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 1, message = "μ΅œλŒ€ κ²Œμž„ μ‹œκ°„μ€ μ΅œμ†Œ 1λΆ„ 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer maxGameTime;

@NotNull(message = "Minimum game time must not be null")
@NotNull(message = "μ΅œμ†Œ κ²Œμž„ μ‹œκ°„μ€ ν•„μˆ˜μž…λ‹ˆλ‹€.")
@Min(value = 1, message = "μ΅œμ†Œ κ²Œμž„ μ‹œκ°„μ€ μ΅œμ†Œ 1λΆ„ 이상이어야 ν•©λ‹ˆλ‹€.")
private Integer minGameTime;

@NotBlank(message = "μž₯λ₯΄λŠ” ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 10, message = "μž₯λ₯΄λŠ” 10자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String genre;

@Size(max = 10, message = "λ‚œμ΄λ„λŠ” 10자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String difficulty;

@NotNull(message = "Summary must not be null")
@NotBlank(message = "λ‚΄μš©μ€ ν•„μˆ˜μ΄λ©°, λΉ„μ–΄ μžˆμ„ 수 μ—†μŠ΅λ‹ˆλ‹€.")
@Size(max = 100, message = "λ‚΄μš©μ€ 100자λ₯Ό μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
private String summary;

public TemplateAdminUpdateReqDto(long categoryId, String gameName, int maxGamePeople, int minGamePeople,
int maxGameTime, int minGameTime, String genre, String difficulty, String summary) {
this.categoryId = categoryId;
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
Expand Up @@ -21,7 +21,7 @@ public class TemplateAdminService {

/**
* ν…œν”Œλ¦Ώ μΆ”κ°€
* @exception CategoryNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μΉ΄ν…Œκ³ λ¦¬ μž…λ ₯
* @exception CategoryNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μΉ΄ν…Œκ³ λ¦¬ μž…λ ₯ - 404
*/
public void addTemplate(TemplateAdminCreateReqDto request) {
Category category = categoryRepository.findById(request.getCategoryId())
Expand All @@ -34,8 +34,8 @@ public void addTemplate(TemplateAdminCreateReqDto request) {

/**
* ν…œν”Œλ¦Ώ μˆ˜μ •
* @exception TemplateNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν…œν”Œλ¦Ώ μž…λ ₯
* @exception CategoryNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μΉ΄ν…Œκ³ λ¦¬ μž…λ ₯
* @exception TemplateNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν…œν”Œλ¦Ώ μž…λ ₯ - 404
* @exception CategoryNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μΉ΄ν…Œκ³ λ¦¬ μž…λ ₯ - 404
*/
@Transactional
public void modifyTemplate(Long templateId, TemplateAdminUpdateReqDto request) {
Expand Down Expand Up @@ -64,7 +64,7 @@ public void modifyTemplate(Long templateId, TemplateAdminUpdateReqDto request) {

/**
* ν…œν”Œλ¦Ώ μ‚­μ œ
* @exception TemplateNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν…œν”Œλ¦Ώ μž…λ ₯
* @exception TemplateNotFoundException μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν…œν”Œλ¦Ώ μž…λ ₯ - 404
*/
@Transactional
public void removeTemplate(Long templateId) {
Expand Down
Loading

0 comments on commit f07723d

Please sign in to comment.