-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #973 from bounswe/backend/character
added character entity and related endpoints
- Loading branch information
Showing
6 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
app/backend/src/main/java/com/app/gamereview/controller/CharacterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.app.gamereview.controller; | ||
|
||
import com.app.gamereview.dto.request.character.CreateCharacterRequestDto; | ||
import com.app.gamereview.dto.request.character.UpdateCharacterRequestDto; | ||
import com.app.gamereview.model.Character; | ||
import com.app.gamereview.service.CharacterService; | ||
import com.app.gamereview.util.validation.annotation.AdminRequired; | ||
import com.app.gamereview.util.validation.annotation.AuthorizationRequired; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.validation.Valid; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/character") | ||
@Validated | ||
public class CharacterController { | ||
|
||
private final CharacterService characterService; | ||
|
||
public CharacterController(CharacterService characterService) { | ||
this.characterService = characterService; | ||
} | ||
|
||
@PostMapping("/create") | ||
@AuthorizationRequired | ||
@AdminRequired | ||
public ResponseEntity<Character> createCharacter(@Valid @RequestBody CreateCharacterRequestDto characterDto, | ||
@RequestHeader String Authorization, HttpServletRequest request) { | ||
Character character = characterService.createCharacter(characterDto); | ||
return ResponseEntity.ok(character); | ||
} | ||
|
||
@PostMapping("/update") | ||
@AuthorizationRequired | ||
@AdminRequired | ||
public ResponseEntity<Character> updateCharacter(@RequestParam String id, | ||
@Valid @RequestBody UpdateCharacterRequestDto updateCharacterRequestDto, | ||
@RequestHeader String Authorization, HttpServletRequest request) { | ||
Character character = characterService.updateCharacter(id, updateCharacterRequestDto); | ||
return ResponseEntity.ok(character); | ||
} | ||
|
||
@DeleteMapping("/delete") | ||
@AuthorizationRequired | ||
@AdminRequired | ||
public ResponseEntity<Character> deleteCharacter(@RequestParam String id, @RequestHeader String Authorization, | ||
HttpServletRequest request) { | ||
Character character = characterService.deleteCharacter(id); | ||
return ResponseEntity.ok(character); | ||
} | ||
|
||
@GetMapping("/get-game-characters") | ||
public ResponseEntity<List<Character>> getGameCharacters(@RequestParam String gameId) { | ||
List<Character> gameCharacters = characterService.getGameCharacters(gameId); | ||
return ResponseEntity.ok(gameCharacters); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...end/src/main/java/com/app/gamereview/dto/request/character/CreateCharacterRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.app.gamereview.dto.request.character; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CreateCharacterRequestDto { | ||
|
||
@NotEmpty(message = "Character name cannot be empty.") | ||
private String name; | ||
|
||
@NotEmpty(message = "Character icon cannot be empty.") | ||
private String icon; | ||
|
||
@NotEmpty(message = "Game list cannot be empty.") | ||
private List<@Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", | ||
message = "Game has invalid Id (UUID) format")String> games; | ||
|
||
private String type; | ||
|
||
private String gender; | ||
|
||
private String race; | ||
|
||
private String status; | ||
|
||
private String occupation; | ||
|
||
private String birthDate; | ||
|
||
private String voiceActor; | ||
|
||
private String height; | ||
|
||
private String age; | ||
|
||
private Map<String, String> customFields; | ||
} |
42 changes: 42 additions & 0 deletions
42
...end/src/main/java/com/app/gamereview/dto/request/character/UpdateCharacterRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.app.gamereview.dto.request.character; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class UpdateCharacterRequestDto { | ||
|
||
private String name; | ||
|
||
private String icon; | ||
|
||
private List<@Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", | ||
message = "Game has invalid Id (UUID) format")String> games; | ||
|
||
private String type; | ||
|
||
private String gender; | ||
|
||
private String race; | ||
|
||
private String status; | ||
|
||
private String occupation; | ||
|
||
private String birthDate; | ||
|
||
private String voiceActor; | ||
|
||
private String height; | ||
|
||
private String age; | ||
|
||
private Map<String, String> customFields; | ||
} |
46 changes: 46 additions & 0 deletions
46
app/backend/src/main/java/com/app/gamereview/model/Character.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.app.gamereview.model; | ||
|
||
import com.app.gamereview.model.common.BaseModel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import org.springframework.data.mongodb.core.mapping.Field; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Document(collection = "Character") | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Character extends BaseModel { | ||
private String name; | ||
|
||
private String icon; | ||
|
||
private List<String> games; | ||
|
||
private String type; | ||
|
||
private String gender; | ||
|
||
private String race; | ||
|
||
private String status; | ||
|
||
private String occupation; | ||
|
||
private String birthDate; | ||
|
||
private String voiceActor; | ||
|
||
private String height; | ||
|
||
private String age; | ||
|
||
@Field("customFields") | ||
private Map<String, String> customFields; | ||
} |
15 changes: 15 additions & 0 deletions
15
app/backend/src/main/java/com/app/gamereview/repository/CharacterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.app.gamereview.repository; | ||
|
||
import com.app.gamereview.model.Character; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CharacterRepository extends MongoRepository<Character, String> { | ||
|
||
Optional<Character> findByIdAndIsDeletedFalse(String id); | ||
|
||
List<Character> findByGamesContains(String game); | ||
|
||
} |
Oops, something went wrong.