Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8d6c727
initial commit
manoger May 11, 2019
c96acef
initial commit
manoger May 12, 2019
4fec9ac
Spock REST API Test
manoger May 12, 2019
3f83ce1
Spock REST API Test dependency.
manoger May 13, 2019
03d61ba
Added integration tests for the controller.
manoger May 13, 2019
e1e3a28
Created an spock specification for unit test ( in development )
manoger May 13, 2019
9b13303
Repository spock initial experiments
manoger May 13, 2019
0db96fe
Pandora added
manoger May 13, 2019
0d5be60
Unit test under experimentation
manoger May 13, 2019
fdcff19
refactored ids
AnaBeatrizNeri May 14, 2019
b0eaadd
deleted DELETE method
AnaBeatrizNeri May 14, 2019
fe5da53
refactored JPQL
AnaBeatrizNeri May 14, 2019
e90dca8
refactored tests
AnaBeatrizNeri May 14, 2019
461a408
New specifications
AnaBeatrizNeri May 15, 2019
b54f36c
Extracted methods and deleted experimental methods
manoger May 20, 2019
debc9a1
Added exception for blank authenticatedUserId
manoger May 20, 2019
3411b93
Added restriction exception for the Json in POST requests
manoger May 20, 2019
f59e532
Refactored spock tests
manoger May 20, 2019
935723e
Refactored SPOCK framework tests
manoger May 20, 2019
3c47ec2
Added READ ME
manoger May 20, 2019
3043462
Added new dependencies
manoger May 20, 2019
83f7846
Removed typo
manoger May 20, 2019
b1dc97f
added final keyword to params
manoger May 27, 2019
1643c51
EOL at EOF
manoger May 27, 2019
1d9f425
EOL at EOF
manoger Jun 1, 2019
f7a8c2f
Significant change: Profile options that have two states are now bool…
manoger Jun 2, 2019
530cadf
Deleted: BlankIdException
manoger Jun 2, 2019
1df46f3
Deleted: findPlayerIdWithAuthenticatedUserId
manoger Jun 2, 2019
0e656c2
Deleted: findPlayerIdWithAuthenticatedUserId
manoger Jun 2, 2019
54360d1
Refactored test names
manoger Jun 2, 2019
7ca616b
Added spring fox swagger :smile:
manoger Sep 29, 2019
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pandora"]
path = pandora
url = https://github.com/hex-g/pandora.git
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
# player
---
**The profile data API**

*"A person in its life is as a player."*

### First steps
(Configuring the environment):

1. git clone https://github.com/hex-g/player.git
1. cd player
2. git checkout [branch]
3. git submodule init
4. git submodule update
5. Run the project in your IDE
---
### Usage
> URL: `http://localhost:9600/`

#### ![#c5f015](https://placehold.it/15/c5f015/000000?text=+) `GET`
If an request profile data does not exist then a new one be created.
* `header`
* *key*: `authenticated-user-id`
* *value*: [string]

#### ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `POST`
Inserts a new profile data or updates an existent.
* `header`
* *key*: `authenticated-user-id`
* *value*: [string]
* `body JSON`
* *value*:
```
{
"loginAlias": string,
"email": string,
"telnumber": string,
"flavorText": string,
"birthday": string,
"options": {
"laurel_wreath": string,
"honorific": string,
"darkmode": string["on"/"off"],
"notify_hiveshare": string["on"/"off"],
"notify_hivecentral": string["on"/"off"],
"notify_disciplines": string["on"/"off"]
},
"social": {
"github": string,
"linkedIn": string,
"twitter": string
}
}
```


69 changes: 69 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
springCloudVersion = 'Greenwich.SR1'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" as Object
classpath "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" as Object
}
}

plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
id 'java'
id 'org.springframework.boot' version '2.1.3.RELEASE'
}

apply plugin: 'groovy'
apply plugin: 'io.spring.dependency-management'

group = 'hive'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
implementation project(':pandora')

implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.activation:activation:1.1.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
//production db:
//implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
//development db:
implementation 'com.h2database:h2'

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox:springfox-swagger-ui:2.9.2'

testCompile(
'org.hamcrest:hamcrest-core:1.3',//if not using delete this
'org.spockframework:spock-core:1.3-groovy-2.5',
'org.spockframework:spock-spring:1.3-groovy-2.5'
)
}

dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
bootJar(){
launchScript()
}
1 change: 1 addition & 0 deletions pandora
Submodule pandora added at 1d677c
11 changes: 2 additions & 9 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/5.2.1/userguide/multi_project_builds.html
*/

rootProject.name = 'player'
include 'pandora'
include 'ishigami'
14 changes: 14 additions & 0 deletions src/main/java/hive/player/PlayerApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hive.player;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
@EnableEurekaClient
public class PlayerApplication {
public static void main(String[] args) {
SpringApplication.run(PlayerApplication.class, args);
}
}
62 changes: 62 additions & 0 deletions src/main/java/hive/player/controller/PlayerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package hive.player.controller;

import static hive.pandora.constant.HiveInternalHeaders.*;

import hive.player.entity.Player;
import hive.player.exception.PlayerIdShouldNotBeInJsonException;
import hive.player.repository.PlayerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/")
public class PlayerController {
private final PlayerRepository playerRepository;

@Autowired
public PlayerController(final PlayerRepository playerRepository) {
this.playerRepository = playerRepository;
}

@GetMapping
public Player retrieveProfileData(
@RequestHeader(name = AUTHENTICATED_USER_ID) final String authenticatedUserId
) {
return createAnPlayerInDatabaseIfNotExists(authenticatedUserId);
}

@PostMapping
public void insertProfileData(
@RequestHeader(name = AUTHENTICATED_USER_ID) final String authenticatedUserId,
@RequestBody final Player player
) {
if(player.getPlayerId() != null){
throw new PlayerIdShouldNotBeInJsonException();
}
updatePlayerCorrelatedWithTheAuthenticatedId(player, authenticatedUserId);
player.setAuthenticatedUserId(authenticatedUserId);
playerRepository.save(player);
}

private Player createAnPlayerInDatabaseIfNotExists(final String authenticatedUserId) {
var player = playerRepository.findByAuthenticatedUserId(authenticatedUserId);
if (player == null) {
player = new Player(authenticatedUserId);
playerRepository.save(player);
}
return player;
}

private void updatePlayerCorrelatedWithTheAuthenticatedId(
final Player player,
final String authenticatedUserId
) {
final var playerFound=playerRepository.findByAuthenticatedUserId(authenticatedUserId);
if(playerFound != null) {
final var autogeneratedPlayerId = playerFound.getPlayerId();
if (autogeneratedPlayerId != null) {
player.setPlayerId(autogeneratedPlayerId);
}
}
}
}
86 changes: 86 additions & 0 deletions src/main/java/hive/player/entity/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package hive.player.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "tb_user_profile")
public class Player {
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
//is some DBMS like Oracle you should change the strategy
private Integer playerId;
@JsonIgnore
private String authenticatedUserId;

@JsonProperty
@Column(name = "login_alias", unique = true)
private String loginAlias;
@JsonProperty
@Column(name = "email")
private String email;
@JsonProperty
@Column(name = "telnumber")
private String telnumber;
@JsonProperty
@Column(name = "flavor_text")
private String flavorText;
@JsonProperty
@Column(name = "birthday")
private String birthday;

@Embedded
@JsonProperty
@Column(name = "options")
private PlayerOptions options;
@Embedded
@JsonProperty
@Column(name = "social")
private PlayerSocial social;

public Integer getPlayerId() {
return playerId;
}

public void setPlayerId(final Integer playerId) {
this.playerId = playerId;
}

public String getAuthenticatedUserId() {
return authenticatedUserId;
}

public void setAuthenticatedUserId(@NotNull final String authenticatedUserId) {
this.authenticatedUserId = authenticatedUserId;
}

private Player() {
}

public Player(
@NotNull final String authenticatedUserId,
final String loginAlias,
final String email,
final String telNumber,
final String flavorText,
final String birthday,
final PlayerOptions options,
final PlayerSocial social
) {
setAuthenticatedUserId(authenticatedUserId);
this.loginAlias = loginAlias;
this.email = email;
this.telnumber = telNumber;
this.flavorText = flavorText;
this.birthday = birthday;
this.options = options;
this.social = social;
}
public Player(@NotNull final String authenticatedUserId){
setAuthenticatedUserId(authenticatedUserId);
}
}
30 changes: 30 additions & 0 deletions src/main/java/hive/player/entity/PlayerOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hive.player.entity;

import javax.persistence.Embeddable;

@Embeddable
public class PlayerOptions {
public String laurel_wreath;
public String honorific;
public Boolean darkmode;
public Boolean notify_hiveshare;
public Boolean notify_hivecentral;
public Boolean notify_disciplines;

public PlayerOptions(
final String laurel_wreath,
final String honorific,
final Boolean darkmode,
final Boolean notify_hiveshare,
final Boolean notify_hivecentral,
final Boolean notify_disciplines
) {
this.laurel_wreath = laurel_wreath;
this.honorific = honorific;
this.darkmode = darkmode;
this.notify_hiveshare = notify_hiveshare;
this.notify_hivecentral = notify_hivecentral;
this.notify_disciplines = notify_disciplines;
}
public PlayerOptions(){}
}
17 changes: 17 additions & 0 deletions src/main/java/hive/player/entity/PlayerSocial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hive.player.entity;

import javax.persistence.Embeddable;

@Embeddable
public class PlayerSocial {
public String github;
public String linkedIn;
public String twitter;

public PlayerSocial(final String github, final String linkedIn, final String twitter) {
this.github = github;
this.linkedIn = linkedIn;
this.twitter = twitter;
}
public PlayerSocial() {}
}
8 changes: 8 additions & 0 deletions src/main/java/hive/player/exception/BlankIdException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hive.player.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "The Authenticated user id can not be blank")
public class BlankIdException extends RuntimeException{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hive.player.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "The autogenerated playerId should not be in JSON")
public class PlayerIdShouldNotBeInJsonException extends RuntimeException{
}
13 changes: 13 additions & 0 deletions src/main/java/hive/player/repository/PlayerRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hive.player.repository;

import hive.player.entity.Player;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface PlayerRepository extends JpaRepository<Player,Integer> {

Player findByAuthenticatedUserId(final String authenticatedUserId);

}
Loading