Skip to content

Commit

Permalink
Merge pull request #89 from Xaptured/ESA-028
Browse files Browse the repository at this point in the history
Added teams table along with code flows
  • Loading branch information
Xaptured committed Nov 26, 2023
2 parents 98fc64f + 0ba4362 commit 1887d49
Show file tree
Hide file tree
Showing 14 changed files with 675 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.thejackfolio.microservices.thejackfolio_db.exceptions.DataBaseOperationException;
import com.thejackfolio.microservices.thejackfolio_db.exceptions.EventException;
import com.thejackfolio.microservices.thejackfolio_db.exceptions.MapperException;
import com.thejackfolio.microservices.thejackfolio_db.exceptions.TeamException;
import com.thejackfolio.microservices.thejackfolio_db.models.Event;
import com.thejackfolio.microservices.thejackfolio_db.models.Team;
import com.thejackfolio.microservices.thejackfolio_db.services.EventService;
import com.thejackfolio.microservices.thejackfolio_db.utilities.StringConstants;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -37,7 +39,7 @@ public ResponseEntity<Event> saveOrUpdateEvent(@RequestBody Event event, @Reques
if(event == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
event = service.saveEvent(event, isCreate, isUpdate);
event = service.saveOrUpdateEvent(event, isCreate, isUpdate);
event.setMessage(StringConstants.REQUEST_PROCESSED);
} catch (MapperException | DataBaseOperationException | EventException exception) {
event.setMessage(exception.getMessage());
Expand Down Expand Up @@ -66,4 +68,44 @@ public ResponseEntity<Event> getEvent(@PathVariable String name) {
}
return ResponseEntity.status(HttpStatus.OK).body(event);
}

@Operation(
summary = "Save OR Update teams",
description = "Save or Update teams and gives the same team response with a message which defines whether the request is successful or not."
)
@PostMapping("/save-team")
public ResponseEntity<Team> saveOrUpdateTeam(@RequestBody Team team, @RequestParam boolean isCreate, @RequestParam boolean isUpdate) {
try {
if(team == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
team = service.saveOrUpdateTeam(team, isCreate, isUpdate);
team.setMessage(StringConstants.REQUEST_PROCESSED);
} catch (MapperException | DataBaseOperationException | TeamException exception) {
team.setMessage(exception.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(team);
}
return ResponseEntity.status(HttpStatus.CREATED).body(team);
}

@Operation(
summary = "Get team",
description = "Get team with a message which defines whether the request is successful or not."
)
@GetMapping("/get-team/{name}")
public ResponseEntity<Team> getTeam(@PathVariable String name) {
Team team = null;
try {
if(name == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
team = service.getTeam(name);
team.setMessage(StringConstants.REQUEST_PROCESSED);
} catch (MapperException | DataBaseOperationException exception) {
team = new Team();
team.setMessage(exception.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(team);
}
return ResponseEntity.status(HttpStatus.OK).body(team);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2023.
* Created this for the project called "TheJackFolio"
* All right reserved by Jack
*/

package com.thejackfolio.microservices.thejackfolio_db.entities;

import jakarta.persistence.*;

import java.util.Objects;

@Entity
@Table(name = "team_details")
public class TeamDetails {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "email")
private String email;
@Column(name = "team_id")
private Integer teamId;
@Column(name = "player_number")
private Integer playerNumber;

public TeamDetails() {
}

public TeamDetails(Integer id, String email, Integer teamId, Integer playerNumber) {
this.id = id;
this.email = email;
this.teamId = teamId;
this.playerNumber = playerNumber;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Integer getTeamId() {
return teamId;
}

public void setTeamId(Integer teamId) {
this.teamId = teamId;
}

public Integer getPlayerNumber() {
return playerNumber;
}

public void setPlayerNumber(Integer playerNumber) {
this.playerNumber = playerNumber;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TeamDetails that = (TeamDetails) o;
return Objects.equals(id, that.id) && Objects.equals(email, that.email) && Objects.equals(teamId, that.teamId) && Objects.equals(playerNumber, that.playerNumber);
}

@Override
public int hashCode() {
return Objects.hash(id, email, teamId, playerNumber);
}

@Override
public String toString() {
return "TeamDetails{" +
"id=" + id +
", email='" + email + '\'' +
", teamId=" + teamId +
", playerNumber=" + playerNumber +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2023.
* Created this for the project called "TheJackFolio"
* All right reserved by Jack
*/

package com.thejackfolio.microservices.thejackfolio_db.entities;

import com.thejackfolio.microservices.thejackfolio_db.enums.TeamStatus;
import jakarta.persistence.*;

import java.util.Objects;

@Entity
@Table(name = "teams")
public class Teams {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "event_id")
private Integer eventId;
@Column(name = "status")
private TeamStatus teamStatus;

public Teams() {
}

public Teams(Integer id, String name, Integer eventId, TeamStatus teamStatus) {
this.id = id;
this.name = name;
this.eventId = eventId;
this.teamStatus = teamStatus;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getEventId() {
return eventId;
}

public void setEventId(Integer eventId) {
this.eventId = eventId;
}

public TeamStatus getTeamStatus() {
return teamStatus;
}

public void setTeamStatus(TeamStatus teamStatus) {
this.teamStatus = teamStatus;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Teams teams = (Teams) o;
return Objects.equals(id, teams.id) && Objects.equals(name, teams.name) && Objects.equals(eventId, teams.eventId) && teamStatus == teams.teamStatus;
}

@Override
public int hashCode() {
return Objects.hash(id, name, eventId, teamStatus);
}

@Override
public String toString() {
return "Teams{" +
"id=" + id +
", name='" + name + '\'' +
", eventId=" + eventId +
", teamStatus=" + teamStatus +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

public enum EventStatus {

INACTIVE, ACTIVE, COMPLETED;
INACTIVE, ACTIVE, ONGOING, COMPLETED;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2023.
* Created this for the project called "TheJackFolio"
* All right reserved by Jack
*/

package com.thejackfolio.microservices.thejackfolio_db.enums;

public enum TeamStatus {

FREE, PENDING, PAID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2023.
* Created this for the project called "TheJackFolio"
* All right reserved by Jack
*/

package com.thejackfolio.microservices.thejackfolio_db.exceptions;

public class TeamException extends Exception{

public TeamException(String message) {
super(message);
}
}
Loading

0 comments on commit 1887d49

Please sign in to comment.