Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ActivityRepository extends MongoRepository<Activity, String> {


List<Activity> findByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import com.example.activityservice.service.ActivityService;
import lombok.AllArgsConstructor;
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;

@RestController
@RequestMapping("/api/activities")
Expand All @@ -17,9 +16,15 @@
private ActivityService activityService;

@PostMapping
public ResponseEntity<ActivityResponse> trackActivity(@RequestBody ActivityRequest request){
public ResponseEntity<ActivityResponse> trackActivity(@RequestBody ActivityRequest request, @RequestHeader("X-User-ID") String userId ){

Check notice on line 19 in activityservice/src/main/java/com/example/activityservice/controller/ActivityController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unknown HTTP header

Unknown HTTP header
request.setUserId(userId);
return ResponseEntity.ok(activityService.trackActivity(request));
}
@GetMapping
public ResponseEntity<List<ActivityResponse>> getUserActivities(@RequestHeader("X-User-ID") String userId){

Check notice on line 24 in activityservice/src/main/java/com/example/activityservice/controller/ActivityController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unknown HTTP header

Unknown HTTP header
return ResponseEntity.ok(activityService.getUserActivities(userId));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

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

@Service
@RequiredArgsConstructor
public class ActivityService {
Expand All @@ -22,7 +25,7 @@

public ActivityResponse trackActivity(ActivityRequest request) {

Boolean isValidUser = userValidationService.validateUser(request.getUserId());

Check warning on line 28 in activityservice/src/main/java/com/example/activityservice/service/ActivityService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Wrapper type may be primitive

Type may be primitive

if(!isValidUser){
throw new RuntimeException("Invalid User: " + request.getUserId());
Expand All @@ -41,7 +44,7 @@
try {
kafkaTemplate.send(topicName, savedActivity.getUserId(),savedActivity);
} catch (Exception e) {
e.printStackTrace();

Check warning on line 47 in activityservice/src/main/java/com/example/activityservice/service/ActivityService.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Call to 'printStackTrace()'

Call to `printStackTrace()` should probably be replaced with more robust logging
}

return mapToResponse(savedActivity);
Expand All @@ -60,4 +63,11 @@
response.setUpdatedAt(activity.getCreatedAt());
return response;
}

public List<ActivityResponse> getUserActivities(String userId) {
List<Activity> activityList=activityRepository.findByUserId(userId);
return activityList.stream()
.map(this::mapToResponse)
.collect(Collectors.toList());
}
}
Loading
Loading