Skip to content

Commit

Permalink
Merge pull request #1066 from bounswe/main
Browse files Browse the repository at this point in the history
deploying latest changes
  • Loading branch information
halisbal authored Dec 23, 2023
2 parents 4d527e6 + b0a5bc8 commit e6f1b2b
Show file tree
Hide file tree
Showing 126 changed files with 57,484 additions and 44,885 deletions.
2 changes: 2 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/annotation/annotation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM eclipse-temurin:17-jdk-alpine
WORKDIR /app
VOLUME /app/images
COPY target/*.jar /app/bounswe.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app/bounswe.jar"]
24 changes: 24 additions & 0 deletions app/annotation/annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>2.2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.app.annotation.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf().disable()
;

return http.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.app.annotation.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPIDefinition
@Configuration
public class SpringdocConfig {

@Bean
public OpenAPI baseOpenAPI() {
return new OpenAPI().info(new Info().title("Spring Doc").version("1.0.0").description("Spring doc"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import com.app.annotation.service.AnnotationService;
import com.app.annotation.dto.request.CreateAnnotationRequestDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
Expand All @@ -26,4 +24,30 @@ public ResponseEntity<Map<String, Object>> createAnnotation(@RequestBody CreateA
return ResponseEntity.ok(annotation);
}

@DeleteMapping("/delete")
public ResponseEntity<Boolean> deleteAnnotation(@RequestParam String id) {
boolean isDeleted = annotationService.deleteAnnotation(id);
if (!isDeleted) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(true);
}

@PutMapping("/update")
public ResponseEntity<Map<String, Object>> updateAnnotation(@RequestBody CreateAnnotationRequestDto dto) {
Map<String, Object> annotation = annotationService.updateAnnotation(dto);
if(annotation == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(annotation);
}

@GetMapping("/get-source-annotations")
public ResponseEntity<List<Map<String, Object>>> getAnnotation(@RequestParam String source) {
List<Map<String, Object>> annotations = annotationService.getAnnotations(source);
if(annotations == null || annotations.isEmpty()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(annotations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
Expand All @@ -17,7 +18,7 @@ public class CreateAnnotationRequestDto {
private TargetDto target;

@NotEmpty(message = "annotation body can not be empty.")
private BodyDto body;
private List<BodyDto> body;

@NotEmpty(message = "annotation id can not be empty.")
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

@Document(collection = "Annotation")
@Getter
Expand All @@ -23,7 +21,7 @@ public class Annotation {

private Target target;

private Body body;
private List<Body> body;

private String type;

Expand All @@ -41,7 +39,14 @@ public Map<String, Object> toJSON() {
if (this.motivation != null) json.put("motivation", this.motivation);
if (this.created != null) json.put("created", this.created);
if (this.target != null) json.put("target", this.target.toJSON());
if (this.body != null) json.put("body", this.body.toJSON());
if (this.body != null) {
List<Map<String, String>> bodyList = new ArrayList<>();

for (Body b : this.body) {
bodyList.add(b.toJSON());
}
json.put("body", bodyList);
}
if (this.creator != null) json.put("creator", this.creator.toJSON());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import com.app.annotation.model.Annotation;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface AnnotationRepository extends MongoRepository<Annotation, String> {
List<Annotation> findAllByTargetSource(String source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class AnnotationService {
Expand Down Expand Up @@ -59,4 +60,49 @@ public Map<String, Object> createAnnotation(CreateAnnotationRequestDto dto) {

return annotationRepository.save(annotationToCreate).toJSON();
}

public boolean deleteAnnotation(String id) {
if(!annotationRepository.existsById(id)) {
return false;
}
annotationRepository.deleteById(id);
return true;
}

public Map<String, Object> updateAnnotation(CreateAnnotationRequestDto dto) {
Optional<Annotation> annotation = annotationRepository.findById(dto.getId());
if (annotation.isEmpty()) {
return null;
}
Annotation annotationToUpdate = annotation.get();

Annotation updatedAnnotation = modelMapper.map(dto, Annotation.class);
List<Selector> selectorList = new ArrayList<>();
for (SelectorDto s : dto.getTarget().getSelector()) {
if (s.getType().equals("TextQuoteSelector")) {
selectorList.add(modelMapper.map(s, TextQuoteSelector.class));
} else if (s.getType().equals("TextPositionSelector")) {
selectorList.add(modelMapper.map(s, TextPositionSelector.class));
}
//TODO add more selectors if implemented in the future
}
updatedAnnotation.getTarget().setSelector(selectorList);

annotationToUpdate.setTarget(updatedAnnotation.getTarget());
annotationToUpdate.setBody(updatedAnnotation.getBody());
annotationToUpdate.setCreated(updatedAnnotation.getCreated());
annotationToUpdate.setCreator(updatedAnnotation.getCreator());
annotationToUpdate.setMotivation(updatedAnnotation.getMotivation());

return annotationRepository.save(annotationToUpdate).toJSON();
}

public List<Map<String, Object>> getAnnotations(String source) {
List<Annotation> annotations = annotationRepository.findAllByTargetSource(source);
List<Map<String, Object>> jsonAnnotations = new ArrayList<>();
for (Annotation a : annotations) {
jsonAnnotations.add(a.toJSON());
}
return jsonAnnotations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import com.app.gamereview.model.Game;
import com.app.gamereview.model.User;
import com.app.gamereview.service.GameService;
import com.app.gamereview.util.JwtUtil;
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.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -107,11 +109,16 @@ public ResponseEntity<Boolean> deleteGame(@RequestParam String id, @RequestHeade
return ResponseEntity.ok(isDeleted);
}

@AuthorizationRequired
@GetMapping("/get-recommendations")
public ResponseEntity<List<Game>> getRecommendedGames(@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
List<Game> games = gameService.getRecommendedGames(user);
public ResponseEntity<List<Game>> getRecommendedGames(@RequestHeader(name = HttpHeaders.AUTHORIZATION,
required = false) String Authorization) {
if(Authorization == null){
return ResponseEntity.ok(gameService.getRecommendedGames());
}
String email = null;
if (JwtUtil.validateToken(Authorization))
email = JwtUtil.extractSubject(Authorization);
List<Game> games = gameService.getRecommendedGames(email);
return ResponseEntity.ok(games);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public enum NotificationMessage {
FIRST_VOTE_OF_THE_POST("Hey {user_name}! 📣 Your post '{post_title}' just got its first vote. Check it out and see what others think about your post!"),
NTH_VOTE_OF_THE_POST("Exciting news {user_name}! 📣 Your post '{post_title}' just reached {overall_vote} overall vote. It's great to see your contributions resonating with the community. Keep up the fantastic work and keep sharing your thoughts!"),
NEW_COMMENT_FOR_THE_POST("Good news, {user_name}! 🌟 Your post '{post_title}' has a new comment. It's great to see your contributions sparking conversations in the community. Dive in and join the discussion!"),
NEW_REPLY_FOR_THE_COMMENT("Hey {user_name}! 🌟 Your comment on '{post_title}' has a new reply. It's great to see your contributions sparking conversations in the community. Dive in and join the discussion!");
NEW_REPLY_FOR_THE_COMMENT("Hey {user_name}! 🌟 Your comment on '{post_title}' has a new reply. It's great to see your contributions sparking conversations in the community. Dive in and join the discussion!"),
BANNED_FROM_GROUP("Important Notice, {user_name}! 🚫 You have been banned from the '{group_title}' group. This may be due to a violation of our community guidelines or group rules. If you believe this is a mistake, you can contact the moderators for further clarification."),
APPLICATION_ACCEPTED("Congratulations, {user_name}! 🎉 Your application to join the private group '{group_title}' has been accepted. Welcome to the group! Dive in and start engaging with your new community."),
APPLICATION_REJECTED("Notification for {user_name}, 🚫 Your application to join the private group '{group_title}' has been reviewed and unfortunately, it has not been accepted at this time. This decision is based on our group criteria and community guidelines. We encourage you to review these guidelines and consider applying again in the future."),
NEW_GROUP_APPLICATION("Attention Moderators! 🌟 There is a new application for the private group '{group_title}'. Applicant: {user_name}. Please review the application and take appropriate action to maintain the integrity and quality of our group community.");
private final String messageTemplate;
NotificationMessage(String messageTemplate) {
this.messageTemplate = messageTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.app.gamereview.enums;

public enum NotificationParent {
POST,
COMMENT,
ACHIEVEMENT

POST,
COMMENT,
ACHIEVEMENT,
GROUP,
GROUP_APPLICATION
}
Loading

0 comments on commit e6f1b2b

Please sign in to comment.