Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into jwt

# Conflicts:
#	src/main/java/com/danielagapov/spawn/Repositories/IUserRepository.java
#	src/main/java/com/danielagapov/spawn/Services/OAuth/OAuthService.java
#	src/main/java/com/danielagapov/spawn/Services/User/IUserService.java
#	src/main/java/com/danielagapov/spawn/Services/User/UserService.java
  • Loading branch information
ShaneMander committed Feb 8, 2025
2 parents b7fda3c + 95dbc80 commit 333f738
Show file tree
Hide file tree
Showing 43 changed files with 2,585 additions and 587 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/syntax-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Spring Boot Syntax Check (Maven)

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-

- name: Compile the project (syntax check)
run: mvn clean compile -DskipTests

- name: Compile tests (syntax check for test files)
run: mvn test-compile -DskipTests

- name: Run test suite (but allow failures)
run: mvn test || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.danielagapov.spawn.Controllers;

import com.danielagapov.spawn.DTOs.BetaAccessSignUpDTO;
import com.danielagapov.spawn.Exceptions.Base.BaseNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.danielagapov.spawn.Services.BetaAccessSignUp.IBetaAccessSignUpService;

import java.util.List;

@RestController()
@RequestMapping("api/v1/betaAccessSignUp")
public class BetaAccessSignUpController {
private final IBetaAccessSignUpService service;

public BetaAccessSignUpController(IBetaAccessSignUpService service) {
this.service = service;
}

// full path: /api/v1/betaAccessSignUp/emails

/**
* Use case: when we'll want to send out emails for the beta access
*/
@GetMapping("emails")
public ResponseEntity<List<String>> getAllEmails() {
try {
return new ResponseEntity<>(service.getAllEmails(), HttpStatus.OK);
} catch (BaseNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// full path: /api/v1/betaAccessSignUp/

/**
* @return returns all signed-up users, for our own internal reference,
* without having to check the database
*/
@GetMapping
public ResponseEntity<List<BetaAccessSignUpDTO>> getAllRecords() {
try {
return new ResponseEntity<>(service.getAllBetaAccessSignUpRecords(), HttpStatus.OK);
} catch (BaseNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// full path: /api/v1/betaAccessSignUp

/**
* Sign-up endpoint for creating a new record
* @param dto constructed via front-end form submission
* @return back the DTO after being persisted into our database if successful.
* Otherwise, we'll throw a 500 (INTERNAL_SERVER_ERROR).
*/
@PostMapping
public ResponseEntity<BetaAccessSignUpDTO> signUp(@RequestBody BetaAccessSignUpDTO dto) {
try {
return new ResponseEntity<>(service.signUp(dto), HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@ public ResponseEntity<List<? extends IEventDTO>> getEventsCreatedByUserId(@PathV
}
}

// full path: /api/v1/events/friendTag/{tagId}?full=full&requestingUserId=requestingUserId
@GetMapping("friendTag/{tagId}")
public ResponseEntity<List<? extends IEventDTO>> getEventsByFriendTagId(@PathVariable UUID tagId, @RequestParam(value="full", required=false) boolean full, @RequestParam UUID requestingUserId) {
// full path: /api/v1/events/friendTag/{friendTagFilterId}
@GetMapping("friendTag/{friendTagFilterId}")
public ResponseEntity<List<FullFeedEventDTO>> getEventsByFriendTag(@PathVariable UUID friendTagFilterId) {
try {
if (full && requestingUserId != null) {
return new ResponseEntity<>(eventService.convertEventsToFullFeedEvents(eventService.getEventsByFriendTagId(tagId), requestingUserId), HttpStatus.OK);
} else {
return new ResponseEntity<>(eventService.getEventsByFriendTagId(tagId), HttpStatus.OK);
}
} catch (BasesNotFoundException e) {
return new ResponseEntity<>(eventService.getFilteredFeedEventsByFriendTagId(friendTagFilterId), HttpStatus.OK);
} catch (BaseNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.danielagapov.spawn.Controllers;

import com.danielagapov.spawn.DTOs.FriendRequestDTO;
import com.danielagapov.spawn.DTOs.FullFriendRequestDTO;
import com.danielagapov.spawn.Exceptions.Base.BaseNotFoundException;
import com.danielagapov.spawn.Services.FriendRequestService.IFriendRequestService;
import org.springframework.http.HttpStatus;
Expand All @@ -22,7 +23,7 @@ public FriendRequestController(IFriendRequestService friendRequestService) {

// full path: /api/v1/users/{id}/friend-requests
@GetMapping("{id}/friend-requests")
public ResponseEntity<List<FriendRequestDTO>> getIncomingFriendRequests(@PathVariable UUID id) {
public ResponseEntity<List<FullFriendRequestDTO>> getIncomingFriendRequests(@PathVariable UUID id) {
try {
return new ResponseEntity<>(friendRequestService.getIncomingFriendRequestsByUserId(id), HttpStatus.OK);
} catch (BaseNotFoundException e) {
Expand All @@ -32,6 +33,16 @@ public ResponseEntity<List<FriendRequestDTO>> getIncomingFriendRequests(@PathVar
}
}

// full path: /api/v1/users/friend-request
@PostMapping("friend-request")
public ResponseEntity<FriendRequestDTO> createFriendRequest(@RequestBody FriendRequestDTO friendReq) {
try {
return new ResponseEntity<>(friendRequestService.saveFriendRequest(friendReq), HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// full path: /api/v1/users/{userId}/friend-requests/{friendRequestId}/accept
@PutMapping("{userId}/friend-requests/{friendRequestId}/accept")
public ResponseEntity<Void> acceptFriendRequest(@PathVariable UUID userId, @PathVariable UUID friendRequestId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.danielagapov.spawn.DTOs.FriendTagDTO;
import com.danielagapov.spawn.DTOs.FullFriendTagDTO;
import com.danielagapov.spawn.DTOs.FullUserDTO;
import com.danielagapov.spawn.DTOs.IFriendTagDTO;
import com.danielagapov.spawn.Exceptions.Base.BaseNotFoundException;
import com.danielagapov.spawn.Exceptions.Base.BaseSaveException;
Expand Down Expand Up @@ -154,4 +155,35 @@ public ResponseEntity<List<FullFriendTagDTO>> getFriendTagsForFriend(@RequestPar
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* The purpose of this endpoint is to return which friends a user can add to a friend tag, since
* they haven't already been added to that friend tag already. On mobile, this corresponds to the
* popup from clicking a tag's add friend button
*/
// full path: /api/v1/friendTags/friendsNotAddedToTag/{friendTagId}
@GetMapping("friendsNotAddedToTag/{friendTagId}")
public ResponseEntity<List<FullUserDTO>> getFriendsNotAddedToTag(@PathVariable UUID friendTagId) {
try {
return new ResponseEntity<>(friendTagService.getFriendsNotAddedToTag(friendTagId), HttpStatus.OK);
} catch (BaseNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// full path: /api/v1/friendTags/bulkAddFriendsToTag
@PostMapping("bulkAddFriendsToTag")
public ResponseEntity<Void> bulkAddFriendsToTag(@RequestBody List<FullUserDTO> friends, @RequestParam UUID friendTagId) {
try {
friendTagService.saveUsersToFriendTag(friendTagId, friends);
return new ResponseEntity<>(HttpStatus.OK);
} catch (BaseNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
// this also catches `BaseSaveException`, which we're treating the same way with a 500 error below
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.danielagapov.spawn.DTOs.FullUserDTO;
import com.danielagapov.spawn.DTOs.UserDTO;
import com.danielagapov.spawn.Enums.OAuthProvider;
import com.danielagapov.spawn.Helpers.Logger.ILogger;
import com.danielagapov.spawn.Exceptions.Logger.ILogger;
import com.danielagapov.spawn.Services.OAuth.IOAuthService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.danielagapov.spawn.Controllers;

import com.danielagapov.spawn.DTOs.FriendRequestDTO;
import com.danielagapov.spawn.DTOs.IOnboardedUserDTO;
import com.danielagapov.spawn.DTOs.RecommendedFriendUserDTO;
import com.danielagapov.spawn.DTOs.UserDTO;
Expand Down Expand Up @@ -137,16 +136,6 @@ public ResponseEntity<Void> deleteUser(@PathVariable UUID id) {
}
}

// full path: /api/v1/users/friend-request
@PostMapping("friend-request")
public ResponseEntity<FriendRequestDTO> createFriendRequest(@RequestBody FriendRequestDTO friendReq) {
try {
return new ResponseEntity<>(friendRequestService.saveFriendRequest(friendReq), HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// full path: /api/v1/users/{id}/removeFriend?friendId=friendId
@DeleteMapping("{id}/removeFriend")
public ResponseEntity<Void> deleteFriendFromUser(@PathVariable UUID id, @RequestParam UUID friendId) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/danielagapov/spawn/DTOs/BetaAccessSignUpDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.danielagapov.spawn.DTOs;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.time.OffsetDateTime;
import java.util.UUID;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class BetaAccessSignUpDTO implements Serializable {
private UUID id;
private String email;
private String firstName;
private String lastName;
private OffsetDateTime signedUpAt;
private String additionalComments;
private String instagramUsername;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.danielagapov.spawn.DTOs;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.UUID;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class FullFriendRequestDTO implements Serializable {
UUID id;
FullUserDTO senderUser;
FullUserDTO receiverUser;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.danielagapov.spawn.Helpers.Logger;
package com.danielagapov.spawn.Exceptions.Logger;

public interface ILogger {
void log(String message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.danielagapov.spawn.Helpers.Logger;
package com.danielagapov.spawn.Exceptions.Logger;

import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.danielagapov.spawn.Mappers;

import com.danielagapov.spawn.DTOs.BetaAccessSignUpDTO;
import com.danielagapov.spawn.Models.BetaAccessSignUp;

import java.util.List;
import java.util.stream.Collectors;

public class BetaAccessSignUpMapper {

public static BetaAccessSignUpDTO toDTO(BetaAccessSignUp entity) {
return new BetaAccessSignUpDTO(
entity.getId(),
entity.getEmail(),
entity.getFirstName(),
entity.getLastName(),
entity.getSignedUpAt(),
entity.getAdditionalComments(),
entity.getInstagramUsername()
);
}

public static BetaAccessSignUp toEntity(BetaAccessSignUpDTO dto) {
return new BetaAccessSignUp(
dto.getId(),
dto.getEmail(),
dto.getFirstName(),
dto.getLastName(),
dto.getSignedUpAt(),
dto.getAdditionalComments(),
dto.getInstagramUsername()
);
}

public static List<BetaAccessSignUpDTO> toDTOList(List<BetaAccessSignUp> entities) {
return entities.stream()
.map(BetaAccessSignUpMapper::toDTO)
.collect(Collectors.toList());
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/danielagapov/spawn/Models/BetaAccessSignUp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.danielagapov.spawn.Models;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.time.OffsetDateTime;
import java.util.UUID;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class BetaAccessSignUp implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private String email;
private String firstName;
private String lastName;
private OffsetDateTime signedUpAt;
private String additionalComments;
private String instagramUsername;

@PrePersist
public void prePersist() {
// this happens upon persistence to our database in `BetaAccessSignUpService::signUp()`
if (this.signedUpAt == null) {
this.signedUpAt = OffsetDateTime.now();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.danielagapov.spawn.Models;

import com.danielagapov.spawn.Models.ChatMessage;
import com.danielagapov.spawn.Models.CompositeKeys.ChatMessageLikesId;
import com.danielagapov.spawn.Models.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.danielagapov.spawn.Models;

import com.danielagapov.spawn.Enums.OAuthProvider;
import com.danielagapov.spawn.Enums.ParticipationStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Loading

0 comments on commit 333f738

Please sign in to comment.